mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 00:30:49 +00:00
Merge pull request #66843 from ClickHouse/fix_getddlworker_deadlock
Fix deadlock in Context::getDDLWorker()
This commit is contained in:
commit
b217506931
@ -3494,9 +3494,15 @@ DDLWorker & Context::getDDLWorker() const
|
|||||||
if (shared->ddl_worker_startup_task)
|
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
|
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)
|
|
||||||
{
|
{
|
||||||
|
/// 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;
|
||||||
|
}
|
||||||
|
|
||||||
if (!hasZooKeeper())
|
if (!hasZooKeeper())
|
||||||
throw Exception(ErrorCodes::NO_ELEMENTS_IN_CONFIG, "There is no Zookeeper configuration in server config");
|
throw Exception(ErrorCodes::NO_ELEMENTS_IN_CONFIG, "There is no Zookeeper configuration in server config");
|
||||||
|
|
||||||
@ -3504,8 +3510,6 @@ DDLWorker & Context::getDDLWorker() const
|
|||||||
throw Exception(ErrorCodes::NO_ELEMENTS_IN_CONFIG, "There is no DistributedDDL configuration in server config");
|
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");
|
throw Exception(ErrorCodes::NO_ELEMENTS_IN_CONFIG, "DDL background thread is not initialized");
|
||||||
}
|
|
||||||
return *shared->ddl_worker;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
zkutil::ZooKeeperPtr Context::getZooKeeper() const
|
zkutil::ZooKeeperPtr Context::getZooKeeper() const
|
||||||
|
Loading…
Reference in New Issue
Block a user