0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-24 16:46:00 +01:00
mongodb/jstests/replsets/standalone_recover_to_oplog_timestamp.js
Moustafa Maher 2fd5f78d5a SERVER-95421 make initiateWithHighElectionTimeout the default in ReplSetTest (#28174)
GitOrigin-RevId: df168ee363c3f0e86526270437d3688ac4bb326d
2024-10-22 02:53:25 +00:00

53 lines
1.7 KiB
JavaScript

/**
* Test replication recovery as standalone with 'recoverToOplogTimestamp' in read-only mode
* (i.e. queryableBackupMode).
*
* @tags: [
* requires_majority_read_concern,
* requires_persistence,
* requires_replication,
* ]
*/
import {ReplSetTest} from "jstests/libs/replsettest.js";
const dbName = "test";
const collName = jsTestName();
const rst = new ReplSetTest({nodes: 1});
rst.startSet();
rst.initiate();
const primary = rst.getPrimary();
const primaryDB = primary.getDB(dbName);
const recoveryTimestamp = assert.commandWorked(primaryDB.runCommand({ping: 1})).operationTime;
// Hold back the recovery timestamp before doing another write so we have some oplog entries to
// apply when restart in queryableBackupMode with recoverToOplogTimestamp.
assert.commandWorked(primaryDB.adminCommand({
"configureFailPoint": 'holdStableTimestampAtSpecificTimestamp',
"mode": 'alwaysOn',
"data": {"timestamp": recoveryTimestamp}
}));
assert.commandWorked(primaryDB.getCollection(collName).createIndex({a: 1}));
const docs = [{_id: 1, a: 1}];
const operationTime =
assert.commandWorked(primaryDB.runCommand({insert: collName, documents: docs})).operationTime;
rst.stopSet(/*signal=*/ null, /*forRestart=*/ true);
// Restart as standalone in queryableBackupMode and run replication recovery up to the last insert.
const primaryStandalone = MongoRunner.runMongod({
dbpath: primary.dbpath,
noReplSet: true,
noCleanData: true,
setParameter: {recoverToOplogTimestamp: tojson({timestamp: operationTime})},
queryableBackupMode: ""
});
// Test that the last insert is visible after replication recovery.
assert.eq(primaryStandalone.getDB(dbName)[collName].find().toArray(), docs);
MongoRunner.stopMongod(primaryStandalone);