diff options
Diffstat (limited to 'src/mongo/db')
6 files changed, 27 insertions, 18 deletions
diff --git a/src/mongo/db/process_health/fault_manager.cpp b/src/mongo/db/process_health/fault_manager.cpp index 1cc855e9b65..818eee320f2 100644 --- a/src/mongo/db/process_health/fault_manager.cpp +++ b/src/mongo/db/process_health/fault_manager.cpp @@ -90,7 +90,7 @@ void FaultManager::set(ServiceContext* svcCtx, std::unique_ptr<FaultManager> new bool FaultManager::isInitialized() { - stdx::lock_guard lock(_stateMutex); + stdx::lock_guard lock(_mutex); return _initialized; } @@ -611,33 +611,38 @@ void FaultManager::updateWithCheckStatus(HealthCheckStatus&& checkStatus) { type, _svcCtx->getFastClockSource(), std::move(checkStatus))); } -FaultManagerConfig FaultManager::getConfig() const { +const FaultManagerConfig& FaultManager::getConfig() const { auto lk = stdx::lock_guard(_mutex); return *_config; } void FaultManager::_init() { - auto lk = stdx::lock_guard(_mutex); + std::set<FaultFacetType> allTypes; + std::vector<std::unique_ptr<HealthObserver>>::size_type observersSize = _observers.size(); + { + auto lk = stdx::lock_guard(_mutex); - _observers = HealthObserverRegistration::instantiateAllObservers(_svcCtx); + _observers = HealthObserverRegistration::instantiateAllObservers(_svcCtx); - // Verify that all observer types are unique. - std::set<FaultFacetType> allTypes; - for (const auto& observer : _observers) { - allTypes.insert(observer->getType()); + for (const auto& observer : _observers) { + allTypes.insert(observer->getType()); + } + observersSize = _observers.size(); } - invariant(allTypes.size() == _observers.size()); + + // Verify that all observer types are unique. + invariant(allTypes.size() == observersSize); // Start the monitor thread after all observers are initialized. _progressMonitor = std::make_unique<ProgressMonitor>(this, _svcCtx, _crashCb); - auto lk2 = stdx::lock_guard(_stateMutex); _initialized = true; + LOGV2_DEBUG(5956701, 1, "Instantiated health observers", "managerState"_attr = str::stream() << state(), - "observersCount"_attr = _observers.size()); + "observersCount"_attr = observersSize); } std::vector<HealthObserver*> FaultManager::getHealthObservers() const { diff --git a/src/mongo/db/process_health/fault_manager.h b/src/mongo/db/process_health/fault_manager.h index e53daefac86..4ef3a6c36e2 100644 --- a/src/mongo/db/process_health/fault_manager.h +++ b/src/mongo/db/process_health/fault_manager.h @@ -115,7 +115,7 @@ public: std::vector<HealthObserver*> getHealthObservers() const; // Gets the aggregate configuration for all process health environment. - FaultManagerConfig getConfig() const; + const FaultManagerConfig& getConfig() const; // Gets the timestamp of the last transition Date_t getLastTransitionTime() const; diff --git a/src/mongo/db/process_health/fault_manager_config.h b/src/mongo/db/process_health/fault_manager_config.h index f6d47bdbf24..072c304376c 100644 --- a/src/mongo/db/process_health/fault_manager_config.h +++ b/src/mongo/db/process_health/fault_manager_config.h @@ -133,6 +133,7 @@ public: } else { // TODO SERVER-61944: this is for kMock1 & kMock2. Remove this branch once mock // types are deleted. + stdx::lock_guard lock(_mutex); if (_facetToIntensityMapForTest.contains(type)) { return _facetToIntensityMapForTest.at(type); } @@ -143,11 +144,12 @@ public: return getIntensity(type); } - bool isHealthObserverEnabled(FaultFacetType type) { + bool isHealthObserverEnabled(FaultFacetType type) const { return getHealthObserverIntensity(type) != HealthObserverIntensityEnum::kOff; } void setIntensityForType(FaultFacetType type, HealthObserverIntensityEnum intensity) { + stdx::lock_guard lock(_mutex); _facetToIntensityMapForTest.insert({type, intensity}); } @@ -245,6 +247,8 @@ private: bool _periodicChecksDisabledForTests = false; stdx::unordered_map<FaultFacetType, HealthObserverIntensityEnum> _facetToIntensityMapForTest; + mutable Mutex _mutex = + MONGO_MAKE_LATCH(HierarchicalAcquisitionLevel(5), "FaultManagerConfig::_mutex"); }; } // namespace process_health diff --git a/src/mongo/db/process_health/fault_manager_test.cpp b/src/mongo/db/process_health/fault_manager_test.cpp index e3466699906..f57f6b869b7 100644 --- a/src/mongo/db/process_health/fault_manager_test.cpp +++ b/src/mongo/db/process_health/fault_manager_test.cpp @@ -48,7 +48,7 @@ TEST(FaultManagerTest, Registration) { // Tests the default health observer intensity of non-critical TEST_F(FaultManagerTest, GetHealthObserverIntensity) { - auto config = manager().getConfig(); + auto& config = manager().getConfig(); ASSERT(config.getHealthObserverIntensity(FaultFacetType::kLdap) == HealthObserverIntensityEnum::kOff); ASSERT(config.getHealthObserverIntensity(FaultFacetType::kDns) == diff --git a/src/mongo/db/process_health/fault_manager_test_suite.h b/src/mongo/db/process_health/fault_manager_test_suite.h index 62332ffb235..d8320e4249b 100644 --- a/src/mongo/db/process_health/fault_manager_test_suite.h +++ b/src/mongo/db/process_health/fault_manager_test_suite.h @@ -106,7 +106,7 @@ public: progressMonitorCheckForTests(crashCb); } - FaultManagerConfig getConfigTest() { + const FaultManagerConfig& getConfigTest() { return getConfig(); } diff --git a/src/mongo/db/process_health/health_observer_test.cpp b/src/mongo/db/process_health/health_observer_test.cpp index 6937f5a70c1..5725fb5b8c0 100644 --- a/src/mongo/db/process_health/health_observer_test.cpp +++ b/src/mongo/db/process_health/health_observer_test.cpp @@ -144,15 +144,15 @@ TEST_F(FaultManagerTest, HealthCheckRunsPeriodically) { << "interval" << 1)))}; RAIIServerParameterControllerForTest _controller{"featureFlagHealthMonitoring", true}; auto faultFacetType = FaultFacetType::kMock1; - auto severity = Severity::kOk; - registerMockHealthObserver(faultFacetType, [&severity] { return severity; }); + AtomicWord<Severity> severity{Severity::kOk}; + registerMockHealthObserver(faultFacetType, [&severity] { return severity.load(); }); assertSoon([this] { return (manager().getFaultState() == FaultState::kStartupCheck); }); auto initialHealthCheckFuture = manager().startPeriodicHealthChecks(); assertSoon([this] { return (manager().getFaultState() == FaultState::kOk); }); - severity = Severity::kFailure; + severity.store(Severity::kFailure); assertSoon([this] { return (manager().getFaultState() == FaultState::kTransientFault); }); resetManager(); // Before fields above go out of scope. } |