mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 10:02:01 +00:00
Merge pull request #51908 from ClickHouse/fix_deadlock_on_catalog_shutdown
Fix deadlock on DatabaseCatalog shutdown
This commit is contained in:
commit
152a4b9d4c
@ -56,6 +56,7 @@ namespace ErrorCodes
|
||||
extern const int DATABASE_ACCESS_DENIED;
|
||||
extern const int LOGICAL_ERROR;
|
||||
extern const int HAVE_DEPENDENT_OBJECTS;
|
||||
extern const int UNFINISHED;
|
||||
}
|
||||
|
||||
TemporaryTableHolder::TemporaryTableHolder(ContextPtr context_, const TemporaryTableHolder::Creator & creator, const ASTPtr & query)
|
||||
@ -196,6 +197,9 @@ void DatabaseCatalog::startupBackgroundCleanup()
|
||||
|
||||
void DatabaseCatalog::shutdownImpl()
|
||||
{
|
||||
is_shutting_down = true;
|
||||
wait_table_finally_dropped.notify_all();
|
||||
|
||||
if (cleanup_task)
|
||||
(*cleanup_task)->deactivate();
|
||||
|
||||
@ -1161,8 +1165,13 @@ void DatabaseCatalog::waitTableFinallyDropped(const UUID & uuid)
|
||||
std::unique_lock lock{tables_marked_dropped_mutex};
|
||||
wait_table_finally_dropped.wait(lock, [&]() TSA_REQUIRES(tables_marked_dropped_mutex) -> bool
|
||||
{
|
||||
return !tables_marked_dropped_ids.contains(uuid);
|
||||
return !tables_marked_dropped_ids.contains(uuid) || is_shutting_down;
|
||||
});
|
||||
|
||||
/// TSA doesn't support unique_lock
|
||||
if (TSA_SUPPRESS_WARNING_FOR_READ(tables_marked_dropped_ids).contains(uuid))
|
||||
throw Exception(ErrorCodes::UNFINISHED, "Did not finish dropping the table with UUID {} because the server is shutting down, "
|
||||
"will finish after restart", uuid);
|
||||
}
|
||||
|
||||
void DatabaseCatalog::addDependencies(
|
||||
|
@ -308,6 +308,8 @@ private:
|
||||
|
||||
Poco::Logger * log;
|
||||
|
||||
std::atomic_bool is_shutting_down = false;
|
||||
|
||||
/// Do not allow simultaneous execution of DDL requests on the same table.
|
||||
/// database name -> database guard -> (table name mutex, counter),
|
||||
/// counter: how many threads are running a query on the table at the same time
|
||||
|
Loading…
Reference in New Issue
Block a user