restart runMainThread in cluster discovery

This commit is contained in:
vdimir 2021-12-07 12:20:33 +03:00
parent 4f8a9cc539
commit 72e63b4f12
No known key found for this signature in database
GPG Key ID: 9B404D301C0CC7EB
2 changed files with 19 additions and 8 deletions

View File

@ -323,18 +323,28 @@ void ClusterDiscovery::start()
main_thread = ThreadFromGlobalPool([this]
{
try
bool finish = false;
while (!finish)
{
runMainThread();
}
catch (...)
{
tryLogCurrentException(log, "Caught exception in cluster discovery runMainThread");
try
{
finish = runMainThread();
}
catch (...)
{
/*
* it can be zk error (will take new session) or other retriable error,
* should not stop discovery forever
*/
tryLogCurrentException(log, "Caught exception in cluster discovery runMainThread");
}
}
});
}
void ClusterDiscovery::runMainThread()
/// Returns `true` on gracefull shutdown (no restart required)
bool ClusterDiscovery::runMainThread()
{
setThreadName("ClusterDiscover");
LOG_DEBUG(log, "Worker thread started");
@ -362,6 +372,7 @@ void ClusterDiscovery::runMainThread()
}
}
LOG_DEBUG(log, "Worker thread stopped");
return stop_flag;
}
void ClusterDiscovery::shutdown()

View File

@ -94,7 +94,7 @@ private:
bool updateCluster(const String & cluster_name);
bool updateCluster(ClusterInfo & cluster_info);
void runMainThread();
bool runMainThread();
void shutdown();
/// cluster name -> cluster info (zk root, set of nodes)