diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-18 17:02:53 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-18 17:02:53 -0300 |
| commit | 959575a5ca598bf5f37fb5cebe7ed1d80d3d71f7 (patch) | |
| tree | acc8d60aedb12b70048e676e8a7349deb0010db8 /src/mongo/client/replica_set_monitor_manager.cpp | |
| parent | 76588293975fc059cf076779e4283e6ffaf8afff (diff) | |
New upstream version 6.0.20upstream
Diffstat (limited to 'src/mongo/client/replica_set_monitor_manager.cpp')
| -rw-r--r-- | src/mongo/client/replica_set_monitor_manager.cpp | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/src/mongo/client/replica_set_monitor_manager.cpp b/src/mongo/client/replica_set_monitor_manager.cpp index 5fe13f2be81..c440f5b0b8f 100644 --- a/src/mongo/client/replica_set_monitor_manager.cpp +++ b/src/mongo/client/replica_set_monitor_manager.cpp @@ -141,10 +141,6 @@ void ReplicaSetMonitorManager::_setupTaskExecutorAndStatsInLock() { return; } - if (!_stats) { - _stats = std::make_shared<ReplicaSetMonitorManagerStats>(); - } - // construct task executor auto hookList = std::make_unique<rpc::EgressMetadataHookList>(); auto networkConnectionHook = std::make_unique<ReplicaSetMonitorManagerNetworkConnectionHook>(); @@ -223,7 +219,6 @@ shared_ptr<ReplicaSetMonitor> ReplicaSetMonitorManager::getMonitorForHost(const vector<string> ReplicaSetMonitorManager::getAllSetNames() const { vector<string> allNames; - stdx::lock_guard<Latch> lk(_mutex); for (const auto& entry : _monitors) { @@ -317,30 +312,31 @@ void ReplicaSetMonitorManager::removeAllMonitors() { } void ReplicaSetMonitorManager::report(BSONObjBuilder* builder, bool forFTDC) { - // Don't hold _mutex the whole time to avoid ever taking a monitor's mutex while holding the - // manager's mutex. Otherwise we could get a deadlock between the manager's, monitor's, and - // ShardRegistry's mutex due to the ReplicaSetMonitor's AsynchronousConfigChangeHook - // potentially calling ShardRegistry::updateConfigServerConnectionString. - auto setNames = getAllSetNames(); - - builder->appendNumber("numReplicaSetMonitorsCreated", _numMonitorsCreated); + std::vector<std::shared_ptr<ReplicaSetMonitor>> monitors; + int numMonitorsCreated; + // Gather relevant data under the lock. Separate out writing it to BSON. + { + stdx::lock_guard lk(_mutex); + _doGarbageCollectionLocked(lk); + for (const auto& [_, weakMonitor] : _monitors) { + if (auto monitor = weakMonitor.lock()) + monitors.push_back(std::move(monitor)); + } + numMonitorsCreated = _numMonitorsCreated; + } + // Now write out the data. + builder->appendNumber("numReplicaSetMonitorsCreated", numMonitorsCreated); { BSONObjBuilder setStats( builder->subobjStart(forFTDC ? "replicaSetPingTimesMillis" : "replicaSets")); - for (const auto& setName : setNames) { - auto monitor = getMonitor(setName); - if (!monitor) { - continue; - } + for (const auto& monitor : monitors) { monitor->appendInfo(setStats, forFTDC); } } - if (_stats) { - _stats->report(builder, forFTDC); - } + _stats->report(builder, forFTDC); } std::shared_ptr<executor::TaskExecutor> ReplicaSetMonitorManager::getExecutor() { |
