summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@mongodb.com>2017-04-19 17:24:51 -0400
committerSpencer T Brody <spencer@mongodb.com>2017-06-16 13:51:48 -0400
commit471020b727192e4067a27bcae29db21a59901568 (patch)
tree2d098f2788820d3eb138a32f89392aa943fe9930 /src/mongo
parentdab240e80f5f69df8f7c5796146fa0fed876a84d (diff)
downloadmongo-471020b727192e4067a27bcae29db21a59901568.tar.gz
SERVER-25765 Commands should wait for write concern even if they throw an exception
(cherry picked from commit 5bdd2f49c02e5fe2812ccc6f21502799fa5a3268)
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/commands/dbcommands.cpp45
-rw-r--r--src/mongo/db/s/config/configsvr_split_chunk_command.cpp4
2 files changed, 29 insertions, 20 deletions
diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp
index c282579a7f1..37bcf783d47 100644
--- a/src/mongo/db/commands/dbcommands.cpp
+++ b/src/mongo/db/commands/dbcommands.cpp
@@ -1252,6 +1252,31 @@ void appendOpTimeMetadata(OperationContext* txn,
}
}
+namespace {
+
+void _waitForWriteConcernAndAddToCommandResponse(OperationContext* opCtx,
+ const std::string& commandName,
+ BSONObjBuilder* commandResponseBuilder) {
+ WriteConcernResult res;
+ auto waitForWCStatus =
+ waitForWriteConcern(opCtx,
+ repl::ReplClientInfo::forClient(opCtx->getClient()).getLastOp(),
+ opCtx->getWriteConcern(),
+ &res);
+ Command::appendCommandWCStatus(*commandResponseBuilder, waitForWCStatus, res);
+
+ // SERVER-22421: This code is to ensure error response backwards compatibility with the
+ // user management commands. This can be removed in 3.6.
+ if (!waitForWCStatus.isOK() && Command::isUserManagementCommand(commandName)) {
+ BSONObj temp = commandResponseBuilder->asTempObj().copy();
+ commandResponseBuilder->resetToEmpty();
+ Command::appendCommandStatus(*commandResponseBuilder, waitForWCStatus);
+ commandResponseBuilder->appendElementsUnique(temp);
+ }
+}
+
+} // namespace
+
/**
* this handles
- auth
@@ -1538,28 +1563,14 @@ bool Command::run(OperationContext* txn,
ON_BLOCK_EXIT([&] { txn->setWriteConcern(oldWC); });
txn->setWriteConcern(wcResult.getValue());
+ ON_BLOCK_EXIT(
+ [&] { _waitForWriteConcernAndAddToCommandResponse(txn, getName(), &inPlaceReplyBob); });
+
result = run(txn, db, cmd, 0, errmsg, inPlaceReplyBob);
// Nothing in run() should change the writeConcern.
dassert(SimpleBSONObjComparator::kInstance.evaluate(txn->getWriteConcern().toBSON() ==
wcResult.getValue().toBSON()));
-
- WriteConcernResult res;
- auto waitForWCStatus =
- waitForWriteConcern(txn,
- repl::ReplClientInfo::forClient(txn->getClient()).getLastOp(),
- wcResult.getValue(),
- &res);
- appendCommandWCStatus(inPlaceReplyBob, waitForWCStatus, res);
-
- // SERVER-22421: This code is to ensure error response backwards compatibility with the
- // user management commands. This can be removed in 3.6.
- if (!waitForWCStatus.isOK() && isUserManagementCommand(getName())) {
- BSONObj temp = inPlaceReplyBob.asTempObj().copy();
- inPlaceReplyBob.resetToEmpty();
- appendCommandStatus(inPlaceReplyBob, waitForWCStatus);
- inPlaceReplyBob.appendElementsUnique(temp);
- }
}
// When a linearizable read command is passed in, check to make sure we're reading
diff --git a/src/mongo/db/s/config/configsvr_split_chunk_command.cpp b/src/mongo/db/s/config/configsvr_split_chunk_command.cpp
index a8744987929..05915a29956 100644
--- a/src/mongo/db/s/config/configsvr_split_chunk_command.cpp
+++ b/src/mongo/db/s/config/configsvr_split_chunk_command.cpp
@@ -116,9 +116,7 @@ public:
parsedRequest.getChunkRange(),
parsedRequest.getSplitPoints(),
parsedRequest.getShardName());
- if (!splitChunkResult.isOK()) {
- return appendCommandStatus(result, splitChunkResult);
- }
+ uassertStatusOK(splitChunkResult);
return true;
}