@@ -750,6 +750,7 @@ struct ContextSharedPart : boost::noncopyable
750750 void shutdown () TSA_NO_THREAD_SAFETY_ANALYSIS
751751 {
752752 swarm_mode_enabled = false ;
753+ CurrentMetrics::set (CurrentMetrics::IsSwarmModeEnabled, 0 );
753754 bool is_shutdown_called = shutdown_called.exchange (true );
754755 if (is_shutdown_called)
755756 return ;
@@ -4665,15 +4666,15 @@ std::shared_ptr<Cluster> Context::tryGetCluster(const std::string & cluster_name
46654666 return res;
46664667}
46674668
4668- void Context::unregisterInDynamicClusters ()
4669+ void Context::unregisterInAutodiscoveryClusters ()
46694670{
46704671 std::lock_guard lock (shared->clusters_mutex );
46714672 if (!shared->cluster_discovery )
46724673 return ;
46734674 shared->cluster_discovery ->unregisterAll ();
46744675}
46754676
4676- void Context::registerInDynamicClusters ()
4677+ void Context::registerInAutodiscoveryClusters ()
46774678{
46784679 std::lock_guard lock (shared->clusters_mutex );
46794680 if (!shared->cluster_discovery )
@@ -5562,16 +5563,24 @@ void Context::shutdown() TSA_NO_THREAD_SAFETY_ANALYSIS
55625563 shared->shutdown ();
55635564}
55645565
5565- void Context::stopSwarmMode ()
5566+ bool Context::stopSwarmMode ()
55665567{
5567- CurrentMetrics::set (CurrentMetrics::IsSwarmModeEnabled, 0 );
5568- shared->swarm_mode_enabled = false ;
5568+ bool expected_is_enabled = true ;
5569+ bool is_stopped_now = shared->swarm_mode_enabled .compare_exchange_strong (expected_is_enabled, false );
5570+ if (is_stopped_now)
5571+ CurrentMetrics::set (CurrentMetrics::IsSwarmModeEnabled, 0 );
5572+ // return true if stop successful
5573+ return is_stopped_now;
55695574}
55705575
5571- void Context::startSwarmMode ()
5576+ bool Context::startSwarmMode ()
55725577{
5573- shared->swarm_mode_enabled = true ;
5574- CurrentMetrics::set (CurrentMetrics::IsSwarmModeEnabled, 1 );
5578+ bool expected_is_enabled = false ;
5579+ bool is_started_now = shared->swarm_mode_enabled .compare_exchange_strong (expected_is_enabled, true );
5580+ if (is_started_now)
5581+ CurrentMetrics::set (CurrentMetrics::IsSwarmModeEnabled, 1 );
5582+ // return true if start successful
5583+ return is_started_now;
55755584}
55765585
55775586bool Context::isSwarmModeEnabled () const
0 commit comments