summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Shuvalov <andrew.shuvalov@mongodb.com>2021-12-24 19:20:00 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-12-28 21:25:36 +0000
commitfe669a72aa4f6913954a017fac259406987d2462 (patch)
treed72e1deeb08c7e3507b894a4062dc45828323ffd
parent776d8f5b7d4d674b2108ccc9335e0355f1166245 (diff)
downloadmongo-fe669a72aa4f6913954a017fac259406987d2462.tar.gz
SERVER-62259 Replace cancellation tokens in the health monitoring backport to 4.4
-rw-r--r--src/mongo/db/process_health/fault_manager.cpp5
-rw-r--r--src/mongo/db/process_health/fault_manager.h4
-rw-r--r--src/mongo/db/process_health/health_observer.h2
-rw-r--r--src/mongo/db/process_health/health_observer_base.cpp6
-rw-r--r--src/mongo/db/process_health/health_observer_base.h4
5 files changed, 11 insertions, 10 deletions
diff --git a/src/mongo/db/process_health/fault_manager.cpp b/src/mongo/db/process_health/fault_manager.cpp
index 9b203c23823..46c049946c6 100644
--- a/src/mongo/db/process_health/fault_manager.cpp
+++ b/src/mongo/db/process_health/fault_manager.cpp
@@ -158,7 +158,7 @@ void FaultManager::schedulePeriodicHealthCheckThread(bool immediately) {
}
FaultManager::~FaultManager() {
- _managerShuttingDownCancellationSource.cancel();
+ _managerShuttingDownCancellation->store(true);
_taskExecutor->shutdown();
LOGV2(5936601, "Shutting down periodic health checks");
@@ -230,9 +230,8 @@ void FaultManager::healthCheck() {
std::vector<HealthObserver*> observers = FaultManager::getHealthObservers();
// Start checks outside of lock.
- auto token = _managerShuttingDownCancellationSource.token();
for (auto observer : observers) {
- observer->periodicCheck(*this, _taskExecutor, token);
+ observer->periodicCheck(*this, _taskExecutor, _managerShuttingDownCancellation);
}
// Garbage collect all resolved fault facets.
diff --git a/src/mongo/db/process_health/fault_manager.h b/src/mongo/db/process_health/fault_manager.h
index bd9b3130f73..a14f0ae69c3 100644
--- a/src/mongo/db/process_health/fault_manager.h
+++ b/src/mongo/db/process_health/fault_manager.h
@@ -148,7 +148,9 @@ private:
AtomicWord<bool> _firstTimeInitExecuted{false};
// This source is canceled before the _taskExecutor shutdown(). It
// can be used to check for the start of the shutdown sequence.
- CancellationSource _managerShuttingDownCancellationSource;
+ // In later versions, this is using the cancellation token.
+ std::shared_ptr<AtomicWord<bool>> _managerShuttingDownCancellation =
+ std::make_shared<AtomicWord<bool>>();
// Manager owns all observer instances.
std::vector<std::unique_ptr<HealthObserver>> _observers;
boost::optional<executor::TaskExecutor::CallbackHandle> _periodicHealthCheckCbHandle;
diff --git a/src/mongo/db/process_health/health_observer.h b/src/mongo/db/process_health/health_observer.h
index 40c9d379db7..f970b8d4ac8 100644
--- a/src/mongo/db/process_health/health_observer.h
+++ b/src/mongo/db/process_health/health_observer.h
@@ -87,7 +87,7 @@ public:
*/
virtual void periodicCheck(FaultFacetsContainerFactory& factory,
std::shared_ptr<executor::TaskExecutor> taskExecutor,
- CancellationToken token) = 0;
+ std::shared_ptr<AtomicWord<bool>> cancellationToken) = 0;
/**
* @return HealthObserverIntensity
diff --git a/src/mongo/db/process_health/health_observer_base.cpp b/src/mongo/db/process_health/health_observer_base.cpp
index d3f6dd03c30..d4def18288d 100644
--- a/src/mongo/db/process_health/health_observer_base.cpp
+++ b/src/mongo/db/process_health/health_observer_base.cpp
@@ -41,7 +41,7 @@ HealthObserverBase::HealthObserverBase(ServiceContext* svcCtx) : _svcCtx(svcCtx)
void HealthObserverBase::periodicCheck(FaultFacetsContainerFactory& factory,
std::shared_ptr<executor::TaskExecutor> taskExecutor,
- CancellationToken token) {
+ std::shared_ptr<AtomicWord<bool>> cancellationToken) {
// TODO(SERVER-59368): fix this for runtime options support.
if (getIntensity() == HealthObserverIntensity::kOff) {
return;
@@ -65,8 +65,8 @@ void HealthObserverBase::periodicCheck(FaultFacetsContainerFactory& factory,
}
// Do the health check.
- taskExecutor->schedule([this, &factory, token, taskExecutor](Status status) {
- periodicCheckImpl({token, taskExecutor})
+ taskExecutor->schedule([this, &factory, cancellationToken, taskExecutor](Status status) {
+ periodicCheckImpl({cancellationToken, taskExecutor})
.then([this, &factory](HealthCheckStatus&& checkStatus) mutable {
const auto severity = checkStatus.getSeverity();
factory.updateWithCheckStatus(std::move(checkStatus));
diff --git a/src/mongo/db/process_health/health_observer_base.h b/src/mongo/db/process_health/health_observer_base.h
index 382f237c6fa..69bff86c8a5 100644
--- a/src/mongo/db/process_health/health_observer_base.h
+++ b/src/mongo/db/process_health/health_observer_base.h
@@ -68,13 +68,13 @@ public:
// Every observer should implement periodicCheckImpl() for specific tests.
void periodicCheck(FaultFacetsContainerFactory& factory,
std::shared_ptr<executor::TaskExecutor> taskExecutor,
- CancellationToken token) override;
+ std::shared_ptr<AtomicWord<bool>> cancellationToken) override;
HealthObserverLivenessStats getStats() const override;
protected:
struct PeriodicHealthCheckContext {
- CancellationToken cancellationToken;
+ std::shared_ptr<AtomicWord<bool>> cancellationToken;
std::shared_ptr<executor::TaskExecutor> taskExecutor;
};