summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Suarez <kyle.suarez@mongodb.com>2016-12-14 09:49:24 -0500
committerKyle Suarez <kyle.suarez@mongodb.com>2017-01-18 13:21:01 -0500
commit3c2c8f709d7043d22d1161fce807c40e4d624742 (patch)
tree46ef8b63641a5301b446b8bd1459a17e688d02e4
parentc67e4f73af63f165bad10d5ceb435056084bf5fa (diff)
downloadmongo-3c2c8f709d7043d22d1161fce807c40e4d624742.tar.gz
SERVER-25286 rewrite drop2.js to not depend on count scan yield behavior
(cherry picked from commit 703678d473121b6402df10c21060241096ee2722) Conflicts: buildscripts/resmokeconfig/suites/sharded_collections_jscore_passthrough.yml buildscripts/resmokeconfig/suites/sharding_jscore_passthrough.yml
-rw-r--r--buildscripts/resmokeconfig/suites/sharded_collections_jscore_passthrough.yml1
-rw-r--r--buildscripts/resmokeconfig/suites/sharding_jscore_passthrough.yml1
-rw-r--r--jstests/core/drop2.js57
-rw-r--r--jstests/core/killop_drop_collection.js55
-rw-r--r--jstests/libs/parallelTester.js2
5 files changed, 58 insertions, 58 deletions
diff --git a/buildscripts/resmokeconfig/suites/sharded_collections_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/sharded_collections_jscore_passthrough.yml
index 32ad9399d63..e88028fcb41 100644
--- a/buildscripts/resmokeconfig/suites/sharded_collections_jscore_passthrough.yml
+++ b/buildscripts/resmokeconfig/suites/sharded_collections_jscore_passthrough.yml
@@ -68,6 +68,7 @@ selector:
- jstests/core/eval0.js
- jstests/core/eval7.js
- jstests/core/eval9.js
+ - jstests/core/killop_drop_collection.js # Uses fsyncLock.
executor:
js_test:
diff --git a/buildscripts/resmokeconfig/suites/sharding_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/sharding_jscore_passthrough.yml
index a1758adb65c..db5e043b209 100644
--- a/buildscripts/resmokeconfig/suites/sharding_jscore_passthrough.yml
+++ b/buildscripts/resmokeconfig/suites/sharding_jscore_passthrough.yml
@@ -42,6 +42,7 @@ selector:
# TODO: SERVER-18292 remove once OP_COMMAND is implemented in mongos.
- jstests/core/invalid_db_name.js
- jstests/core/validate_cmd_ns.js
+ - jstests/core/killop_drop_collection.js # Uses fsyncLock.
executor:
js_test:
diff --git a/jstests/core/drop2.js b/jstests/core/drop2.js
deleted file mode 100644
index 54f6b8b78ab..00000000000
--- a/jstests/core/drop2.js
+++ /dev/null
@@ -1,57 +0,0 @@
-var coll = db.jstests_drop2;
-coll.drop();
-
-function debug(x) {
- printjson(x);
-}
-
-coll.save({});
-
-function getOpId(drop) {
- var inProg = db.currentOp().inprog;
- debug(inProg);
- for (var id in inProg) {
- var op = inProg[id];
- if (drop) {
- if (op.query && op.query.drop && op.query.drop == coll.getName()) {
- return op.opid;
- }
- } else {
- if (op.query && op.query.query && op.query.query.$where && op.ns == (coll + "")) {
- return op.opid;
- }
- }
- }
- return null;
-}
-
-var awaitCount = startParallelShell(
- "print(\"Count thread started\");" + "db.getMongo().getCollection(\"" + (coll + "") + "\")" +
- ".count( { $where: function() {" + "while( 1 ) { sleep( 1 ); } } } );" +
- "print(\"Count thread terminating\");");
-countOpId = null;
-assert.soon(function() {
- countOpId = getOpId(false);
- return countOpId;
-});
-
-var awaitDrop =
- startParallelShell("print(\"Drop thread started\");" + "print(\"drop result: \" + " +
- "db.getMongo().getCollection(\"" + (coll + "") + "\")" + ".drop() );" +
- "print(\"Drop thread terminating\")");
-dropOpId = null;
-assert.soon(function() {
- dropOpId = getOpId(true);
- return dropOpId;
-});
-
-db.killOp(dropOpId);
-db.killOp(countOpId);
-
-var exitCode = awaitCount({checkExitSuccess: false});
-assert.neq(0, exitCode, "expected shell to exit abnormally due to JS execution being terminated");
-
-// The drop operation may or may not have been killed.
-awaitDrop({checkExitSuccess: false});
-
-coll.drop(); // in SERVER-1818, this fails
diff --git a/jstests/core/killop_drop_collection.js b/jstests/core/killop_drop_collection.js
new file mode 100644
index 00000000000..94d7d560dd3
--- /dev/null
+++ b/jstests/core/killop_drop_collection.js
@@ -0,0 +1,55 @@
+/**
+ * A killOp command issued against a collection drop should not interfere with the drop and allow it
+ * to complete. Interrupting a collection drop could leave the database in an inconsistent state.
+ * This test confirms that killOp won't interrupt a collection drop, and that the drop occurs
+ * successfully.
+ */
+(function() {
+ "use strict";
+
+ const collectionName = "killop_drop";
+ let collection = db.getCollection(collectionName);
+ collection.drop();
+ assert.writeOK(collection.insert({x: 1}));
+
+ // Attempt to fsyncLock the database, aborting early if the storage engine doesn't support it.
+ const storageEngine = jsTest.options().storageEngine;
+ let fsyncRes = db.fsyncLock();
+ if (!fsyncRes.ok) {
+ assert.commandFailedWithCode(fsyncRes, ErrorCodes.CommandNotSupported);
+ jsTest.log("Skipping test on storage engine " + storageEngine +
+ ", which does not support fsyncLock.");
+ return;
+ }
+
+ // Kick off a drop on the collection.
+ const useDefaultPort = null;
+ const noConnect = false;
+ let awaitDropCommand = startParallelShell(function() {
+ assert.commandWorked(db.getSiblingDB("test").runCommand({drop: "killop_drop"}));
+ }, useDefaultPort, noConnect);
+
+ // Wait for the drop operation to appear in the db.currentOp() output.
+ let dropCommandOpId = null;
+ assert.soon(function() {
+ let dropOpsInProgress =
+ db.currentOp().inprog.filter(op => op.query && op.query.drop === collection.getName());
+ if (dropOpsInProgress.length > 0) {
+ dropCommandOpId = dropOpsInProgress[0].opid;
+ }
+ return dropCommandOpId;
+ });
+
+ // Issue a killOp for the drop command, then unlock the server. We expect that the drop
+ // operation was *not* killed, and that the collection was dropped successfully.
+ assert.commandWorked(db.killOp(dropCommandOpId));
+ let unlockRes = assert.commandWorked(db.fsyncUnlock());
+ assert.eq(0,
+ unlockRes.lockCount,
+ "Expected the number of fsyncLocks to be zero after issuing fsyncUnlock");
+ awaitDropCommand();
+
+ // Ensure that the collection has been dropped.
+ assert(!db.getCollectionNames().includes(collectionName),
+ "Expected collection to not appear in listCollections output after being dropped");
+}());
diff --git a/jstests/libs/parallelTester.js b/jstests/libs/parallelTester.js
index 0126bfad9c3..ed55078934b 100644
--- a/jstests/libs/parallelTester.js
+++ b/jstests/libs/parallelTester.js
@@ -139,7 +139,6 @@ if (typeof _threadInject != "undefined") {
"killop.js",
"run_program1.js",
"notablescan.js",
- "drop2.js",
"dropdb_race.js",
"fsync2.js", // May be placed in serialTestsArr once SERVER-4243 is fixed.
"bench_test1.js",
@@ -170,6 +169,7 @@ if (typeof _threadInject != "undefined") {
// These tests use fsyncLock.
parallelFilesDir + "/fsync.js",
parallelFilesDir + "/currentop.js",
+ parallelFilesDir + "/killop_drop_collection.js",
// These tests expect the profiler to be on or off at specific points
// during the test run.