mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-19 16:20:50 +00:00
Merge pull request #66843 from ClickHouse/fix_getddlworker_deadlock
Fix deadlock in Context::getDDLWorker()
This commit is contained in:
commit
b217506931
@ -3494,18 +3494,22 @@ DDLWorker & Context::getDDLWorker() const
|
||||
if (shared->ddl_worker_startup_task)
|
||||
waitLoad(shared->ddl_worker_startup_task); // Just wait and do not prioritize, because it depends on all load and startup tasks
|
||||
|
||||
SharedLockGuard lock(shared->mutex);
|
||||
if (!shared->ddl_worker)
|
||||
{
|
||||
if (!hasZooKeeper())
|
||||
throw Exception(ErrorCodes::NO_ELEMENTS_IN_CONFIG, "There is no Zookeeper configuration in server config");
|
||||
|
||||
if (!hasDistributedDDL())
|
||||
throw Exception(ErrorCodes::NO_ELEMENTS_IN_CONFIG, "There is no DistributedDDL configuration in server config");
|
||||
|
||||
throw Exception(ErrorCodes::NO_ELEMENTS_IN_CONFIG, "DDL background thread is not initialized");
|
||||
/// Only acquire the lock for reading ddl_worker field.
|
||||
/// hasZooKeeper() and hasDistributedDDL() acquire the same lock as well and double acquisition of the lock in shared mode can lead
|
||||
/// to a deadlock if an exclusive lock attempt is made in the meantime by another thread.
|
||||
SharedLockGuard lock(shared->mutex);
|
||||
if (shared->ddl_worker)
|
||||
return *shared->ddl_worker;
|
||||
}
|
||||
return *shared->ddl_worker;
|
||||
|
||||
if (!hasZooKeeper())
|
||||
throw Exception(ErrorCodes::NO_ELEMENTS_IN_CONFIG, "There is no Zookeeper configuration in server config");
|
||||
|
||||
if (!hasDistributedDDL())
|
||||
throw Exception(ErrorCodes::NO_ELEMENTS_IN_CONFIG, "There is no DistributedDDL configuration in server config");
|
||||
|
||||
throw Exception(ErrorCodes::NO_ELEMENTS_IN_CONFIG, "DDL background thread is not initialized");
|
||||
}
|
||||
|
||||
zkutil::ZooKeeperPtr Context::getZooKeeper() const
|
||||
|
Loading…
Reference in New Issue
Block a user