summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Shuvalov <andrew.shuvalov@mongodb.com>2021-12-24 00:09:40 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-12-28 21:25:36 +0000
commit07d78c04d349d8ce1cdfc18e751be9492a7d9027 (patch)
tree3ddbb9e51c9987353362bb95d1d56b1f05e5dfb2
parent3f05e7a5dcf014200722dc9a5a0d90f444ea4b0a (diff)
downloadmongo-07d78c04d349d8ce1cdfc18e751be9492a7d9027.tar.gz
SERVER-62259 refactor TransientFaultDeadline cancellation token for the 4.4 backport
-rw-r--r--src/mongo/db/process_health/fault_manager.cpp30
-rw-r--r--src/mongo/db/process_health/fault_manager.h6
2 files changed, 21 insertions, 15 deletions
diff --git a/src/mongo/db/process_health/fault_manager.cpp b/src/mongo/db/process_health/fault_manager.cpp
index 9d9901ada34..46ff38c2bcb 100644
--- a/src/mongo/db/process_health/fault_manager.cpp
+++ b/src/mongo/db/process_health/fault_manager.cpp
@@ -45,6 +45,7 @@
#include "mongo/executor/task_executor_pool.h"
#include "mongo/executor/thread_pool_task_executor.h"
#include "mongo/logv2/log.h"
+#include "mongo/util/future_util.h"
namespace mongo {
@@ -88,21 +89,24 @@ FaultManager::TransientFaultDeadline::TransientFaultDeadline(
FaultManager* faultManager,
std::shared_ptr<executor::TaskExecutor> executor,
Milliseconds timeout)
- : cancelActiveFaultTransition(CancellationSource()),
- activeFaultTransition(
- executor->sleepFor(timeout, cancelActiveFaultTransition.token())
- .thenRunOn(executor)
- .then([faultManager]() { faultManager->transitionToState(FaultState::kActiveFault); })
- .onError([](Status status) {
- LOGV2_WARNING(5937001,
- "The Fault Manager transient fault deadline was disabled.",
- "status"_attr = status);
- })) {}
+ : activeFaultTransition(sleepFor(executor, timeout)
+ .thenRunOn(executor)
+ .then([faultManager, cancelled = cancelActiveFaultTransition]() {
+ // `faultManager` waits for all tasks scheduled in the executor
+ // to be canceled or complete, so this check is safe.
+ if (!cancelled->load()) {
+ faultManager->transitionToState(FaultState::kActiveFault);
+ }
+ })
+ .onError([](Status status) {
+ LOGV2_WARNING(
+ 5937001,
+ "The Fault Manager transient fault deadline was disabled.",
+ "status"_attr = status);
+ })) {}
FaultManager::TransientFaultDeadline::~TransientFaultDeadline() {
- if (!cancelActiveFaultTransition.token().isCanceled()) {
- cancelActiveFaultTransition.cancel();
- }
+ cancelActiveFaultTransition->store(true);
}
FaultManager::FaultManager(ServiceContext* svcCtx,
diff --git a/src/mongo/db/process_health/fault_manager.h b/src/mongo/db/process_health/fault_manager.h
index 823bf724350..c44055072ea 100644
--- a/src/mongo/db/process_health/fault_manager.h
+++ b/src/mongo/db/process_health/fault_manager.h
@@ -154,8 +154,10 @@ private:
virtual ~TransientFaultDeadline();
protected:
- // Cancel timer for transitioning to ActiveFault
- CancellationSource cancelActiveFaultTransition;
+ // Cancel timer for transitioning to ActiveFault.
+ // In later versions, this is using the cancellation token.
+ std::shared_ptr<AtomicWord<bool>> cancelActiveFaultTransition =
+ std::make_shared<AtomicWord<bool>>();
// Fufilled when we should transition to ActiveFault
ExecutorFuture<void> activeFaultTransition;