diff options
-rw-r--r-- | jstests/auth/lib/commands_lib.js | 16 | ||||
-rw-r--r-- | jstests/libs/storage_engine_utils.js | 12 | ||||
-rw-r--r-- | jstests/noPassthroughWithMongod/query_oplogreplay.js | 23 | ||||
-rw-r--r-- | jstests/replsets/drop_oplog_should_fail_if_storage_engine_supports_replSetResizeOplog_command.js | 44 | ||||
-rw-r--r-- | src/mongo/db/commands/dbcommands.cpp | 21 |
5 files changed, 10 insertions, 106 deletions
diff --git a/jstests/auth/lib/commands_lib.js b/jstests/auth/lib/commands_lib.js index c98964c5bfd..5d91ae32500 100644 --- a/jstests/auth/lib/commands_lib.js +++ b/jstests/auth/lib/commands_lib.js @@ -4230,22 +4230,10 @@ var authCommandsLib = { command: {insert: "oplog.rs", documents: [{ts: Timestamp()}]}, skipSharded: true, setup: function(db) { - load("jstests/libs/storage_engine_utils.js"); - if (!db.getCollectionNames().includes("oplog.rs")) { - assert.commandWorked( - db.runCommand({create: "oplog.rs", capped: true, size: 10000})); - } else { - if (storageEngineIsWiredTigerOrInMemory()) { - assert.commandWorked(db.adminCommand({replSetResizeOplog: 1, size: 10000})); - } else { - assert.commandWorked(db.runCommand({drop: "oplog.rs"})); - assert.commandWorked( - db.runCommand({create: "oplog.rs", capped: true, size: 10000})); - } - } + db.createCollection("oplog.rs", {capped: true, size: 10000}); }, teardown: function(db) { - assert.commandWorked(db.oplog.rs.runCommand('emptycapped')); + db.oplog.rs.drop(); }, testcases: [ { diff --git a/jstests/libs/storage_engine_utils.js b/jstests/libs/storage_engine_utils.js deleted file mode 100644 index 7c6f2d1309e..00000000000 --- a/jstests/libs/storage_engine_utils.js +++ /dev/null @@ -1,12 +0,0 @@ -function storageEngineIsWiredTigerOrInMemory() { - // We assume that WiredTiger is the default storage engine, if the storage engine is - // unspecified in the test options. - return !jsTest.options().storageEngine || jsTest.options().storageEngine === "wiredTiger" || - jsTest.options().storageEngine === "inMemory"; -} - -function storageEngineIsWiredTiger() { - // We assume that WiredTiger is the default storage engine, if the storage engine is - // unspecified in the test options. - return !jsTest.options().storageEngine || jsTest.options().storageEngine === "wiredTiger"; -}
\ No newline at end of file diff --git a/jstests/noPassthroughWithMongod/query_oplogreplay.js b/jstests/noPassthroughWithMongod/query_oplogreplay.js index 9b42f7ea705..c264e211ef6 100644 --- a/jstests/noPassthroughWithMongod/query_oplogreplay.js +++ b/jstests/noPassthroughWithMongod/query_oplogreplay.js @@ -5,28 +5,11 @@ "use strict"; load("jstests/libs/analyze_plan.js"); - load("jstests/libs/storage_engine_utils.js"); function test(t) { - const isOplog = t.getName().startsWith("oplog."); - - if (storageEngineIsWiredTigerOrInMemory() && isOplog) { - // We forbid dropping the oplog when using the WiredTiger or in-memory storage engines - // and so we can't drop the oplog here. Because Evergreen reuses nodes for testing, - // the oplog may already exist on the test node; in this case, trying to create the - // oplog once again would fail. - // To ensure we are working with a clean oplog (an oplog without entries), we resort - // to truncating the oplog instead. - if (!t.getDB().getCollectionNames().includes(t.getName())) { - t.getDB().createCollection(t.getName(), {capped: true, size: 16 * 1024}); - } - t.runCommand('emptycapped'); - t.getDB().adminCommand({replSetResizeOplog: 1, size: 16 * 1024}); - } else { - t.drop(); - assert.commandWorked( - t.getDB().createCollection(t.getName(), {capped: true, size: 16 * 1024})); - } + t.drop(); + assert.commandWorked( + t.getDB().createCollection(t.getName(), {capped: true, size: 16 * 1024})); /** * Helper function for making timestamps with the property that if i < j, then makeTS(i) < diff --git a/jstests/replsets/drop_oplog_should_fail_if_storage_engine_supports_replSetResizeOplog_command.js b/jstests/replsets/drop_oplog_should_fail_if_storage_engine_supports_replSetResizeOplog_command.js deleted file mode 100644 index 4ba1be0dbdc..00000000000 --- a/jstests/replsets/drop_oplog_should_fail_if_storage_engine_supports_replSetResizeOplog_command.js +++ /dev/null @@ -1,44 +0,0 @@ -/* Tests that dropping the oplog is forbidden on standalone nodes with storage engines - * that support the command "replSetResizeOplog". The support for this command is - * provided only by the WiredTiger storage engine. - * Therefore, attempts to drop the oplog when using these storage engines should fail. - * Also, nodes running in a replica set will forbid dropping the oplog, but - * for a different reason. - * Note: We detect whether a storage engine supports the replSetResizeOplog command - * by checking whether it supportsRecoveryTimestamp(). - * - * @tags: [requires_persistence] - */ - -(function() { - "use strict"; - - load("jstests/libs/storage_engine_utils.js"); - - const rt = new ReplSetTest({ - name: "drop_oplog_should_fail_if_storage_engine_supports_replSetResizeOplog_command", - nodes: 1 - }); - - // Start as a standalone node. - rt.start(0, {noReplSet: true}); - - let master = rt.getPrimary(); - let localDB = master.getDB('local'); - - // Standalone nodes don't start with an oplog; create one. The size of the oplog doesn't - // matter. We are capping the oplog because some storage engines do not allow the creation - // of uncapped oplog collections. - assert.commandWorked(localDB.runCommand({create: 'oplog.rs', capped: true, size: 1000})); - - if (storageEngineIsWiredTiger()) { - const ret = assert.commandFailed(localDB.runCommand({drop: 'oplog.rs'})); - assert.eq("can't drop oplog on storage engines that support replSetResizeOplog command", - ret.errmsg); - } else { - assert.commandWorked(localDB.runCommand({drop: 'oplog.rs'})); - } - - rt.stopSet(); - -}());
\ No newline at end of file diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp index 5f9628912c6..615f4fbe3c5 100644 --- a/src/mongo/db/commands/dbcommands.cpp +++ b/src/mongo/db/commands/dbcommands.cpp @@ -305,22 +305,11 @@ public: return false; } - if (nsToDrop.isOplog()) { - if (repl::ReplicationCoordinator::get(opCtx)->isReplEnabled()) { - errmsg = "can't drop live oplog while replicating"; - return false; - } - - auto storageEngine = opCtx->getServiceContext()->getStorageEngine(); - invariant(storageEngine); - if (storageEngine->supportsRecoveryTimestamp()) { - // We use the method supportsRecoveryTimestamp() to detect whether we are using - // the WiredTiger storage engine, which is currently only storage engine that - // supports the replSetResizeOplog command. - errmsg = - "can't drop oplog on storage engines that support replSetResizeOplog command"; - return false; - } + if ((repl::ReplicationCoordinator::get(opCtx)->getReplicationMode() != + repl::ReplicationCoordinator::modeNone) && + nsToDrop.isOplog()) { + errmsg = "can't drop live oplog while replicating"; + return false; } uassertStatusOK( |