summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuganthi Mani <suganthi.mani@mongodb.com>2019-07-08 10:31:49 -0400
committerSuganthi Mani <suganthi.mani@mongodb.com>2019-08-30 14:53:42 -0400
commit58e4edb8237288f45f55cd8a59ea96a955489353 (patch)
tree2fc6137a218cb489a10926ea25097566dbe5c57d
parent12c21c952a48fe83af11c19beb9761635ec0e699 (diff)
downloadmongo-58e4edb8237288f45f55cd8a59ea96a955489353.tar.gz
SERVER-38356 added functionality to forbid dropping the oplog, modified tests to get around Evergreen issue
(cherry picked from commit a3244d8ac0ae530e2394248e72aadb27241adba3)
-rw-r--r--jstests/auth/lib/commands_lib.js9
-rw-r--r--jstests/libs/storage_engine_utils.js6
-rw-r--r--jstests/noPassthroughWithMongod/query_oplogreplay.js23
-rw-r--r--jstests/replsets/drop_oplog_should_fail_if_storage_engine_supports_replSetResizeOplog_command.js39
-rw-r--r--src/mongo/db/commands/dbcommands.cpp21
5 files changed, 88 insertions, 10 deletions
diff --git a/jstests/auth/lib/commands_lib.js b/jstests/auth/lib/commands_lib.js
index 053ad4e9f49..0cd3cae0330 100644
--- a/jstests/auth/lib/commands_lib.js
+++ b/jstests/auth/lib/commands_lib.js
@@ -4230,10 +4230,15 @@ var authCommandsLib = {
command: {insert: "oplog.rs", documents: [{ts: Timestamp()}]},
skipSharded: true,
setup: function(db) {
- db.createCollection("oplog.rs", {capped: true, size: 10000});
+ if (!db.getCollectionNames().includes("oplog.rs")) {
+ assert.commandWorked(
+ db.runCommand({create: "oplog.rs", capped: true, size: 10000}));
+ } else {
+ assert.commandWorked(db.adminCommand({replSetResizeOplog: 1, size: 10000}));
+ }
},
teardown: function(db) {
- db.oplog.rs.drop();
+ assert.commandWorked(db.oplog.rs.runCommand('emptycapped'));
},
testcases: [
{
diff --git a/jstests/libs/storage_engine_utils.js b/jstests/libs/storage_engine_utils.js
new file mode 100644
index 00000000000..2d3bb719f11
--- /dev/null
+++ b/jstests/libs/storage_engine_utils.js
@@ -0,0 +1,6 @@
+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";
+} \ No newline at end of file
diff --git a/jstests/noPassthroughWithMongod/query_oplogreplay.js b/jstests/noPassthroughWithMongod/query_oplogreplay.js
index c264e211ef6..9b42f7ea705 100644
--- a/jstests/noPassthroughWithMongod/query_oplogreplay.js
+++ b/jstests/noPassthroughWithMongod/query_oplogreplay.js
@@ -5,11 +5,28 @@
"use strict";
load("jstests/libs/analyze_plan.js");
+ load("jstests/libs/storage_engine_utils.js");
function test(t) {
- t.drop();
- assert.commandWorked(
- t.getDB().createCollection(t.getName(), {capped: true, size: 16 * 1024}));
+ 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}));
+ }
/**
* 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
new file mode 100644
index 00000000000..3194bf28d33
--- /dev/null
+++ b/jstests/replsets/drop_oplog_should_fail_if_storage_engine_supports_replSetResizeOplog_command.js
@@ -0,0 +1,39 @@
+// 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().
+(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
+ });
+
+ rt.startSet();
+
+ rt.initiate();
+
+ // Restart as a standalone node.
+ rt.restart(0, {noReplSet: true});
+
+ let master = rt.getPrimary();
+ let localDB = master.getDB('local');
+
+ if (storageEngineIsWiredTigerOrInMemory()) {
+ 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 6e7fc422d5f..6203a030672 100644
--- a/src/mongo/db/commands/dbcommands.cpp
+++ b/src/mongo/db/commands/dbcommands.cpp
@@ -305,11 +305,22 @@ public:
return false;
}
- if ((repl::ReplicationCoordinator::get(opCtx)->getReplicationMode() !=
- repl::ReplicationCoordinator::modeNone) &&
- nsToDrop.isOplog()) {
- errmsg = "can't drop live oplog while replicating";
- 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;
+ }
}
uassertStatusOK(