diff options
author | Maria van Keulen <maria.vankeulen@mongodb.com> | 2020-02-19 20:03:40 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2020-02-19 20:03:40 +0000 |
commit | 8dd337953bdf7b918da37fb7f32b3200e9c0c12b (patch) | |
tree | 8bd5bf18fb8622d774fe152450a68d7dafed366a /src/mongo/db/repl | |
parent | a56d4030fc278b40a320e45422f7ee8e4eaecc34 (diff) | |
download | mongo-8dd337953bdf7b918da37fb7f32b3200e9c0c12b.tar.gz |
SERVER-45405 Allow implicit collection creation inside multi-doc txns
Diffstat (limited to 'src/mongo/db/repl')
-rw-r--r-- | src/mongo/db/repl/oplog.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/repl/rollback_impl.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/repl/transaction_oplog_application.cpp | 6 |
3 files changed, 10 insertions, 9 deletions
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index 14d57c18b74..8150dfbeb70 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -1427,11 +1427,8 @@ Status applyCommand_inlock(OperationContext* opCtx, switch (replMode) { case ReplicationCoordinator::modeReplSet: { - // The 'applyOps' command never logs 'applyOps' oplog entries with nested - // command operations, so this code will never be run from inside the 'applyOps' - // command on secondaries. Thus, the timestamps in the command oplog - // entries are always real timestamps from this oplog and we should - // timestamp our writes with them. + // The timestamps in the command oplog entries are always real timestamps from this + // oplog and we should timestamp our writes with them. return true; } case ReplicationCoordinator::modeNone: { diff --git a/src/mongo/db/repl/rollback_impl.cpp b/src/mongo/db/repl/rollback_impl.cpp index aa5d60beb85..26c9c1a0fd4 100644 --- a/src/mongo/db/repl/rollback_impl.cpp +++ b/src/mongo/db/repl/rollback_impl.cpp @@ -946,9 +946,11 @@ Status RollbackImpl::_processRollbackOpForApplyOps(OperationContext* opCtx, invariant(oplogEntry.getCommandType() == OplogEntry::CommandType::kApplyOps); try { + // Roll back operations in reverse order in order to account for non-commutative + // members of applyOps (e.g., commands inside of multi-document transactions). auto subOps = ApplyOps::extractOperations(oplogEntry); - for (auto& subOp : subOps) { - auto subStatus = _processRollbackOp(opCtx, subOp); + for (auto reverseIt = subOps.rbegin(); reverseIt != subOps.rend(); ++reverseIt) { + auto subStatus = _processRollbackOp(opCtx, *reverseIt); if (!subStatus.isOK()) { return subStatus; } diff --git a/src/mongo/db/repl/transaction_oplog_application.cpp b/src/mongo/db/repl/transaction_oplog_application.cpp index 3d2f77905dc..99185e45c14 100644 --- a/src/mongo/db/repl/transaction_oplog_application.cpp +++ b/src/mongo/db/repl/transaction_oplog_application.cpp @@ -65,9 +65,11 @@ Status _applyOperationsForTransaction(OperationContext* opCtx, // Apply each the operations via repl::applyOperation. for (const auto& op : ops) { try { - Status status = Status::OK(); + // Presently, it is not allowed to run a prepared transaction with a command + // inside. TODO(SERVER-46105) + invariant(!op.isCommand()); AutoGetCollection coll(opCtx, op.getNss(), MODE_IX); - status = repl::applyOperation_inlock( + auto status = repl::applyOperation_inlock( opCtx, coll.getDb(), &op, false /*alwaysUpsert*/, oplogApplicationMode); if (!status.isOK()) { return status; |