summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/replsets/batch_write_command_wc.js4
-rw-r--r--src/mongo/db/commands/write_commands/batch_executor.cpp29
2 files changed, 14 insertions, 19 deletions
diff --git a/jstests/replsets/batch_write_command_wc.js b/jstests/replsets/batch_write_command_wc.js
index 24212154a49..997648abc96 100644
--- a/jstests/replsets/batch_write_command_wc.js
+++ b/jstests/replsets/batch_write_command_wc.js
@@ -85,7 +85,7 @@ assert(result.writeConcernError);
assert.eq(1, coll.count());
//
-// Two ordered inserts, write error and wc error not reported
+// Two ordered inserts, write error and wc error both reported
coll.remove({});
printjson( request = {insert : coll.getName(),
documents: [{a:1},{$invalid:'doc'}],
@@ -95,7 +95,7 @@ assert(result.ok);
assert.eq(1, result.n);
assert.eq(result.writeErrors.length, 1);
assert.eq(result.writeErrors[0].index, 1);
-assert(!result.writeConcernError);
+assert(result.writeConcernError);
assert.eq(1, coll.count());
//
diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp
index 43dab2649c7..bedc9c8f4bf 100644
--- a/src/mongo/db/commands/write_commands/batch_executor.cpp
+++ b/src/mongo/db/commands/write_commands/batch_executor.cpp
@@ -321,27 +321,22 @@ void WriteBatchExecutor::executeBatch(const BatchedCommandRequest& request,
bulkExecute(request, &upserted, &writeErrors);
//
- // Try to enforce the write concern if everything succeeded (unordered or ordered)
- // OR if something succeeded and we're unordered.
- //
+ // Always try to enforce the write concern, even if everything failed.
+ // If something failed, we have already set the lastOp to be the last op to have succeeded
+ // and written to the oplog.
unique_ptr<WCErrorDetail> wcError;
- bool needToEnforceWC = writeErrors.empty() ||
- (!request.getOrdered() && writeErrors.size() < request.sizeWriteOps());
-
- if (needToEnforceWC) {
- {
- stdx::lock_guard<Client> lk(*_txn->getClient());
- CurOp::get(_txn)->setMessage_inlock("waiting for write concern");
- }
+ {
+ stdx::lock_guard<Client> lk(*_txn->getClient());
+ CurOp::get(_txn)->setMessage_inlock("waiting for write concern");
+ }
- WriteConcernResult res;
- Status status = waitForWriteConcern(
- _txn, repl::ReplClientInfo::forClient(_txn->getClient()).getLastOp(), &res);
+ WriteConcernResult res;
+ Status status = waitForWriteConcern(
+ _txn, repl::ReplClientInfo::forClient(_txn->getClient()).getLastOp(), &res);
- if (!status.isOK()) {
- wcError.reset(toWriteConcernError(status, res));
- }
+ if (!status.isOK()) {
+ wcError.reset(toWriteConcernError(status, res));
}
//