diff options
author | Eric Milkie <milkie@10gen.com> | 2015-09-30 10:00:36 -0400 |
---|---|---|
committer | Eric Milkie <milkie@10gen.com> | 2015-09-30 10:00:39 -0400 |
commit | e11728471f3c428ef5c6fdd4b458c2a50013ce04 (patch) | |
tree | 82ed4f1c99715b3255b347c11dc4d56968eff9b7 | |
parent | 7c8c1f8d508f62aeb3dbc1ac093330fb5a872174 (diff) | |
download | mongo-e11728471f3c428ef5c6fdd4b458c2a50013ce04.tar.gz |
SERVER-20487 actually honor WC for batch write commands, even for errors
-rw-r--r-- | jstests/replsets/batch_write_command_wc.js | 4 | ||||
-rw-r--r-- | src/mongo/db/commands/write_commands/batch_executor.cpp | 29 |
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)); } // |