@@ -750,6 +750,7 @@ struct ContextSharedPart : boost::noncopyable
750
750
void shutdown () TSA_NO_THREAD_SAFETY_ANALYSIS
751
751
{
752
752
swarm_mode_enabled = false ;
753
+ CurrentMetrics::set (CurrentMetrics::IsSwarmModeEnabled, 0 );
753
754
bool is_shutdown_called = shutdown_called.exchange (true );
754
755
if (is_shutdown_called)
755
756
return ;
@@ -4665,15 +4666,15 @@ std::shared_ptr<Cluster> Context::tryGetCluster(const std::string & cluster_name
4665
4666
return res;
4666
4667
}
4667
4668
4668
- void Context::unregisterInDynamicClusters ()
4669
+ void Context::unregisterInAutodiscoveryClusters ()
4669
4670
{
4670
4671
std::lock_guard lock (shared->clusters_mutex );
4671
4672
if (!shared->cluster_discovery )
4672
4673
return ;
4673
4674
shared->cluster_discovery ->unregisterAll ();
4674
4675
}
4675
4676
4676
- void Context::registerInDynamicClusters ()
4677
+ void Context::registerInAutodiscoveryClusters ()
4677
4678
{
4678
4679
std::lock_guard lock (shared->clusters_mutex );
4679
4680
if (!shared->cluster_discovery )
@@ -5562,16 +5563,24 @@ void Context::shutdown() TSA_NO_THREAD_SAFETY_ANALYSIS
5562
5563
shared->shutdown ();
5563
5564
}
5564
5565
5565
- void Context::stopSwarmMode ()
5566
+ bool Context::stopSwarmMode ()
5566
5567
{
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;
5569
5574
}
5570
5575
5571
- void Context::startSwarmMode ()
5576
+ bool Context::startSwarmMode ()
5572
5577
{
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;
5575
5584
}
5576
5585
5577
5586
bool Context::isSwarmModeEnabled () const
0 commit comments