summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/write_commands
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2015-04-29 20:28:39 -0400
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2015-04-29 20:28:39 -0400
commit66a48710fcdfa9783d44f1b467a7bceb6df7dcd2 (patch)
tree3c3e13cc68fa4fb493208a9ad1186cb057ca87e3 /src/mongo/db/commands/write_commands
parent5c4824de27af185aa584aee61d4c4cf5e9b79ff5 (diff)
downloadmongo-66a48710fcdfa9783d44f1b467a7bceb6df7dcd2.tar.gz
Revert "SERVER-5218 Batch oplog writes always wait for journal."
This reverts commit 27a8cb772d9e876fc7549a2c6ce3c1a62a4a394f.
Diffstat (limited to 'src/mongo/db/commands/write_commands')
-rw-r--r--src/mongo/db/commands/write_commands/batch_executor.cpp34
-rw-r--r--src/mongo/db/commands/write_commands/batch_executor.h2
2 files changed, 35 insertions, 1 deletions
diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp
index 1c12d272270..ae57fdbecbb 100644
--- a/src/mongo/db/commands/write_commands/batch_executor.cpp
+++ b/src/mongo/db/commands/write_commands/batch_executor.cpp
@@ -735,13 +735,32 @@ namespace mongo {
std::vector<BatchedUpsertDetail*>* upsertedIds,
std::vector<WriteErrorDetail*>* errors ) {
+ WriteConcernOptions originalWC = _txn->getWriteConcern();
+
+ // We adjust the write concern attached to the OperationContext to not wait for
+ // journal. Later, the code will restore the write concern to wait for journal on
+ // the last write of the batch.
+ if (request.sizeWriteOps() > 1
+ && originalWC.syncMode == WriteConcernOptions::JOURNAL)
+ {
+ WriteConcernOptions writeConcern = originalWC;
+ writeConcern.syncMode = WriteConcernOptions::NONE;
+ _txn->setWriteConcern(writeConcern);
+ }
+
if ( request.getBatchType() == BatchedCommandRequest::BatchType_Insert ) {
- execInserts( request, errors );
+ execInserts( request, originalWC, errors );
}
else if ( request.getBatchType() == BatchedCommandRequest::BatchType_Update ) {
for ( size_t i = 0; i < request.sizeWriteOps(); i++ ) {
if ( i + 1 == request.sizeWriteOps() ) {
+ // For the last write in the batch, restore the write concern back to the
+ // original provided one; this may set WriteConcernOptions::JOURNAL back
+ // to true.
+ _txn->setWriteConcern(originalWC);
+ // Use the original write concern to possibly await the commit of this write,
+ // in order to flush the journal as requested.
setupSynchronousCommit( _txn );
}
@@ -768,6 +787,12 @@ namespace mongo {
for ( size_t i = 0; i < request.sizeWriteOps(); i++ ) {
if ( i + 1 == request.sizeWriteOps() ) {
+ // For the last write in the batch, restore the write concern back to the
+ // original provided one; this may set WriteConcernOptions::JOURNAL back
+ // to true.
+ _txn->setWriteConcern(originalWC);
+ // Use the original write concern to possibly await the commit of this write,
+ // in order to flush the journal as requested.
setupSynchronousCommit( _txn );
}
@@ -812,6 +837,7 @@ namespace mongo {
}
void WriteBatchExecutor::execInserts( const BatchedCommandRequest& request,
+ const WriteConcernOptions& originalWC,
std::vector<WriteErrorDetail*>* errors ) {
// Theory of operation:
@@ -856,6 +882,12 @@ namespace mongo {
++state.currIndex) {
if (state.currIndex + 1 == state.request->sizeWriteOps()) {
+ // For the last write in the batch, restore the write concern back to the
+ // original provided one; this may set WriteConcernOptions::JOURNAL back
+ // to true.
+ _txn->setWriteConcern(originalWC);
+ // Use the original write concern to possibly await the commit of this write,
+ // in order to flush the journal as requested.
setupSynchronousCommit(_txn);
}
diff --git a/src/mongo/db/commands/write_commands/batch_executor.h b/src/mongo/db/commands/write_commands/batch_executor.h
index 6216ae65c89..e5d55a5b9fb 100644
--- a/src/mongo/db/commands/write_commands/batch_executor.h
+++ b/src/mongo/db/commands/write_commands/batch_executor.h
@@ -33,6 +33,7 @@
#include "mongo/base/disallow_copying.h"
#include "mongo/db/ops/update_request.h"
+#include "mongo/db/write_concern_options.h"
#include "mongo/s/write_ops/batched_command_request.h"
#include "mongo/s/write_ops/batched_command_response.h"
#include "mongo/s/write_ops/batched_delete_document.h"
@@ -94,6 +95,7 @@ namespace mongo {
* times.
*/
void execInserts( const BatchedCommandRequest& request,
+ const WriteConcernOptions& originalWC,
std::vector<WriteErrorDetail*>* errors );
/**