summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavi Vetriselvan <pavithra.vetriselvan@mongodb.com>2021-08-17 11:18:35 -0400
committerPavi Vetriselvan <pavithra.vetriselvan@mongodb.com>2021-08-20 14:41:29 -0400
commit0540ed3053add3e352dc81c6fb7f6dd3a11afc31 (patch)
treee8c3b3fe855ccb003b7403fc3a61fd9efcb6c9a7
parent2e8cc64d061a0cd8ed0f98db92dd9232521f94ca (diff)
downloadmongo-0540ed3053add3e352dc81c6fb7f6dd3a11afc31.tar.gz
SERVER-58184 Move getOldestActiveTimestamp after prepare reconstruction
(cherry picked from commit 841cff317bf34a320f9b8be24cdf27faf4393cbb)
-rw-r--r--src/mongo/db/mongod_main.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/mongo/db/mongod_main.cpp b/src/mongo/db/mongod_main.cpp
index da733aa10ae..b2c6a2a9f4b 100644
--- a/src/mongo/db/mongod_main.cpp
+++ b/src/mongo/db/mongod_main.cpp
@@ -658,10 +658,6 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
auto replCoord = repl::ReplicationCoordinator::get(startupOpCtx.get());
invariant(replCoord);
- if (replCoord->isReplEnabled()) {
- storageEngine->setOldestActiveTransactionTimestampCallback(
- TransactionParticipant::getOldestActiveTimestamp);
- }
if (serverGlobalParams.clusterRole == ClusterRole::ShardServer) {
// Note: For replica sets, ShardingStateRecovery happens on transition to primary.
@@ -694,6 +690,17 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) {
}
replCoord->startup(startupOpCtx.get(), lastShutdownState);
+ // 'getOldestActiveTimestamp', which is called in the background by the checkpoint thread,
+ // requires a read on 'config.transactions' at the stableTimestamp. If this read occurs
+ // while applying prepared transactions at the end of replication recovery, it's possible to
+ // prepare a transaction at timestamp earlier than the stableTimestamp. This will result in
+ // a WiredTiger invariant. Register the callback after the call to 'startup' to ensure we've
+ // finished applying prepared transactions.
+ if (replCoord->isReplEnabled()) {
+ storageEngine->setOldestActiveTransactionTimestampCallback(
+ TransactionParticipant::getOldestActiveTimestamp);
+ }
+
if (getReplSetMemberInStandaloneMode(serviceContext)) {
LOGV2_WARNING_OPTIONS(
20547,