Use auxiliary keeper for cluster discovery

This commit is contained in:
Anton Ivashkin 2024-11-14 11:16:48 +01:00
parent 3145aeda84
commit 57ddde47ea
2 changed files with 10 additions and 4 deletions

View File

@ -129,9 +129,11 @@ ClusterDiscovery::ClusterDiscovery(
if (!config.has(cluster_config_prefix)) if (!config.has(cluster_config_prefix))
continue; continue;
String zk_root = config.getString(cluster_config_prefix + ".path"); String zk_name_and_root = config.getString(cluster_config_prefix + ".path");
if (zk_root.empty()) if (zk_name_and_root.empty())
throw Exception(ErrorCodes::NO_ELEMENTS_IN_CONFIG, "ZooKeeper path for cluster '{}' is empty", key); throw Exception(ErrorCodes::NO_ELEMENTS_IN_CONFIG, "ZooKeeper path for cluster '{}' is empty", key);
String zk_root = zkutil::extractZooKeeperPath(zk_name_and_root, true);
String zk_name = zkutil::extractZooKeeperName(zk_name_and_root);
const auto & password = config.getString(cluster_config_prefix + ".password", ""); const auto & password = config.getString(cluster_config_prefix + ".password", "");
const auto & cluster_secret = config.getString(cluster_config_prefix + ".secret", ""); const auto & cluster_secret = config.getString(cluster_config_prefix + ".secret", "");
@ -142,6 +144,7 @@ ClusterDiscovery::ClusterDiscovery(
key, key,
ClusterInfo( ClusterInfo(
/* name_= */ key, /* name_= */ key,
/* zk_name_= */ zk_name,
/* zk_root_= */ zk_root, /* zk_root_= */ zk_root,
/* host_name= */ config.getString(cluster_config_prefix + ".my_hostname", getFQDNOrHostName()), /* host_name= */ config.getString(cluster_config_prefix + ".my_hostname", getFQDNOrHostName()),
/* username= */ config.getString(cluster_config_prefix + ".user", context->getUserName()), /* username= */ config.getString(cluster_config_prefix + ".user", context->getUserName()),
@ -288,7 +291,7 @@ bool ClusterDiscovery::updateCluster(ClusterInfo & cluster_info)
{ {
LOG_DEBUG(log, "Updating cluster '{}'", cluster_info.name); LOG_DEBUG(log, "Updating cluster '{}'", cluster_info.name);
auto zk = context->getZooKeeper(); auto zk = context->getDefaultOrAuxiliaryZooKeeper(cluster_info.zk_name);
int start_version; int start_version;
Strings node_uuids = getNodeNames(zk, cluster_info.zk_root, cluster_info.name, &start_version, false); Strings node_uuids = getNodeNames(zk, cluster_info.zk_root, cluster_info.name, &start_version, false);
@ -381,9 +384,9 @@ void ClusterDiscovery::initialUpdate()
throw Exception(ErrorCodes::KEEPER_EXCEPTION, "Failpoint cluster_discovery_faults is triggered"); throw Exception(ErrorCodes::KEEPER_EXCEPTION, "Failpoint cluster_discovery_faults is triggered");
}); });
auto zk = context->getZooKeeper();
for (auto & [_, info] : clusters_info) for (auto & [_, info] : clusters_info)
{ {
auto zk = context->getDefaultOrAuxiliaryZooKeeper(info.zk_name);
registerInZk(zk, info); registerInZk(zk, info);
if (!updateCluster(info)) if (!updateCluster(info))
{ {

View File

@ -67,6 +67,7 @@ private:
struct ClusterInfo struct ClusterInfo
{ {
const String name; const String name;
const String zk_name;
const String zk_root; const String zk_root;
NodesInfo nodes_info; NodesInfo nodes_info;
@ -88,6 +89,7 @@ private:
String cluster_secret; String cluster_secret;
ClusterInfo(const String & name_, ClusterInfo(const String & name_,
const String & zk_name_,
const String & zk_root_, const String & zk_root_,
const String & host_name, const String & host_name,
const String & username_, const String & username_,
@ -99,6 +101,7 @@ private:
bool observer_mode, bool observer_mode,
bool invisible) bool invisible)
: name(name_) : name(name_)
, zk_name(zk_name_)
, zk_root(zk_root_) , zk_root(zk_root_)
, current_node(host_name + ":" + toString(port), secure, shard_id) , current_node(host_name + ":" + toString(port), secure, shard_id)
, current_node_is_observer(observer_mode) , current_node_is_observer(observer_mode)