summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Chan <jason.chan@10gen.com>2019-07-17 17:35:05 -0400
committerJason Chan <jason.chan@10gen.com>2019-07-17 17:35:05 -0400
commit53e25a0c588a4256a73589ca777cfc4b436d544c (patch)
tree828e6fc4e7a19b026c6b97ae85eb576df39fc510
parentff31e4391df93b9186bee6366e194c08173fd1c7 (diff)
downloadmongo-failpoint_sync.tar.gz
wrap condition variable waitForConditionOrInterruptNoAssertUntilfailpoint_sync
-rw-r--r--src/mongo/db/commands/fail_point_cmd.cpp2
-rw-r--r--src/mongo/util/fail_point.cpp17
-rw-r--r--src/mongo/util/fail_point.h6
-rw-r--r--src/mongo/util/fail_point_service.cpp4
-rw-r--r--src/mongo/util/fail_point_service.h2
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