Skip to content

Commit 2b0d78e

Browse files
committed
SERVER-52617: Cache the pointer to the oplog collection before running recoverToOplogTimestamp
1 parent f3699db commit 2b0d78e

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Test replication recovery as standalone with 'recoverToOplogTimestamp' in read-only mode
3+
* (i.e. queryableBackupMode).
4+
*
5+
* @tags: [
6+
* requires_majority_read_concern,
7+
* requires_persistence,
8+
* requires_replication,
9+
* requires_wiredtiger,
10+
* ]
11+
*/
12+
13+
(function() {
14+
"use strict";
15+
16+
const dbName = "test";
17+
const collName = "foo";
18+
19+
const rst = new ReplSetTest({nodes: 1});
20+
rst.startSet();
21+
rst.initiateWithHighElectionTimeout();
22+
const primary = rst.getPrimary();
23+
const primaryDB = primary.getDB(dbName);
24+
25+
const recoveryTimestamp = assert.commandWorked(primaryDB.runCommand({ping: 1})).operationTime;
26+
27+
// Hold back the recovery timestamp before doing another write so we have some oplog entries to
28+
// apply when restart in queryableBackupMode with recoverToOplogTimestamp.
29+
assert.commandWorked(primaryDB.adminCommand({
30+
"configureFailPoint": 'holdStableTimestampAtSpecificTimestamp',
31+
"mode": 'alwaysOn',
32+
"data": {"timestamp": recoveryTimestamp}
33+
}));
34+
35+
const docs = [{_id: 1}];
36+
const operationTime =
37+
assert.commandWorked(primaryDB.runCommand({insert: collName, documents: docs})).operationTime;
38+
39+
rst.stopSet(/*signal=*/null, /*forRestart=*/true);
40+
41+
// Restart as standalone in queryableBackupMode and run replication recovery up to the last insert.
42+
const primaryStandalone = MongoRunner.runMongod({
43+
dbpath: primary.dbpath,
44+
noReplSet: true,
45+
noCleanData: true,
46+
setParameter: {recoverToOplogTimestamp: tojson({timestamp: operationTime})},
47+
queryableBackupMode: ""
48+
});
49+
50+
// Test that the last insert is visible after replication recovery.
51+
assert.eq(primaryStandalone.getDB(dbName)[collName].find().toArray(), docs);
52+
53+
MongoRunner.stopMongod(primaryStandalone);
54+
}());

src/mongo/db/repl/SConscript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ env.Library(
2525
'repl_coordinator_interface',
2626
'$BUILD_DIR/mongo/db/logical_clock',
2727
'$BUILD_DIR/mongo/db/logical_time',
28+
'$BUILD_DIR/mongo/db/mongod_options',
2829
'$BUILD_DIR/mongo/db/storage/flow_control',
2930
],
3031
)

src/mongo/db/repl/local_oplog_info.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#include "mongo/db/logical_clock.h"
3737
#include "mongo/db/logical_time.h"
38+
#include "mongo/db/mongod_options_storage_gen.h"
3839
#include "mongo/db/repl/replication_coordinator.h"
3940
#include "mongo/db/storage/flow_control.h"
4041
#include "mongo/db/storage/record_store.h"
@@ -74,7 +75,8 @@ void LocalOplogInfo::setOplogCollectionName(ServiceContext* service) {
7475
_oplogName = NamespaceString::kRsOplogNamespace;
7576
break;
7677
case ReplicationCoordinator::modeNone:
77-
if (ReplSettings::shouldRecoverFromOplogAsStandalone()) {
78+
if (ReplSettings::shouldRecoverFromOplogAsStandalone() ||
79+
(storageGlobalParams.readOnly && !recoverToOplogTimestamp.empty())) {
7880
_oplogName = NamespaceString::kRsOplogNamespace;
7981
}
8082
// leave empty otherwise.

src/mongo/db/repl/replication_recovery.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@ void ReplicationRecoveryImpl::recoverFromOplogUpTo(OperationContext* opCtx, Time
359359
"Cannot use 'recoverToOplogTimestamp' without a stable checkpoint");
360360
}
361361

362+
// Initialize the cached pointer to the oplog collection.
363+
acquireOplogCollectionForLogging(opCtx);
364+
362365
// This may take an IS lock on the oplog collection.
363366
_truncateOplogIfNeededAndThenClearOplogTruncateAfterPoint(opCtx, recoveryTS);
364367

0 commit comments

Comments
 (0)