From af654fa43fe293f9c3551ac50e908fcc618ca875 Mon Sep 17 00:00:00 2001 From: Esha Maharishi Date: Wed, 7 Sep 2016 18:41:36 -0400 Subject: SERVER-26008 allow setting failpoints on the command line --- src/mongo/db/commands/fail_point_cmd.cpp | 62 +++----------------------------- 1 file changed, 5 insertions(+), 57 deletions(-) (limited to 'src/mongo/db/commands/fail_point_cmd.cpp') diff --git a/src/mongo/db/commands/fail_point_cmd.cpp b/src/mongo/db/commands/fail_point_cmd.cpp index 2df83c93427..a298c267647 100644 --- a/src/mongo/db/commands/fail_point_cmd.cpp +++ b/src/mongo/db/commands/fail_point_cmd.cpp @@ -105,64 +105,12 @@ public: return false; } - FailPoint::Mode mode = FailPoint::alwaysOn; - FailPoint::ValType val = 0; - - const BSONElement modeElem(cmdObj["mode"]); - if (modeElem.eoo()) { - result.appendElements(failPoint->toBSON()); - return true; - } else if (modeElem.type() == String) { - const string modeStr(modeElem.valuestr()); - - if (modeStr == "off") { - mode = FailPoint::off; - } else if (modeStr == "alwaysOn") { - mode = FailPoint::alwaysOn; - } else { - errmsg = "unknown mode: " + modeStr; - return false; - } - } else if (modeElem.type() == Object) { - const BSONObj modeObj(modeElem.Obj()); - - if (modeObj.hasField("times")) { - mode = FailPoint::nTimes; - const int intVal = modeObj["times"].numberInt(); - - if (intVal < 0) { - errmsg = "times should be positive"; - return false; - } - - val = intVal; - } else if (modeObj.hasField("activationProbability")) { - mode = FailPoint::random; - const double activationProbability = - modeObj["activationProbability"].numberDouble(); - if (activationProbability < 0 || activationProbability > 1) { - errmsg = str::stream() - << "activationProbability must be between 0.0 and 1.0; found " - << activationProbability; - return false; - } - val = static_cast(std::numeric_limits::max() * - activationProbability); - } else { - errmsg = "invalid mode object"; - return false; - } - } else { - errmsg = "invalid mode format"; - return false; - } - - BSONObj dataObj; - if (cmdObj.hasField("data")) { - dataObj = cmdObj["data"].Obj(); - } + FailPoint::Mode mode; + FailPoint::ValType val; + BSONObj data; + std::tie(mode, val, data) = uassertStatusOK(FailPoint::parseBSON(cmdObj)); - failPoint->setMode(mode, val, dataObj); + failPoint->setMode(mode, val, data); warning() << "failpoint: " << failPointName << " set to: " << failPoint->toBSON(); return true; -- cgit v1.2.1