diff options
author | Lingzhi Deng <lingzhi.deng@mongodb.com> | 2019-07-15 18:13:46 -0400 |
---|---|---|
committer | Lingzhi Deng <lingzhi.deng@mongodb.com> | 2019-07-15 18:13:46 -0400 |
commit | bb6d532819ca9b2bf57e0a404398d3626e675ef9 (patch) | |
tree | 1ebecba2575772fef6087e2488be4e6277f6c447 | |
parent | 1e2a4a534ac925db108f0508adbe88f0158b1eef (diff) | |
download | mongo-bb6d532819ca9b2bf57e0a404398d3626e675ef9.tar.gz |
wrap sync-related members into SyncConfig
-rw-r--r-- | src/mongo/util/fail_point.cpp | 24 | ||||
-rw-r--r-- | src/mongo/util/fail_point.h | 19 | ||||
-rw-r--r-- | src/mongo/util/fail_point_registry.cpp | 3 | ||||
-rw-r--r-- | src/mongo/util/fail_point_service.cpp | 3 |
4 files changed, 31 insertions, 18 deletions
diff --git a/src/mongo/util/fail_point.cpp b/src/mongo/util/fail_point.cpp index e776bb9f399..ddd50d320ad 100644 --- a/src/mongo/util/fail_point.cpp +++ b/src/mongo/util/fail_point.cpp @@ -89,9 +89,9 @@ void FailPoint::shouldFailCloseBlock() { } bool FailPoint::isSynced() const { - if (_waitFor.size() == 0) + if (_syncConfig.waitFor.size() == 0) return true; - for (auto w : _waitFor) { + for (auto w : _syncConfig.waitFor) { if (_activeSignals.find(w) == _activeSignals.end()) { return false; } @@ -99,13 +99,17 @@ bool FailPoint::isSynced() const { return true; } +bool FailPoint::syncEnabled() const { + return _syncConfig.enabled; +} + void FailPoint::sync() const { - // if (!syncEnabled()) { - // return; - //} + if (!syncEnabled()) { + return; + } stdx::unique_lock<stdx::mutex> lk(_syncMutex); - for (auto& s : _signals) { + for (auto& s : _syncConfig.signals) { _activeSignals.insert(s); } _condVar.notify_all(); @@ -199,8 +203,8 @@ FailPoint::RetCode FailPoint::slowShouldFailOpenBlock( } } -StatusWith<std::tuple<FailPoint::Mode, FailPoint::ValType, BSONObj>> FailPoint::parseBSON( - const BSONObj& obj) { +StatusWith<std::tuple<FailPoint::Mode, FailPoint::ValType, BSONObj, FailPoint::SyncConfig>> +FailPoint::parseBSON(const BSONObj& obj) { Mode mode = FailPoint::alwaysOn; ValType val = 0; const BSONElement modeElem(obj["mode"]); @@ -286,7 +290,9 @@ StatusWith<std::tuple<FailPoint::Mode, FailPoint::ValType, BSONObj>> FailPoint:: data = obj["data"].Obj().getOwned(); } - return std::make_tuple(mode, val, data); + SyncConfig syncConfig; + + return std::make_tuple(mode, val, data, syncConfig); } BSONObj FailPoint::toBSON() const { diff --git a/src/mongo/util/fail_point.h b/src/mongo/util/fail_point.h index 8fb4d749dd2..421959a63bd 100644 --- a/src/mongo/util/fail_point.h +++ b/src/mongo/util/fail_point.h @@ -77,6 +77,15 @@ public: enum Mode { off, alwaysOn, random, nTimes, skip }; enum RetCode { fastOff = 0, slowOff, slowOn, userIgnored }; + struct SyncConfig { + // Is this failpoint configured for failpoints synchronization. + bool enabled; + // Signals to emit when the failpoint is reached. + std::unordered_set<std::string> signals; + // Signals to wait for when the failpoint is reached. + std::unordered_set<std::string> waitFor; + }; + /** * Explicitly resets the seed used for the PRNG in this thread. If not called on a thread, * an instance of SecureRandom is used to seed the PRNG. @@ -86,7 +95,7 @@ public: /** * Parses the FailPoint::Mode, FailPoint::ValType, and data BSONObj from the BSON. */ - static StatusWith<std::tuple<Mode, ValType, BSONObj>> parseBSON(const BSONObj& obj); + static StatusWith<std::tuple<Mode, ValType, BSONObj, SyncConfig>> parseBSON(const BSONObj& obj); FailPoint(); @@ -187,15 +196,11 @@ private: AtomicWord<int> _timesOrPeriod{0}; BSONObj _data; + SyncConfig _syncConfig; + // protects _mode, _timesOrPeriod, _data mutable stdx::mutex _modMutex; - // Is this failpoint configured for failpoints synchronization. - bool _isSync; - // Signals to emit when the failpoint is reached. - std::unordered_set<std::string> _signals; - // Signals to wait for when the failpoint is reached. - std::unordered_set<std::string> _waitFor; /** * Enables this fail point. diff --git a/src/mongo/util/fail_point_registry.cpp b/src/mongo/util/fail_point_registry.cpp index 158d6ab8023..e304b936a27 100644 --- a/src/mongo/util/fail_point_registry.cpp +++ b/src/mongo/util/fail_point_registry.cpp @@ -99,7 +99,8 @@ Status FailPointServerParameter::setFromString(const std::string& str) { FailPoint::Mode mode; FailPoint::ValType val; BSONObj data; - std::tie(mode, val, data) = std::move(swParsedOptions.getValue()); + FailPoint::SyncConfig syncConfig; + std::tie(mode, val, data, syncConfig) = std::move(swParsedOptions.getValue()); _data->setMode(mode, val, data); diff --git a/src/mongo/util/fail_point_service.cpp b/src/mongo/util/fail_point_service.cpp index 77068f82100..6c2941f3b5a 100644 --- a/src/mongo/util/fail_point_service.cpp +++ b/src/mongo/util/fail_point_service.cpp @@ -72,7 +72,8 @@ void setGlobalFailPoint(const std::string& failPointName, const BSONObj& cmdObj) FailPoint::Mode mode; FailPoint::ValType val; BSONObj data; - std::tie(mode, val, data) = uassertStatusOK(FailPoint::parseBSON(cmdObj)); + FailPoint::SyncConfig syncConfig; + std::tie(mode, val, data, syncConfig) = uassertStatusOK(FailPoint::parseBSON(cmdObj)); failPoint->setMode(mode, val, data); warning() << "failpoint: " << failPointName << " set to: " << failPoint->toBSON(); |