diff options
author | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2018-10-05 21:59:19 -0400 |
---|---|---|
committer | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2018-10-08 17:42:02 -0400 |
commit | d753adf541a85c152fa0db90432accfce3d49676 (patch) | |
tree | b76d6a6cb95a1efdf94a44445d7579c49bfae3e3 /src/mongo/db | |
parent | 2718702ac721b29a065fa1e2f4949737c1c374ae (diff) | |
download | mongo-d753adf541a85c152fa0db90432accfce3d49676.tar.gz |
SERVER-37505 Run applyOps with prepare: true in its own batch in MultiApplier.
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/repl/apply_ops.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog_applier.cpp | 3 |
2 files changed, 9 insertions, 3 deletions
diff --git a/src/mongo/db/repl/apply_ops.cpp b/src/mongo/db/repl/apply_ops.cpp index 3530c71aca7..5d349d92303 100644 --- a/src/mongo/db/repl/apply_ops.cpp +++ b/src/mongo/db/repl/apply_ops.cpp @@ -276,10 +276,15 @@ Status _applyPrepareTransaction(OperationContext* opCtx, int* numApplied, BSONArrayBuilder* opsBuilder, const OpTime& optime) { - // Only run on secondary. + // Return error if run via applyOps command. uassert(50945, "applyOps with prepared flag is only used internally by secondaries.", - oplogApplicationMode == repl::OplogApplication::Mode::kSecondary); + oplogApplicationMode != repl::OplogApplication::Mode::kApplyOpsCmd); + + // TODO: SERVER-35879 Only run on secondary until we support replication recovery and initial + // sync. + invariant(oplogApplicationMode == repl::OplogApplication::Mode::kSecondary); + uassert( 50946, "applyOps with prepared must only include CRUD operations and cannot have precondition.", diff --git a/src/mongo/db/repl/oplog_applier.cpp b/src/mongo/db/repl/oplog_applier.cpp index e7c5160f902..3b86518fd7c 100644 --- a/src/mongo/db/repl/oplog_applier.cpp +++ b/src/mongo/db/repl/oplog_applier.cpp @@ -179,7 +179,8 @@ StatusWith<OplogApplier::Operations> OplogApplier::getNextApplierBatch( // Commands must be processed one at a time. The only exception to this is applyOps because // applyOps oplog entries are effectively containers for CRUD operations. Therefore, it is // safe to batch applyOps commands with CRUD operations when reading from the oplog buffer. - if (entry.isCommand() && entry.getCommandType() != OplogEntry::CommandType::kApplyOps) { + if (entry.isCommand() && (entry.getCommandType() != OplogEntry::CommandType::kApplyOps || + entry.shouldPrepare())) { if (ops.empty()) { // Apply commands one-at-a-time. ops.push_back(std::move(entry)); |