@@ -296,17 +296,32 @@ Strings ClusterDiscovery::getNodeNames(zkutil::ZooKeeperPtr & zk,
296296 auto callback = get_nodes_callbacks.find (cluster_name);
297297 if (callback == get_nodes_callbacks.end ())
298298 {
299- auto watch_dynamic_callback = std::make_shared<Coordination::WatchCallback>([
300- cluster_name,
301- my_clusters_to_update = clusters_to_update,
302- my_discovery_paths_need_update = multicluster_discovery_paths[zk_root_index - 1 ].need_update
303- ](auto )
304- {
305- my_discovery_paths_need_update->store (true );
306- my_clusters_to_update->set (cluster_name);
307- });
308- auto res = get_nodes_callbacks.insert (std::make_pair (cluster_name, watch_dynamic_callback));
309- callback = res.first ;
299+ if (zk_root_index > 0 )
300+ {
301+ auto watch_dynamic_callback = std::make_shared<Coordination::WatchCallback>([
302+ cluster_name,
303+ my_clusters_to_update = clusters_to_update,
304+ my_discovery_paths_need_update = multicluster_discovery_paths[zk_root_index - 1 ].need_update
305+ ](auto )
306+ {
307+ my_discovery_paths_need_update->store (true );
308+ my_clusters_to_update->set (cluster_name);
309+ });
310+ auto res = get_nodes_callbacks.insert (std::make_pair (cluster_name, watch_dynamic_callback));
311+ callback = res.first ;
312+ }
313+ else
314+ { // zk_root_index == 0 for static clusters
315+ auto watch_dynamic_callback = std::make_shared<Coordination::WatchCallback>([
316+ cluster_name,
317+ my_clusters_to_update = clusters_to_update
318+ ](auto )
319+ {
320+ my_clusters_to_update->set (cluster_name);
321+ });
322+ auto res = get_nodes_callbacks.insert (std::make_pair (cluster_name, watch_dynamic_callback));
323+ callback = res.first ;
324+ }
310325 }
311326 nodes = zk->getChildrenWatch (getShardsListPath (zk_root), &stat, callback->second );
312327 }
0 commit comments