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

@ -322,19 +322,29 @@ void ClusterDiscovery::start()
} }
main_thread = ThreadFromGlobalPool([this] main_thread = ThreadFromGlobalPool([this]
{
bool finish = false;
while (!finish)
{ {
try try
{ {
runMainThread(); finish = runMainThread();
} }
catch (...) 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"); tryLogCurrentException(log, "Caught exception in cluster discovery runMainThread");
} }
}
}); });
} }
void ClusterDiscovery::runMainThread()
/// Returns `true` on gracefull shutdown (no restart required)
bool ClusterDiscovery::runMainThread()
{ {
setThreadName("ClusterDiscover"); setThreadName("ClusterDiscover");
LOG_DEBUG(log, "Worker thread started"); LOG_DEBUG(log, "Worker thread started");
@ -362,6 +372,7 @@ void ClusterDiscovery::runMainThread()
} }
} }
LOG_DEBUG(log, "Worker thread stopped"); LOG_DEBUG(log, "Worker thread stopped");
return stop_flag;
} }
void ClusterDiscovery::shutdown() void ClusterDiscovery::shutdown()

View File

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