summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2020-12-17 19:55:15 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-01-09 04:46:24 +0000
commit8495ff679afa2c3a13d3456e3f3f1742d8431c85 (patch)
tree1c2b7a1272171c86b1662de586336813e03fa9c6
parentb01d1f1c14f1270e36adf06c78b6de9f63308936 (diff)
downloadmongo-8495ff679afa2c3a13d3456e3f3f1742d8431c85.tar.gz
SERVER-52950 recoverFromOplogAsStandalone mode must not start oplog truncater thread
(cherry picked from commit 3417215850d7a577452552499ea55d1872199d74)
-rw-r--r--jstests/noPassthrough/check_for_oplog_cap_maintainer_thread.js58
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_record_store_mongod.cpp12
2 files changed, 68 insertions, 2 deletions
diff --git a/jstests/noPassthrough/check_for_oplog_cap_maintainer_thread.js b/jstests/noPassthrough/check_for_oplog_cap_maintainer_thread.js
new file mode 100644
index 00000000000..abcfdd574f3
--- /dev/null
+++ b/jstests/noPassthrough/check_for_oplog_cap_maintainer_thread.js
@@ -0,0 +1,58 @@
+/**
+ * Checks that the oplog cap maintainer thread is started and the oplog stones calculation is
+ * performed under normal startup circumstances. Both of these operations should not be done when
+ * starting up with any of the following modes:
+ * - readonly
+ * - repair
+ * - recoverFromOplogAsStandalone
+ *
+ * @tags: [requires_replication, requires_persistence]
+ */
+(function() {
+ "use strict";
+
+ // Verify that the oplog cap maintainer thread is running under normal circumstances.
+ jsTestLog("Testing single node replica set mode");
+ const rst = new ReplSetTest({nodes: 1, nodeOptions: {setParameter: {logLevel: 1}}});
+ rst.startSet();
+ rst.initiate();
+
+ const primary = rst.getPrimary();
+
+ checkLog.contains(primary, "OplogTruncaterThread started");
+ checkLog.contains(primary, "WiredTiger record store oplog processing took");
+
+ rst.stopSet(/*signal=*/null, /*forRestart=*/true);
+
+ // A subset of startup options prevent the oplog cap maintainer thread from being started. These
+ // startup options are currently limited to readOnly, recoverFromOplogAsStandalone and repair.
+ function verifyOplogCapMaintainerThreadNotStarted(log) {
+ const threadRegex = new RegExp("OplogTruncaterThread started");
+ const oplogStonesRegex = new RegExp("WiredTiger record store oplog processing took");
+
+ assert(!threadRegex.test(log));
+ assert(!oplogStonesRegex.test(log));
+ }
+
+ jsTestLog("Testing recoverFromOplogAsStandalone mode");
+ clearRawMongoProgramOutput();
+ let conn = MongoRunner.runMongod({
+ dbpath: primary.dbpath,
+ noCleanData: true,
+ setParameter: {recoverFromOplogAsStandalone: true, logLevel: 1},
+ });
+ assert(conn);
+ MongoRunner.stopMongod(conn);
+ verifyOplogCapMaintainerThreadNotStarted(rawMongoProgramOutput());
+
+ jsTestLog("Testing repair mode");
+ clearRawMongoProgramOutput();
+ conn = MongoRunner.runMongod({
+ dbpath: primary.dbpath,
+ noCleanData: true,
+ repair: "",
+ setParameter: {logLevel: 1},
+ });
+ assert(!conn);
+ verifyOplogCapMaintainerThreadNotStarted(rawMongoProgramOutput());
+}());
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_mongod.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_mongod.cpp
index fdc45e0c54f..81696dba8f4 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_mongod.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_mongod.cpp
@@ -129,6 +129,7 @@ public:
virtual void run() {
Client::initThread(_name.c_str());
+ LOG(1) << "OplogTruncaterThread started";
ON_BLOCK_EXIT([] { Client::destroy(); });
while (!globalInShutdownDeprecated()) {
@@ -148,9 +149,16 @@ bool initRsOplogBackgroundThread(StringData ns) {
return false;
}
- if (storageGlobalParams.repair || storageGlobalParams.readOnly) {
+ // When starting up with recoverFromOplogAsStandalone=true, the readOnly flag is initially set
+ // to false to allow oplog recovery to run and perform its necessary writes. After recovery is
+ // complete, the readOnly flag gets flipped to true. Because of this subtlety, we avoid
+ // calculating the oplog stones when recoverFromOplogAsStandalone=true as the RecordStore
+ // construction for the oplog happens before the readOnly flag gets flipped to true.
+ if (storageGlobalParams.repair || storageGlobalParams.readOnly ||
+ repl::ReplSettings::shouldRecoverFromOplogAsStandalone()) {
LOG(1) << "not starting OplogTruncaterThread for " << ns
- << " because we are either in repair or read-only mode";
+ << " because we are either in repair mode, read-only mode or recovering from the"
+ << " oplog in standalone mode";
return false;
}