summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2015-03-06 09:16:49 -0500
committerRamon Fernandez <ramon.fernandez@mongodb.com>2015-03-09 11:06:13 -0400
commit7acc227640803a2ae3f391205bb448551db60837 (patch)
tree61eab804be3b3f495c6234ad94f7dc3ce2e03baf
parent0cbcdfd5b4cd4961b448f1a35fd0d4ea19629b93 (diff)
downloadmongo-7acc227640803a2ae3f391205bb448551db60837.tar.gz
SERVER-17489: in bulk ops, only mark last operation with commit=synchronous
(cherry picked from commit af56dea51db8d96773ed541927522ee18ff96f31)
-rw-r--r--src/mongo/db/commands/write_commands/batch_executor.cpp28
-rw-r--r--src/mongo/db/commands/write_commands/batch_executor.h2
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 d42d4e1a826..d4481b2940c 100644
--- a/src/mongo/db/commands/write_commands/batch_executor.cpp
+++ b/src/mongo/db/commands/write_commands/batch_executor.cpp
@@ -228,11 +228,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" ),
@@ -269,7 +264,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)
@@ -759,16 +754,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 );
@@ -791,6 +798,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 );
@@ -832,6 +842,7 @@ namespace mongo {
}
void WriteBatchExecutor::execInserts( const BatchedCommandRequest& request,
+ const WriteConcernOptions& writeConcern,
std::vector<WriteErrorDetail*>* errors ) {
// Theory of operation:
@@ -864,6 +875,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 );
/**