summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Chan <jason.chan@10gen.com>2019-07-15 18:04:10 -0400
committerJason Chan <jason.chan@10gen.com>2019-07-15 18:04:10 -0400
commit1e2a4a534ac925db108f0508adbe88f0158b1eef (patch)
tree33b89e6c1f18e0d027bff6e83656680cdad44718
parent7e1fc2257b09d4fe399576d12747801d5d8bc35c (diff)
downloadmongo-1e2a4a534ac925db108f0508adbe88f0158b1eef.tar.gz
sync logic
-rw-r--r--src/mongo/util/fail_point.cpp31
-rw-r--r--src/mongo/util/fail_point.h21
2 files changed, 52 insertions, 0 deletions
diff --git a/src/mongo/util/fail_point.cpp b/src/mongo/util/fail_point.cpp
index 9582a0e4939..e776bb9f399 100644
--- a/src/mongo/util/fail_point.cpp
+++ b/src/mongo/util/fail_point.cpp
@@ -74,6 +74,10 @@ thread_local std::unique_ptr<FailPointPRNG> FailPointPRNG::_failPointPrng;
} // namespace
+std::unordered_set<std::string> FailPoint::_activeSignals;
+stdx::mutex FailPoint::_syncMutex;
+stdx::condition_variable FailPoint::_condVar;
+
void FailPoint::setThreadPRNGSeed(int32_t seed) {
FailPointPRNG::current()->resetSeed(seed);
}
@@ -84,6 +88,33 @@ void FailPoint::shouldFailCloseBlock() {
_fpInfo.subtractAndFetch(1);
}
+bool FailPoint::isSynced() const {
+ if (_waitFor.size() == 0)
+ return true;
+ for (auto w : _waitFor) {
+ if (_activeSignals.find(w) == _activeSignals.end()) {
+ return false;
+ }
+ }
+ return true;
+}
+
+void FailPoint::sync() const {
+ // if (!syncEnabled()) {
+ // return;
+ //}
+ stdx::unique_lock<stdx::mutex> lk(_syncMutex);
+
+ for (auto& s : _signals) {
+ _activeSignals.insert(s);
+ }
+ _condVar.notify_all();
+ auto timeout = Seconds(60);
+ while (!isSynced()) {
+ _condVar.wait_for(lk, timeout.toSystemDuration());
+ }
+}
+
void FailPoint::setMode(Mode mode, ValType val, const BSONObj& extra) {
/**
* Outline:
diff --git a/src/mongo/util/fail_point.h b/src/mongo/util/fail_point.h
index 7f83c165cd7..8fb4d749dd2 100644
--- a/src/mongo/util/fail_point.h
+++ b/src/mongo/util/fail_point.h
@@ -135,6 +135,12 @@ public:
*/
void shouldFailCloseBlock();
+ void sync() const;
+
+ bool isSynced() const;
+
+ bool syncEnabled() const;
+
/**
* Changes the settings of this fail point. This will turn off the fail point
* and waits for all dynamic instances referencing this fail point to go away before
@@ -167,6 +173,9 @@ public:
private:
static const ValType ACTIVE_BIT = 1 << 31;
static const ValType REF_COUNTER_MASK = ~ACTIVE_BIT;
+ static std::unordered_set<std::string> _activeSignals;
+ static stdx::mutex _syncMutex;
+ static stdx::condition_variable _condVar;
// Bit layout:
// 31: tells whether this fail point is active.
@@ -283,6 +292,18 @@ inline void MONGO_FAIL_POINT_PAUSE_WHILE_SET_OR_INTERRUPTED(OperationContext* op
}
}
+inline void MONGO_FAIL_POINT_SYNC(FailPoint& failPoint) {
+ if (MONGO_FAIL_POINT(failPoint)) {
+ if (failPoint.syncEnabled()) {
+ failPoint.sync();
+ } else {
+ while (MONGO_FAIL_POINT(failPoint)) {
+ sleepmillis(100);
+ }
+ }
+ }
+}
+
/**
* Macro for creating a fail point with block context. Also use this when
* you want to access the data stored in the fail point.