From bb6d532819ca9b2bf57e0a404398d3626e675ef9 Mon Sep 17 00:00:00 2001 From: Lingzhi Deng Date: Mon, 15 Jul 2019 18:13:46 -0400 Subject: wrap sync-related members into SyncConfig --- src/mongo/util/fail_point.cpp | 24 +++++++++++++++--------- src/mongo/util/fail_point.h | 19 ++++++++++++------- src/mongo/util/fail_point_registry.cpp | 3 ++- 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 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> FailPoint::parseBSON( - const BSONObj& obj) { +StatusWith> +FailPoint::parseBSON(const BSONObj& obj) { Mode mode = FailPoint::alwaysOn; ValType val = 0; const BSONElement modeElem(obj["mode"]); @@ -286,7 +290,9 @@ StatusWith> 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 signals; + // Signals to wait for when the failpoint is reached. + std::unordered_set 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> parseBSON(const BSONObj& obj); + static StatusWith> parseBSON(const BSONObj& obj); FailPoint(); @@ -187,15 +196,11 @@ private: AtomicWord _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 _signals; - // Signals to wait for when the failpoint is reached. - std::unordered_set _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(); -- cgit v1.2.1