summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLingzhi Deng <lingzhi.deng@mongodb.com>2020-11-04 00:37:53 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-11-06 03:20:31 +0000
commita53936d6b01f26babe3ac2be79be68e8334590b2 (patch)
treef0713c5a6988dbb815bded0c04422c7bdbcf2aac
parent50b49e377caf436b698f915186ad39122232f40e (diff)
downloadmongo-a53936d6b01f26babe3ac2be79be68e8334590b2.tar.gz
SERVER-52624: Cache the pointer to the oplog collection before running recoverToOplogTimestamp
-rw-r--r--jstests/replsets/standalone_recover_to_oplog_timestamp.js54
-rw-r--r--src/mongo/db/repl/local_oplog_info.cpp12
-rw-r--r--src/mongo/db/repl/replication_recovery.cpp3
3 files changed, 58 insertions, 11 deletions
diff --git a/jstests/replsets/standalone_recover_to_oplog_timestamp.js b/jstests/replsets/standalone_recover_to_oplog_timestamp.js
new file mode 100644
index 00000000000..b675eb72add
--- /dev/null
+++ b/jstests/replsets/standalone_recover_to_oplog_timestamp.js
@@ -0,0 +1,54 @@
+/**
+ * Test replication recovery as standalone with 'recoverToOplogTimestamp' in read-only mode
+ * (i.e. queryableBackupMode).
+ *
+ * @tags: [
+ * requires_majority_read_concern,
+ * requires_persistence,
+ * requires_replication,
+ * requires_wiredtiger,
+ * ]
+ */
+
+(function() {
+"use strict";
+
+const dbName = "test";
+const collName = "foo";
+
+const rst = new ReplSetTest({nodes: 1});
+rst.startSet();
+rst.initiateWithHighElectionTimeout();
+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}
+}));
+
+const docs = [{_id: 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);
+}());
diff --git a/src/mongo/db/repl/local_oplog_info.cpp b/src/mongo/db/repl/local_oplog_info.cpp
index eb7de479b6d..881f974aaea 100644
--- a/src/mongo/db/repl/local_oplog_info.cpp
+++ b/src/mongo/db/repl/local_oplog_info.cpp
@@ -68,17 +68,7 @@ const NamespaceString& LocalOplogInfo::getOplogCollectionName() const {
}
void LocalOplogInfo::setOplogCollectionName(ServiceContext* service) {
- switch (ReplicationCoordinator::get(service)->getReplicationMode()) {
- case ReplicationCoordinator::modeReplSet:
- _oplogName = NamespaceString::kRsOplogNamespace;
- break;
- case ReplicationCoordinator::modeNone:
- if (ReplSettings::shouldRecoverFromOplogAsStandalone()) {
- _oplogName = NamespaceString::kRsOplogNamespace;
- }
- // leave empty otherwise.
- break;
- }
+ _oplogName = NamespaceString::kRsOplogNamespace;
}
const CollectionPtr& LocalOplogInfo::getCollection() const {
diff --git a/src/mongo/db/repl/replication_recovery.cpp b/src/mongo/db/repl/replication_recovery.cpp
index ecaf6fb104e..5673e10251a 100644
--- a/src/mongo/db/repl/replication_recovery.cpp
+++ b/src/mongo/db/repl/replication_recovery.cpp
@@ -357,6 +357,9 @@ void ReplicationRecoveryImpl::recoverFromOplogUpTo(OperationContext* opCtx, Time
"Cannot use 'recoverToOplogTimestamp' without a stable checkpoint");
}
+ // Initialize the cached pointer to the oplog collection.
+ acquireOplogCollectionForLogging(opCtx);
+
// This may take an IS lock on the oplog collection.
_truncateOplogIfNeededAndThenClearOplogTruncateAfterPoint(opCtx, recoveryTS);