summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/fail_point_cmd.cpp
diff options
context:
space:
mode:
authorEsha Maharishi <esha.maharishi@mongodb.com>2016-09-07 18:41:36 -0400
committerEsha Maharishi <esha.maharishi@mongodb.com>2016-09-12 15:16:10 -0400
commitaf654fa43fe293f9c3551ac50e908fcc618ca875 (patch)
treef864a4c6fe94caf883dba2095791d35273a73466 /src/mongo/db/commands/fail_point_cmd.cpp
parenta3e0d0bfde22d7fd7ab89c31fe34ddf19948ad9b (diff)
downloadmongo-af654fa43fe293f9c3551ac50e908fcc618ca875.tar.gz
SERVER-26008 allow setting failpoints on the command line
Diffstat (limited to 'src/mongo/db/commands/fail_point_cmd.cpp')
-rw-r--r--src/mongo/db/commands/fail_point_cmd.cpp62
1 files changed, 5 insertions, 57 deletions
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<int32_t>(std::numeric_limits<int32_t>::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;