@@ -737,6 +737,7 @@ struct ContextSharedPart : boost::noncopyable
737737 void shutdown () TSA_NO_THREAD_SAFETY_ANALYSIS
738738 {
739739 swarm_mode_enabled = false ;
740+ CurrentMetrics::set (CurrentMetrics::IsSwarmModeEnabled, 0 );
740741 bool is_shutdown_called = shutdown_called.exchange (true );
741742 if (is_shutdown_called)
742743 return ;
@@ -4502,15 +4503,15 @@ std::shared_ptr<Cluster> Context::tryGetCluster(const std::string & cluster_name
45024503 return res;
45034504}
45044505
4505- void Context::unregisterInDynamicClusters ()
4506+ void Context::unregisterInAutodiscoveryClusters ()
45064507{
45074508 std::lock_guard lock (shared->clusters_mutex );
45084509 if (!shared->cluster_discovery )
45094510 return ;
45104511 shared->cluster_discovery ->unregisterAll ();
45114512}
45124513
4513- void Context::registerInDynamicClusters ()
4514+ void Context::registerInAutodiscoveryClusters ()
45144515{
45154516 std::lock_guard lock (shared->clusters_mutex );
45164517 if (!shared->cluster_discovery )
@@ -5372,16 +5373,24 @@ void Context::shutdown() TSA_NO_THREAD_SAFETY_ANALYSIS
53725373 shared->shutdown ();
53735374}
53745375
5375- void Context::stopSwarmMode ()
5376+ bool Context::stopSwarmMode ()
53765377{
5377- CurrentMetrics::set (CurrentMetrics::IsSwarmModeEnabled, 0 );
5378- shared->swarm_mode_enabled = false ;
5378+ bool expected_is_enabled = true ;
5379+ bool is_stopped_now = shared->swarm_mode_enabled .compare_exchange_strong (expected_is_enabled, false );
5380+ if (is_stopped_now)
5381+ CurrentMetrics::set (CurrentMetrics::IsSwarmModeEnabled, 0 );
5382+ // return true if stop successful
5383+ return is_stopped_now;
53795384}
53805385
5381- void Context::startSwarmMode ()
5386+ bool Context::startSwarmMode ()
53825387{
5383- shared->swarm_mode_enabled = true ;
5384- CurrentMetrics::set (CurrentMetrics::IsSwarmModeEnabled, 1 );
5388+ bool expected_is_enabled = false ;
5389+ bool is_started_now = shared->swarm_mode_enabled .compare_exchange_strong (expected_is_enabled, true );
5390+ if (is_started_now)
5391+ CurrentMetrics::set (CurrentMetrics::IsSwarmModeEnabled, 1 );
5392+ // return true if start successful
5393+ return is_started_now;
53855394}
53865395
53875396bool Context::isSwarmModeEnabled () const
0 commit comments