This commit is contained in:
serxa 2023-11-02 14:55:53 +00:00
parent 59c0f4c652
commit 9f954ece81
3 changed files with 12 additions and 7 deletions

View File

@ -202,8 +202,7 @@ LoadTaskPtr DatabaseOrdinary::startupTableAsync(
fmt::format("startup table {}", name.getFullName()),
[this, name] (AsyncLoader &, const LoadJobPtr &)
{
// `DatabaseOnDisk::tryGetTable()` is used to avoid waiting for a startup
if (auto table = DatabaseOnDisk::tryGetTable(name.table, {}))
if (auto table = tryGetTableNoWait(name.table))
{
/// Since startup() method can use physical paths on disk we don't allow any exclusive actions (rename, drop so on)
/// until startup finished.

View File

@ -200,11 +200,7 @@ bool DatabaseWithOwnTablesBase::isTableExist(const String & table_name, ContextP
StoragePtr DatabaseWithOwnTablesBase::tryGetTable(const String & table_name, ContextPtr) const
{
waitTableStarted(table_name);
std::lock_guard lock(mutex);
auto it = tables.find(table_name);
if (it != tables.end())
return it->second;
return {};
return tryGetTableNoWait(table_name);
}
DatabaseTablesIteratorPtr DatabaseWithOwnTablesBase::getTablesIterator(ContextPtr, const FilterByNameFunction & filter_by_table_name) const
@ -376,4 +372,13 @@ void DatabaseWithOwnTablesBase::createTableRestoredFromBackup(const ASTPtr & cre
interpreter.execute();
}
StoragePtr DatabaseWithOwnTablesBase::tryGetTableNoWait(const String & table_name) const
{
std::lock_guard lock(mutex);
auto it = tables.find(table_name);
if (it != tables.end())
return it->second;
return {};
}
}

View File

@ -52,6 +52,7 @@ protected:
void attachTableUnlocked(const String & table_name, const StoragePtr & table) TSA_REQUIRES(mutex);
StoragePtr detachTableUnlocked(const String & table_name) TSA_REQUIRES(mutex);
StoragePtr getTableUnlocked(const String & table_name) const TSA_REQUIRES(mutex);
StoragePtr tryGetTableNoWait(const String & table_name) const;
};
}