From 6da923cbe1a391904c26a170d45a176dba2ed922 Mon Sep 17 00:00:00 2001 From: bharatnc Date: Mon, 14 Dec 2020 14:13:13 -0800 Subject: [PATCH] Use tryGetChildren() for Zookeeper --- .../System/StorageSystemDDLWorkerQueue.cpp | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/Storages/System/StorageSystemDDLWorkerQueue.cpp b/src/Storages/System/StorageSystemDDLWorkerQueue.cpp index 83107f50dd4..3d4dd9d1037 100644 --- a/src/Storages/System/StorageSystemDDLWorkerQueue.cpp +++ b/src/Storages/System/StorageSystemDDLWorkerQueue.cpp @@ -143,8 +143,12 @@ void StorageSystemDDLWorkerQueue::fillData(MutableColumns & res_columns, const C /* [zk: localhost:2181(CONNECTED) 51] ls /clickhouse/task_queue/ddl [query-0000000000, query-0000000001, query-0000000002, query-0000000003, query-0000000004] */ - zkutil::Strings queries = zookeeper->getChildren(ddl_zookeeper_path); + // if there is error querying the root path of the ddl directory throw exception and stop + zkutil::Strings queries; + Coordination::Error code = zookeeper->tryGetChildren(ddl_zookeeper_path, queries); + if (code != Coordination::Error::ZOK && code != Coordination::Error::ZNONODE) + throw Coordination::Exception(code, ddl_zookeeper_path); const auto & cluster = context.tryGetCluster(cluster_name); const auto & shards_info = cluster->getShardsInfo(); @@ -153,7 +157,6 @@ void StorageSystemDDLWorkerQueue::fillData(MutableColumns & res_columns, const C if (cluster == nullptr) throw Exception("No cluster with the name: " + cluster_name + " was found.", ErrorCodes::BAD_ARGUMENTS); - for (size_t shard_index = 0; shard_index < shards_info.size(); ++shard_index) { const auto & shard_addresses = addresses_with_failover[shard_index]; @@ -182,10 +185,26 @@ void StorageSystemDDLWorkerQueue::fillData(MutableColumns & res_columns, const C res_columns[i++]->insert(resolved ? resolved->host().toString() : String()); // host_address res_columns[i++]->insert(address.port); // port ddl_query_path = fs::path(ddl_zookeeper_path) / queries[query_id]; - zkutil::Strings active_nodes = zookeeper->getChildren(fs::path(ddl_query_path) / "active"); - zkutil::Strings finished_nodes = zookeeper->getChildren(fs::path(ddl_query_path) / "finished"); - // status + zkutil::Strings active_nodes; + zkutil::Strings finished_nodes; + + // on error just skip and continue. + + code = zookeeper->tryGetChildren(fs::path(ddl_query_path) / "active", active_nodes); + if (code != Coordination::Error::ZOK && code != Coordination::Error::ZNONODE) + continue; + + code = zookeeper->tryGetChildren(fs::path(ddl_query_path) / "finished", finished_nodes); + if (code != Coordination::Error::ZOK && code != Coordination::Error::ZNONODE) + continue; + + /* status: + * active: If the hostname:port entry is present under active path. + * finished: If the hostname:port entry is present under the finished path. + * errored: If the hostname:port entry is present under the finished path but the error count is not 0. + * unknown: If the above cases don't hold true, then status is unknown. + */ if (std::find(active_nodes.begin(), active_nodes.end(), address.toString()) != active_nodes.end()) { res_columns[i++]->insert(static_cast(Status::active));