diff options
author | Eliot Horowitz <eliot@10gen.com> | 2015-03-06 09:16:49 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2015-03-08 18:01:16 -0400 |
commit | af56dea51db8d96773ed541927522ee18ff96f31 (patch) | |
tree | b911c6a35f343bb18b282c81ca083c7764d57e76 /src/mongo/db/commands/write_commands | |
parent | 4f4387d9b98c2da5eb5a4b070a1b28e856f8ecca (diff) | |
download | mongo-af56dea51db8d96773ed541927522ee18ff96f31.tar.gz |
SERVER-17489: in bulk ops, only mark last operation with commit=synchronous
Diffstat (limited to 'src/mongo/db/commands/write_commands')
-rw-r--r-- | src/mongo/db/commands/write_commands/batch_executor.cpp | 28 | ||||
-rw-r--r-- | src/mongo/db/commands/write_commands/batch_executor.h | 2 |
2 files changed, 23 insertions, 7 deletions
diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp index a23282cd56a..34f4a448021 100644 --- a/src/mongo/db/commands/write_commands/batch_executor.cpp +++ b/src/mongo/db/commands/write_commands/batch_executor.cpp @@ -227,11 +227,6 @@ namespace mongo { return; } - if ( writeConcern.syncMode == WriteConcernOptions::JOURNAL || - writeConcern.syncMode == WriteConcernOptions::FSYNC ) { - _txn->recoveryUnit()->goingToAwaitCommit(); - } - if ( request.sizeWriteOps() == 0u ) { toBatchError( Status( ErrorCodes::InvalidLength, "no write ops were included in the batch" ), @@ -268,7 +263,7 @@ namespace mongo { // Stops on error if batch is ordered. // - bulkExecute( request, &upserted, &writeErrors ); + bulkExecute( request, writeConcern, &upserted, &writeErrors ); // // Try to enforce the write concern if everything succeeded (unordered or ordered) @@ -758,16 +753,28 @@ namespace mongo { Collection* _collection; }; + void setupSynchronousCommit( const WriteConcernOptions& writeConcern, + OperationContext* txn ) { + if ( writeConcern.syncMode == WriteConcernOptions::JOURNAL || + writeConcern.syncMode == WriteConcernOptions::FSYNC ) { + txn->recoveryUnit()->goingToAwaitCommit(); + } + } + void WriteBatchExecutor::bulkExecute( const BatchedCommandRequest& request, + const WriteConcernOptions& writeConcern, std::vector<BatchedUpsertDetail*>* upsertedIds, std::vector<WriteErrorDetail*>* errors ) { if ( request.getBatchType() == BatchedCommandRequest::BatchType_Insert ) { - execInserts( request, errors ); + execInserts( request, writeConcern, errors ); } else if ( request.getBatchType() == BatchedCommandRequest::BatchType_Update ) { for ( size_t i = 0; i < request.sizeWriteOps(); i++ ) { + if ( i + 1 == request.sizeWriteOps() ) + setupSynchronousCommit( writeConcern, _txn ); + WriteErrorDetail* error = NULL; BSONObj upsertedId; execUpdate( BatchItemRef( &request, i ), &upsertedId, &error ); @@ -790,6 +797,9 @@ namespace mongo { dassert( request.getBatchType() == BatchedCommandRequest::BatchType_Delete ); for ( size_t i = 0; i < request.sizeWriteOps(); i++ ) { + if ( i + 1 == request.sizeWriteOps() ) + setupSynchronousCommit( writeConcern, _txn ); + WriteErrorDetail* error = NULL; execRemove( BatchItemRef( &request, i ), &error ); @@ -831,6 +841,7 @@ namespace mongo { } void WriteBatchExecutor::execInserts( const BatchedCommandRequest& request, + const WriteConcernOptions& writeConcern, std::vector<WriteErrorDetail*>* errors ) { // Theory of operation: @@ -863,6 +874,9 @@ namespace mongo { state.currIndex < state.request->sizeWriteOps(); ++state.currIndex) { + if (state.currIndex + 1 == state.request->sizeWriteOps()) + setupSynchronousCommit(writeConcern, _txn); + if (elapsedTracker.intervalHasElapsed()) { // Yield between inserts. if (state.hasLock()) { diff --git a/src/mongo/db/commands/write_commands/batch_executor.h b/src/mongo/db/commands/write_commands/batch_executor.h index 3050f66ceca..fa27996c80a 100644 --- a/src/mongo/db/commands/write_commands/batch_executor.h +++ b/src/mongo/db/commands/write_commands/batch_executor.h @@ -86,6 +86,7 @@ namespace mongo { * Dispatches to one of the three functions below for DBLock, CurOp, and stats management. */ void bulkExecute( const BatchedCommandRequest& request, + const WriteConcernOptions& writeConcern, std::vector<BatchedUpsertDetail*>* upsertedIds, std::vector<WriteErrorDetail*>* errors ); @@ -97,6 +98,7 @@ namespace mongo { * times. */ void execInserts( const BatchedCommandRequest& request, + const WriteConcernOptions& writeConcern, std::vector<WriteErrorDetail*>* errors ); /** |