summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorMaria van Keulen <maria@mongodb.com>2018-05-17 15:12:05 -0400
committerMaria van Keulen <maria@mongodb.com>2018-06-06 16:54:44 -0400
commit7c12245583958023e35bce05d6b2212dcd7f24e3 (patch)
tree4cfa8bb4915cef1973b208d33fa6023b1c5cdb65 /jstests
parent0b001ed1ab7e8443213db38030cf17d2a6f5be2c (diff)
downloadmongo-7c12245583958023e35bce05d6b2212dcd7f24e3.tar.gz
SERVER-34615 Make UUIDCatalog updates for renameCollection atomic
Diffstat (limited to 'jstests')
-rw-r--r--jstests/libs/parallel_shell_helpers.js5
-rw-r--r--jstests/multiVersion/upgrade_downgrade_while_creating_collection.js4
-rw-r--r--jstests/noPassthrough/find_by_uuid_and_rename.js56
-rw-r--r--jstests/noPassthrough/libs/concurrent_rename.js16
-rw-r--r--jstests/noPassthrough/list_databases_and_rename_collection.js26
5 files changed, 84 insertions, 23 deletions
diff --git a/jstests/libs/parallel_shell_helpers.js b/jstests/libs/parallel_shell_helpers.js
new file mode 100644
index 00000000000..70a60a5be0a
--- /dev/null
+++ b/jstests/libs/parallel_shell_helpers.js
@@ -0,0 +1,5 @@
+/**
+ * Allows passing arguments to the function executed by startParallelShell.
+ */
+const funWithArgs = (fn, ...args) =>
+ "(" + fn.toString() + ")(" + args.map(x => tojson(x)).reduce((x, y) => x + ", " + y) + ")";
diff --git a/jstests/multiVersion/upgrade_downgrade_while_creating_collection.js b/jstests/multiVersion/upgrade_downgrade_while_creating_collection.js
index 8926cbdfa90..ba675fbae67 100644
--- a/jstests/multiVersion/upgrade_downgrade_while_creating_collection.js
+++ b/jstests/multiVersion/upgrade_downgrade_while_creating_collection.js
@@ -4,6 +4,7 @@
(function() {
"use strict";
load("jstests/libs/feature_compatibility_version.js");
+ load("jstests/libs/parallel_shell_helpers.js");
const rst = new ReplSetTest({nodes: 2});
rst.startSet();
@@ -42,9 +43,6 @@
return rawMongoProgramOutput().match("createCollection: test.mycoll");
});
- const funWithArgs = (fn, ...args) => "(" + fn.toString() + ")(" +
- args.map(x => tojson(x)).reduce((x, y) => x + ", " + y) + ")";
-
awaitUpgradeFCV = startParallelShell(
funWithArgs(function(version) {
assert.commandWorked(
diff --git a/jstests/noPassthrough/find_by_uuid_and_rename.js b/jstests/noPassthrough/find_by_uuid_and_rename.js
new file mode 100644
index 00000000000..d07c1da0ce6
--- /dev/null
+++ b/jstests/noPassthrough/find_by_uuid_and_rename.js
@@ -0,0 +1,56 @@
+//
+// Run 'find' by UUID while renaming a collection concurrently. See SERVER-34615.
+//
+
+(function() {
+ "use strict";
+ const dbName = "do_concurrent_rename";
+ const collName = "collA";
+ const otherName = "collB";
+ const repeatFind = 100;
+ load("jstests/noPassthrough/libs/concurrent_rename.js");
+ load("jstests/libs/parallel_shell_helpers.js");
+
+ const conn = MongoRunner.runMongod({});
+ assert.neq(null, conn, "mongod was unable to start up");
+ jsTestLog("Create collection.");
+ let findRenameDB = conn.getDB(dbName);
+ findRenameDB.dropDatabase();
+ assert.commandWorked(findRenameDB.runCommand({"create": collName}));
+ assert.commandWorked(
+ findRenameDB.runCommand({insert: collName, documents: [{fooField: 'FOO'}]}));
+
+ let infos = findRenameDB.getCollectionInfos();
+ let uuid = infos[0].info.uuid;
+ const findCmd = {"find": uuid};
+
+ // Assert 'find' command by UUID works.
+ assert.commandWorked(findRenameDB.runCommand(findCmd));
+
+ jsTestLog("Start parallel shell for renames.");
+ let renameShell =
+ startParallelShell(funWithArgs(doRenames, dbName, collName, otherName), conn.port);
+
+ // Wait until we receive confirmation that the parallel shell has started.
+ assert.soon(() => conn.getDB("test").await_data.findOne({_id: "signal parent shell"}) !== null,
+ "Expected parallel shell to insert a document.");
+
+ jsTestLog("Start 'find' commands.");
+ while (conn.getDB("test").await_data.findOne({_id: "rename has ended"}) == null) {
+ for (let i = 0; i < repeatFind; i++) {
+ let res = findRenameDB.runCommand(findCmd);
+ assert.commandWorked(res, "could not run " + tojson(findCmd));
+ let cursor = new DBCommandCursor(findRenameDB, res);
+ let errMsg = "expected more data from command " + tojson(findCmd) + ", with result " +
+ tojson(res);
+ assert(cursor.hasNext(), errMsg);
+ let doc = cursor.next();
+ assert.eq(doc.fooField, "FOO");
+ assert(!cursor.hasNext(),
+ "expected to have exhausted cursor for results " + tojson(res));
+ }
+ }
+ renameShell();
+ MongoRunner.stopMongod(conn);
+
+}());
diff --git a/jstests/noPassthrough/libs/concurrent_rename.js b/jstests/noPassthrough/libs/concurrent_rename.js
new file mode 100644
index 00000000000..79d1a0074c3
--- /dev/null
+++ b/jstests/noPassthrough/libs/concurrent_rename.js
@@ -0,0 +1,16 @@
+// Perform a set number of renames from collA to collB and vice versa. This function is to be called
+// from a parallel shell, and is useful for simulating executions of functions concurrently with
+// collection renames.
+function doRenames(dbName, collName, otherName) {
+ const repeatRename = 200;
+ // Signal to the parent shell that the parallel shell has started.
+ assert.writeOK(db.await_data.insert({_id: "signal parent shell"}));
+ let renameDB = db.getSiblingDB(dbName);
+ for (let i = 0; i < repeatRename; i++) {
+ // Rename the collection back and forth.
+ assert.commandWorked(renameDB[collName].renameCollection(otherName));
+ assert.commandWorked(renameDB[otherName].renameCollection(collName));
+ }
+ // Signal to the parent shell that the renames have completed.
+ assert.writeOK(db.await_data.insert({_id: "rename has ended"}));
+}
diff --git a/jstests/noPassthrough/list_databases_and_rename_collection.js b/jstests/noPassthrough/list_databases_and_rename_collection.js
index 6d8351e0737..9faebcb7dc8 100644
--- a/jstests/noPassthrough/list_databases_and_rename_collection.js
+++ b/jstests/noPassthrough/list_databases_and_rename_collection.js
@@ -4,28 +4,13 @@
(function() {
"use strict";
- const dbName = "list_databases_rename";
+ const dbName = "do_concurrent_rename";
const collName = "collA";
+ const otherName = "collB";
const repeatListDatabases = 20;
const listDatabasesCmd = {"listDatabases": 1};
-
- // To be called from startParallelShell.
- function doRenames() {
- const dbName = "list_databases_rename";
- const collName = "collA";
- const repeatRename = 200;
- // Signal to the parent shell that the parallel shell has started.
- assert.writeOK(db.await_data.insert({_id: "signal parent shell"}));
- const otherName = "collB";
- let listRenameDB = db.getSiblingDB(dbName);
- for (let i = 0; i < repeatRename; i++) {
- // Rename the collection back and forth.
- assert.commandWorked(listRenameDB[collName].renameCollection(otherName));
- assert.commandWorked(listRenameDB[otherName].renameCollection(collName));
- }
- // Signal to the parent shell that the renames have completed.
- assert.writeOK(db.await_data.insert({_id: "rename has ended"}));
- }
+ load("jstests/noPassthrough/libs/concurrent_rename.js");
+ load("jstests/libs/parallel_shell_helpers.js");
const conn = MongoRunner.runMongod({});
assert.neq(null, conn, "mongod was unable to start up");
@@ -46,7 +31,8 @@
"expected " + tojson(cmdRes) + " to include " + dbName);
jsTestLog("Start parallel shell");
- let renameShell = startParallelShell(doRenames, conn.port);
+ let renameShell =
+ startParallelShell(funWithArgs(doRenames, dbName, collName, otherName), conn.port);
// Wait until we receive confirmation that the parallel shell has started.
assert.soon(() => conn.getDB("test").await_data.findOne({_id: "signal parent shell"}) !== null);