diff options
author | Benety Goh <benety@mongodb.com> | 2023-01-14 06:52:19 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-01-14 12:33:35 +0000 |
commit | 2597c37f5bfa29f1ddc9b33d7212c7beecc5afb2 (patch) | |
tree | 4ef57bc4d7bbdbb42a99b104a33f4a87c3169a0c /src/mongo/db/op_observer/op_observer_impl.cpp | |
parent | 8e4e9c216274b2e66c1395011ce015ce25a58c14 (diff) | |
download | mongo-2597c37f5bfa29f1ddc9b33d7212c7beecc5afb2.tar.gz |
SERVER-70903 keep prevOpTime field for large batched writes (multiple oplog entries)
Diffstat (limited to 'src/mongo/db/op_observer/op_observer_impl.cpp')
-rw-r--r-- | src/mongo/db/op_observer/op_observer_impl.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/mongo/db/op_observer/op_observer_impl.cpp b/src/mongo/db/op_observer/op_observer_impl.cpp index 6503e3f7b34..73d0ecc0b85 100644 --- a/src/mongo/db/op_observer/op_observer_impl.cpp +++ b/src/mongo/db/op_observer/op_observer_impl.cpp @@ -1902,12 +1902,17 @@ void OpObserverImpl::onBatchedWriteCommit(OperationContext* opCtx) { bool firstOp, bool lastOp, std::vector<StmtId> stmtIdsWritten) { - // 'prevOpTime' is not allowed during oplog application because this field - // is not part of the the legacy atomic applyOps oplog entry format that - // we use to replicate batched writes. + // Remove 'prevOpTime' when replicating as a single applyOps oplog entry. + // This preserves backwards compatibility with the legacy atomic applyOps oplog + // entry format that we use to replicate batched writes. // OplogApplierImpl::_deriveOpsAndFillWriterVectors() enforces this restriction // using an invariant added in SERVER-43651. - oplogEntry->setPrevWriteOpTimeInTransaction(boost::none); + // For batched writes that replicate over a chain of applyOps oplog entries, we include + // 'prevOpTime' so that oplog application is able to consume all the linked operations, + // similar to large multi-document transactions. See SERVER-70572. + if (firstOp && lastOp) { + oplogEntry->setPrevWriteOpTimeInTransaction(boost::none); + } return logApplyOps(opCtx, oplogEntry, /*txnState=*/DurableTxnStateEnum::kCommitted, // unused |