summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2017-06-23 13:35:51 -0400
committerMathias Stearn <mathias@10gen.com>2017-07-13 16:53:12 -0400
commitb6abff538f84abecae2bd7137173a37a8626ac14 (patch)
tree93def0ddaa7f6fe751da4e3bee9aaa6d95ca8a29
parent8c228549b7e29f0c83eb94f4c913e61cd61523a9 (diff)
downloadmongo-b6abff538f84abecae2bd7137173a37a8626ac14.tar.gz
SERVER-29731 Get errmsg out of public Command API
-rw-r--r--src/mongo/db/commands.cpp13
-rw-r--r--src/mongo/db/commands.h6
-rw-r--r--src/mongo/db/commands/write_commands/write_commands.cpp1
-rw-r--r--src/mongo/db/service_entry_point_mongod.cpp7
-rw-r--r--src/mongo/s/commands/cluster_write_cmd.cpp8
-rw-r--r--src/mongo/s/commands/strategy.cpp7
6 files changed, 18 insertions, 24 deletions
diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp
index 18e38077238..b98eb1bcc6f 100644
--- a/src/mongo/db/commands.cpp
+++ b/src/mongo/db/commands.cpp
@@ -189,9 +189,8 @@ BSONObj Command::runCommandDirectly(OperationContext* opCtx, const OpMsgRequest&
BSONObjBuilder out;
try {
- std::string errmsg;
- bool ok = command->enhancedRun(opCtx, request, errmsg, out);
- appendCommandStatus(out, ok, errmsg);
+ bool ok = command->enhancedRun(opCtx, request, out);
+ appendCommandStatus(out, ok);
} catch (const StaleConfigException& ex) {
// These exceptions are intended to be handled at a higher level and cannot losslessly
// round-trip through Status.
@@ -367,13 +366,17 @@ bool Command::isUserManagementCommand(const std::string& name) {
bool BasicCommand::enhancedRun(OperationContext* opCtx,
const OpMsgRequest& request,
- std::string& errmsg,
BSONObjBuilder& result) {
uassert(40472,
str::stream() << "The " << getName() << " command does not support document sequences.",
request.sequences.empty());
- return run(opCtx, request.getDatabase().toString(), request.body, errmsg, result);
+ std::string errmsg;
+ bool ok = run(opCtx, request.getDatabase().toString(), request.body, errmsg, result);
+ if (!errmsg.empty()) {
+ appendCommandStatus(result, ok, errmsg);
+ }
+ return ok;
}
BSONObj Command::filterCommandRequestForPassthrough(const BSONObj& cmdObj) {
diff --git a/src/mongo/db/commands.h b/src/mongo/db/commands.h
index 1692584c02f..1953866e624 100644
--- a/src/mongo/db/commands.h
+++ b/src/mongo/db/commands.h
@@ -105,7 +105,6 @@ public:
*/
virtual bool enhancedRun(OperationContext* opCtx,
const OpMsgRequest& request,
- std::string& errmsg,
BSONObjBuilder& result) = 0;
/**
@@ -392,7 +391,9 @@ public:
static Command* findCommand(StringData name);
// Helper for setting errmsg and ok field in command result object.
- static void appendCommandStatus(BSONObjBuilder& result, bool ok, const std::string& errmsg);
+ static void appendCommandStatus(BSONObjBuilder& result,
+ bool ok,
+ const std::string& errmsg = {});
// @return s.isOK()
static bool appendCommandStatus(BSONObjBuilder& result, const Status& status);
@@ -571,7 +572,6 @@ public:
*/
bool enhancedRun(OperationContext* opCtx,
const OpMsgRequest& request,
- std::string& errmsg,
BSONObjBuilder& result) final;
/**
diff --git a/src/mongo/db/commands/write_commands/write_commands.cpp b/src/mongo/db/commands/write_commands/write_commands.cpp
index dcab92230d2..2c9d5a37c8f 100644
--- a/src/mongo/db/commands/write_commands/write_commands.cpp
+++ b/src/mongo/db/commands/write_commands/write_commands.cpp
@@ -205,7 +205,6 @@ public:
bool enhancedRun(OperationContext* opCtx,
const OpMsgRequest& request,
- std::string& errmsg,
BSONObjBuilder& result) final {
try {
runImpl(opCtx, request, result);
diff --git a/src/mongo/db/service_entry_point_mongod.cpp b/src/mongo/db/service_entry_point_mongod.cpp
index 470feb11bd1..0491274939f 100644
--- a/src/mongo/db/service_entry_point_mongod.cpp
+++ b/src/mongo/db/service_entry_point_mongod.cpp
@@ -425,7 +425,6 @@ bool runCommandImpl(OperationContext* opCtx,
return result;
}
- std::string errmsg;
bool result;
if (!command->supportsWriteConcern(cmd)) {
if (commandSpecifiesWriteConcern(cmd)) {
@@ -437,7 +436,7 @@ bool runCommandImpl(OperationContext* opCtx,
return result;
}
- result = command->enhancedRun(opCtx, request, errmsg, inPlaceReplyBob);
+ result = command->enhancedRun(opCtx, request, inPlaceReplyBob);
} else {
auto wcResult = extractWriteConcern(opCtx, cmd, db);
if (!wcResult.isOK()) {
@@ -456,7 +455,7 @@ bool runCommandImpl(OperationContext* opCtx,
opCtx, command->getName(), &inPlaceReplyBob);
});
- result = command->enhancedRun(opCtx, request, errmsg, inPlaceReplyBob);
+ result = command->enhancedRun(opCtx, request, inPlaceReplyBob);
// Nothing in run() should change the writeConcern.
dassert(SimpleBSONObjComparator::kInstance.evaluate(opCtx->getWriteConcern().toBSON() ==
@@ -481,7 +480,7 @@ bool runCommandImpl(OperationContext* opCtx,
}
}
- Command::appendCommandStatus(inPlaceReplyBob, result, errmsg);
+ Command::appendCommandStatus(inPlaceReplyBob, result);
auto operationTime = computeOperationTime(
opCtx, startOperationTime, readConcernArgsStatus.getValue().getLevel());
diff --git a/src/mongo/s/commands/cluster_write_cmd.cpp b/src/mongo/s/commands/cluster_write_cmd.cpp
index b4dd380fae5..b0c5e248c8f 100644
--- a/src/mongo/s/commands/cluster_write_cmd.cpp
+++ b/src/mongo/s/commands/cluster_write_cmd.cpp
@@ -128,7 +128,6 @@ public:
bool enhancedRun(OperationContext* opCtx,
const OpMsgRequest& request,
- string& errmsg,
BSONObjBuilder& result) final {
BatchedCommandRequest batchedRequest(_writeType);
batchedRequest.parseRequest(request);
@@ -180,13 +179,8 @@ public:
->addHostOpTimes(writer.getStats().getWriteOpTimes());
}
- // TODO
- // There's a pending issue about how to report response here. If we use
- // the command infra-structure, we should reuse the 'errmsg' field. But
- // we have already filed that message inside the BatchCommandResponse.
- // return response.getOk();
result.appendElements(response.toBSON());
- return true;
+ return response.getOk();
}
protected:
diff --git a/src/mongo/s/commands/strategy.cpp b/src/mongo/s/commands/strategy.cpp
index c4f20e93b82..915809a03aa 100644
--- a/src/mongo/s/commands/strategy.cpp
+++ b/src/mongo/s/commands/strategy.cpp
@@ -220,22 +220,21 @@ void execCommandClient(OperationContext* opCtx,
}
try {
- std::string errmsg;
bool ok = false;
if (!supportsWriteConcern) {
- ok = c->enhancedRun(opCtx, request, errmsg, result);
+ ok = c->enhancedRun(opCtx, request, result);
} else {
// Change the write concern while running the command.
const auto oldWC = opCtx->getWriteConcern();
ON_BLOCK_EXIT([&] { opCtx->setWriteConcern(oldWC); });
opCtx->setWriteConcern(wcResult.getValue());
- ok = c->enhancedRun(opCtx, request, errmsg, result);
+ ok = c->enhancedRun(opCtx, request, result);
}
if (!ok) {
c->incrementCommandsFailed();
}
- Command::appendCommandStatus(result, ok, errmsg);
+ Command::appendCommandStatus(result, ok);
} catch (const DBException& e) {
result.resetToEmpty();
const int code = e.getCode();