make separate functions

This commit is contained in:
Alexander Tokmakov 2021-04-20 14:22:02 +03:00
parent 0354312294
commit 4108a235f5
5 changed files with 18 additions and 14 deletions

View File

@ -571,17 +571,8 @@ void DatabaseAtomic::renameDictionaryInMemoryUnlocked(const StorageID & old_name
const auto & dict = dynamic_cast<const IDictionary &>(*result.object);
dict.updateDictionaryName(new_name);
}
void DatabaseAtomic::waitDetachedTableNotInUseOrThrow(const UUID & uuid, bool throw_if_in_use)
void DatabaseAtomic::waitDetachedTableNotInUse(const UUID & uuid)
{
if (throw_if_in_use)
{
DetachedTables not_in_use;
std::lock_guard lock{mutex};
not_in_use = cleanupDetachedTables();
assertDetachedTableNotInUse(uuid);
return;
}
/// Table is in use while its shared_ptr counter is greater than 1.
/// We cannot trigger condvar on shared_ptr destruction, so it's busy wait.
while (true)
@ -597,5 +588,13 @@ void DatabaseAtomic::waitDetachedTableNotInUseOrThrow(const UUID & uuid, bool th
}
}
void DatabaseAtomic::checkDetachedTableNotInUse(const UUID & uuid)
{
DetachedTables not_in_use;
std::lock_guard lock{mutex};
not_in_use = cleanupDetachedTables();
assertDetachedTableNotInUse(uuid);
}
}

View File

@ -57,7 +57,8 @@ public:
void tryCreateSymlink(const String & table_name, const String & actual_data_path, bool if_data_path_exist = false);
void tryRemoveSymlink(const String & table_name);
void waitDetachedTableNotInUseOrThrow(const UUID & uuid, bool throw_if_in_use) override;
void waitDetachedTableNotInUse(const UUID & uuid) override;
void checkDetachedTableNotInUse(const UUID & uuid) override;
void setDetachedTableNotInUseForce(const UUID & uuid);
protected:

View File

@ -345,7 +345,8 @@ public:
virtual void assertCanBeDetached(bool /*cleanup*/) {}
virtual void waitDetachedTableNotInUseOrThrow(const UUID & /*uuid*/, bool /*throw_if_in_use*/) { }
virtual void waitDetachedTableNotInUse(const UUID & /*uuid*/) { }
virtual void checkDetachedTableNotInUse(const UUID & /*uuid*/) { }
/// Ask all tables to complete the background threads they are using and delete all table objects.
virtual void shutdown() = 0;

View File

@ -1003,7 +1003,10 @@ bool InterpreterCreateQuery::doCreateTable(ASTCreateQuery & create,
/// so we allow waiting here. If database_atomic_wait_for_drop_and_detach_synchronously is disabled
/// and old storage instance still exists it will throw exception.
bool throw_if_table_in_use = getContext()->getSettingsRef().database_atomic_wait_for_drop_and_detach_synchronously;
database->waitDetachedTableNotInUseOrThrow(create.uuid, throw_if_table_in_use);
if (throw_if_table_in_use)
database->checkDetachedTableNotInUse(create.uuid);
else
database->waitDetachedTableNotInUse(create.uuid);
}
StoragePtr res;

View File

@ -81,7 +81,7 @@ void InterpreterDropQuery::waitForTableToBeActuallyDroppedOrDetached(const ASTDr
if (query.kind == ASTDropQuery::Kind::Drop)
DatabaseCatalog::instance().waitTableFinallyDropped(uuid_to_wait);
else if (query.kind == ASTDropQuery::Kind::Detach)
db->waitDetachedTableNotInUseOrThrow(uuid_to_wait, false);
db->waitDetachedTableNotInUse(uuid_to_wait);
}
BlockIO InterpreterDropQuery::executeToTable(ASTDropQuery & query)