mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 00:52:02 +00:00
initial initialization of cluster discovery in main thread
This commit is contained in:
parent
7a38716360
commit
fbdb5c60bd
@ -1555,7 +1555,14 @@ if (ThreadFuzzer::instance().isEffective())
|
|||||||
server.start();
|
server.start();
|
||||||
LOG_INFO(log, "Ready for connections.");
|
LOG_INFO(log, "Ready for connections.");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
global_context->startClusterDiscovery();
|
global_context->startClusterDiscovery();
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
tryLogCurrentException(log, "Caught exception while starting cluster discovery");
|
||||||
|
}
|
||||||
|
|
||||||
SCOPE_EXIT_SAFE({
|
SCOPE_EXIT_SAFE({
|
||||||
LOG_DEBUG(log, "Received termination signal.");
|
LOG_DEBUG(log, "Received termination signal.");
|
||||||
|
@ -190,7 +190,7 @@ bool ClusterDiscovery::needUpdate(const Strings & node_uuids, const NodesInfo &
|
|||||||
return has_difference;
|
return has_difference;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClusterPtr ClusterDiscovery::getCluster(const ClusterInfo & cluster_info)
|
ClusterPtr ClusterDiscovery::makeCluster(const ClusterInfo & cluster_info)
|
||||||
{
|
{
|
||||||
Strings replica_adresses;
|
Strings replica_adresses;
|
||||||
replica_adresses.reserve(cluster_info.nodes_info.size());
|
replica_adresses.reserve(cluster_info.nodes_info.size());
|
||||||
@ -262,7 +262,7 @@ bool ClusterDiscovery::updateCluster(ClusterInfo & cluster_info)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto cluster = getCluster(cluster_info);
|
auto cluster = makeCluster(cluster_info);
|
||||||
context->setCluster(cluster_info.name, cluster);
|
context->setCluster(cluster_info.name, cluster);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -280,6 +280,8 @@ bool ClusterDiscovery::updateCluster(const String & cluster_name)
|
|||||||
|
|
||||||
void ClusterDiscovery::registerInZk(zkutil::ZooKeeperPtr & zk, ClusterInfo & info)
|
void ClusterDiscovery::registerInZk(zkutil::ZooKeeperPtr & zk, ClusterInfo & info)
|
||||||
{
|
{
|
||||||
|
LOG_DEBUG(log, "Registering current node {} in cluster {}", node_name, info.name);
|
||||||
|
|
||||||
String node_path = getShardsListPath(info.zk_root) / node_name;
|
String node_path = getShardsListPath(info.zk_root) / node_name;
|
||||||
zk->createAncestors(node_path);
|
zk->createAncestors(node_path);
|
||||||
|
|
||||||
@ -297,15 +299,7 @@ void ClusterDiscovery::start()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LOG_TRACE(log, "Starting working thread");
|
LOG_TRACE(log, "Starting working thread");
|
||||||
main_thread = ThreadFromGlobalPool([this] { runMainThread(); });
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClusterDiscovery::runMainThread()
|
|
||||||
{
|
|
||||||
LOG_DEBUG(log, "Worker thread started");
|
|
||||||
// setThreadName("ClusterDiscovery");
|
|
||||||
|
|
||||||
{
|
|
||||||
auto zk = context->getZooKeeper();
|
auto zk = context->getZooKeeper();
|
||||||
for (auto & [_, info] : clusters_info)
|
for (auto & [_, info] : clusters_info)
|
||||||
{
|
{
|
||||||
@ -316,7 +310,24 @@ void ClusterDiscovery::runMainThread()
|
|||||||
clusters_to_update->set(info.name);
|
clusters_to_update->set(info.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main_thread = ThreadFromGlobalPool([this]
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
runMainThread();
|
||||||
}
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
tryLogCurrentException(log, "Caught exception in cluster discovery runMainThread");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClusterDiscovery::runMainThread()
|
||||||
|
{
|
||||||
|
setThreadName("ClusterDiscover");
|
||||||
|
LOG_DEBUG(log, "Worker thread started");
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ private:
|
|||||||
|
|
||||||
NodesInfo getNodes(zkutil::ZooKeeperPtr & zk, const String & zk_root, const Strings & node_uuids);
|
NodesInfo getNodes(zkutil::ZooKeeperPtr & zk, const String & zk_root, const Strings & node_uuids);
|
||||||
|
|
||||||
ClusterPtr getCluster(const ClusterInfo & cluster_info);
|
ClusterPtr makeCluster(const ClusterInfo & cluster_info);
|
||||||
|
|
||||||
bool needUpdate(const Strings & node_uuids, const NodesInfo & nodes);
|
bool needUpdate(const Strings & node_uuids, const NodesInfo & nodes);
|
||||||
bool updateCluster(const String & cluster_name);
|
bool updateCluster(const String & cluster_name);
|
||||||
|
@ -31,11 +31,11 @@ def check_nodes_count_in_cluster(nodes, expected, cluster_name, *, retries=5):
|
|||||||
assert 1 <= retries <= 6
|
assert 1 <= retries <= 6
|
||||||
|
|
||||||
for retry in range(1, retries + 1):
|
for retry in range(1, retries + 1):
|
||||||
nodes_cnt = [
|
nodes_cnt = {
|
||||||
int(node.query(f"SELECT count() FROM system.clusters WHERE cluster = '{cluster_name}'"))
|
node.name: int(node.query(f"SELECT count() FROM system.clusters WHERE cluster = '{cluster_name}'"))
|
||||||
for node in nodes
|
for node in nodes
|
||||||
]
|
}
|
||||||
if all(actual == expected for actual in nodes_cnt):
|
if all(actual == expected for actual in nodes_cnt.values()):
|
||||||
break
|
break
|
||||||
|
|
||||||
if retry != retries:
|
if retry != retries:
|
||||||
|
Loading…
Reference in New Issue
Block a user