From 53e25a0c588a4256a73589ca777cfc4b436d544c Mon Sep 17 00:00:00 2001 From: Jason Chan Date: Wed, 17 Jul 2019 17:35:05 -0400 Subject: wrap condition variable waitForConditionOrInterruptNoAssertUntil --- src/mongo/db/commands/fail_point_cmd.cpp | 2 +- src/mongo/util/fail_point.cpp | 17 ++++------------- src/mongo/util/fail_point.h | 6 +++--- src/mongo/util/fail_point_service.cpp | 4 ++-- src/mongo/util/fail_point_service.h | 2 +- 5 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/mongo/db/commands/fail_point_cmd.cpp b/src/mongo/db/commands/fail_point_cmd.cpp index 408a5857470..bd69c2f52c9 100644 --- a/src/mongo/db/commands/fail_point_cmd.cpp +++ b/src/mongo/db/commands/fail_point_cmd.cpp @@ -99,7 +99,7 @@ public: const std::string failPointName(cmdObj.firstElement().str()); if (failPointName == "now" && cmdObj.hasField("sync")) - syncNow(cmdObj); + syncNow(opCtx, cmdObj); else setGlobalFailPoint(failPointName, cmdObj); diff --git a/src/mongo/util/fail_point.cpp b/src/mongo/util/fail_point.cpp index 30e1fbe8e8a..8e618a585b0 100644 --- a/src/mongo/util/fail_point.cpp +++ b/src/mongo/util/fail_point.cpp @@ -103,7 +103,7 @@ bool FailPoint::syncEnabled() const { return _syncConfig.enabled; } -void FailPoint::sync() const { +void FailPoint::sync(OperationContext* opCtx) const { if (!syncEnabled()) { return; } @@ -117,20 +117,11 @@ void FailPoint::sync() const { ? Date_t::now() + Seconds(_syncConfig.timeoutSec) : Date_t::max(); while (!isSynced()) { - Milliseconds timeout; - if (deadline == Date_t::max()) { - timeout = Milliseconds::max(); - } else { - auto now = Date_t::now(); - if (deadline <= now) { - timeout = Milliseconds(0); - } else { - timeout = deadline - Date_t::now(); - } - } + auto waitStatus = + opCtx->waitForConditionOrInterruptNoAssertUntil(_condVar, lk, deadline); uassert(ErrorCodes::ExceededTimeLimit, "Timed out waiting for signals", - _condVar.wait_for(lk, timeout.toSystemDuration()) != stdx::cv_status::timeout); + waitStatus.getValue() != stdx::cv_status::timeout); } if (_syncConfig.clearSignals && !_syncConfig.waitFor.empty()) { for (auto& w : _syncConfig.waitFor) { diff --git a/src/mongo/util/fail_point.h b/src/mongo/util/fail_point.h index 7c00827fc73..7b8b51d21e3 100644 --- a/src/mongo/util/fail_point.h +++ b/src/mongo/util/fail_point.h @@ -149,7 +149,7 @@ public: */ void shouldFailCloseBlock(); - void sync() const; + void sync(OperationContext* opCtx) const; bool syncEnabled() const; @@ -305,10 +305,10 @@ inline void MONGO_FAIL_POINT_PAUSE_WHILE_SET_OR_INTERRUPTED(OperationContext* op } } -inline void MONGO_FAIL_POINT_SYNC(FailPoint& failPoint) { +inline void MONGO_FAIL_POINT_SYNC(OperationContext* opCtx, FailPoint& failPoint) { if (MONGO_FAIL_POINT(failPoint)) { if (failPoint.syncEnabled()) { - failPoint.sync(); + failPoint.sync(opCtx); } else { while (MONGO_FAIL_POINT(failPoint)) { sleepmillis(100); diff --git a/src/mongo/util/fail_point_service.cpp b/src/mongo/util/fail_point_service.cpp index f2ceb8bc42f..eb0f5df6cb7 100644 --- a/src/mongo/util/fail_point_service.cpp +++ b/src/mongo/util/fail_point_service.cpp @@ -62,7 +62,7 @@ FailPointRegistry* getGlobalFailPointRegistry() { return _fpRegistry.get(); } -void syncNow(const BSONObj& cmdObj) { +void syncNow(OperationContext* opCtx, const BSONObj& cmdObj) { FailPoint fp; FailPoint::Mode mode; @@ -74,7 +74,7 @@ void syncNow(const BSONObj& cmdObj) { fp.setMode(mode, val, data, syncConfig); warning() << "failpoint: 'now' set to: " << fp.toBSON(); - MONGO_FAIL_POINT_SYNC(fp); + MONGO_FAIL_POINT_SYNC(opCtx, fp); warning() << "failpoint: 'now' synced"; } diff --git a/src/mongo/util/fail_point_service.h b/src/mongo/util/fail_point_service.h index 12903ddbcea..2beda426433 100644 --- a/src/mongo/util/fail_point_service.h +++ b/src/mongo/util/fail_point_service.h @@ -43,7 +43,7 @@ FailPointRegistry* getGlobalFailPointRegistry(); /** * Signals or waits inline. */ -void syncNow(const BSONObj& cmdObj); +void syncNow(OperationContext* opCtx, const BSONObj& cmdObj); /** * Set a fail point in the global registry to a given value via BSON -- cgit v1.2.1