Skip to content

Commit 97d1373

Browse files
committed
SERVER-41178: TransactionHistoryIterator should do untimestamped reads during rollback recovery
1 parent 60008cd commit 97d1373

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/mongo/db/repl/transaction_oplog_application.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ Status _applyTransactionFromOplogChain(OperationContext* opCtx,
9393
// Traverse the oplog chain with its own snapshot and read timestamp.
9494
ReadSourceScope readSourceScope(opCtx);
9595

96+
// If we are recovering, the lastApplied timestamp could be ahead of the common point in the
97+
// case of rollback recovery because we do not update the lastAppliedOpTime until after we
98+
// are done recovering the oplog. TransactionHistoryIterator by default does timestamped
99+
// reads on the oplog using lastApplied. So this could race with the config.transactions
100+
// table update (run by a different replication writer thread) whose commitTimestamp is less
101+
// than the common point and thus less than the read timestamp of the
102+
// TransactionHistoryIterator. We require that the commit timestamp of non-prepared storage
103+
// transactions (which is the case for config.transactions update) is newer than the latest
104+
// active read timestamp. So, we make TransactionHistoryIterator read untimestamped to avoid
105+
// violating this rule. This is safe because there is no concurrent write to the oplog and
106+
// all oplog entries we need on the transaction oplog chain should also be visible under
107+
// untimestamped reads.
108+
if (mode == repl::OplogApplication::Mode::kRecovering) {
109+
opCtx->recoveryUnit()->setTimestampReadSource(RecoveryUnit::ReadSource::kNoTimestamp);
110+
}
111+
96112
// Get the corresponding prepare applyOps oplog entry.
97113
const auto prepareOpTime = entry.getPrevWriteOpTimeInTransaction();
98114
invariant(prepareOpTime);

0 commit comments

Comments
 (0)