diff options
-rw-r--r-- | src/mongo/db/mongod_options.cpp | 23 | ||||
-rw-r--r-- | src/mongo/db/storage/storage_options.h | 3 | ||||
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp | 5 |
3 files changed, 28 insertions, 3 deletions
diff --git a/src/mongo/db/mongod_options.cpp b/src/mongo/db/mongod_options.cpp index 2312596120a..3c5deb111be 100644 --- a/src/mongo/db/mongod_options.cpp +++ b/src/mongo/db/mongod_options.cpp @@ -470,12 +470,29 @@ Status storeMongodOptions(const moe::Environment& params) { } repl::ReplSettings replSettings; - if (params.count("replication.replSetName")) { - replSettings.setReplSetString(params["replication.replSetName"].as<std::string>().c_str()); - } if (params.count("replication.replSet")) { /* seed list of hosts for the repl set */ replSettings.setReplSetString(params["replication.replSet"].as<std::string>().c_str()); + } else if (params.count("replication.replSetName")) { + // "replSetName" is previously removed if "replSet" and "replSetName" are both found to be + // set by the user. Therefore, we only need to check for it if "replSet" in not found. + replSettings.setReplSetString(params["replication.replSetName"].as<std::string>().c_str()); + } else { + // If neither "replication.replSet" nor "replication.replSetName" is set, then we are in + // standalone mode. + // + // A standalone node does not use the oplog collection, so special truncation handling for + // the capped collection is unnecessary. + // + // A standalone node that will be reintroduced to its replica set must not allow oplog + // truncation while in standalone mode because oplog history needed for startup recovery as + // a replica set member could be deleted. Replication can need history older than the last + // checkpoint to support transactions. + // + // Note: we only use this to defer oplog collection truncation via OplogStones in WT. Non-WT + // storage engines will continue to perform regular capped collection handling for the oplog + // collection, regardless of this parameter setting. + storageGlobalParams.allowOplogTruncation = false; } if (params.count("replication.enableMajorityReadConcern")) { diff --git a/src/mongo/db/storage/storage_options.h b/src/mongo/db/storage/storage_options.h index 733808ce3c1..ceec92d42fb 100644 --- a/src/mongo/db/storage/storage_options.h +++ b/src/mongo/db/storage/storage_options.h @@ -109,6 +109,9 @@ struct StorageGlobalParams { // an existing underlying MongoDB database level resource if possible. This can improve // workloads that rely heavily on creating many collections within a database. bool groupCollections; + + // Controls whether we allow the OplogStones mechanism to delete oplog history on WT. + bool allowOplogTruncation = true; }; extern StorageGlobalParams storageGlobalParams; diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp index b978edec751..d9d07d00cd1 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp @@ -1854,6 +1854,11 @@ boost::optional<Timestamp> WiredTigerKVEngine::getOplogNeededForCrashRecovery() Timestamp WiredTigerKVEngine::getPinnedOplog() const { stdx::lock_guard<stdx::mutex> lock(_oplogPinnedByBackupMutex); + if (!storageGlobalParams.allowOplogTruncation) { + // If oplog truncation is not allowed, then return the min timestamp so that no history is + // ever allowed to be deleted. + return Timestamp::min(); + } if (_oplogPinnedByBackup) { // All the oplog since `_oplogPinnedByBackup` should remain intact during the backup. return _oplogPinnedByBackup.get(); |