summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2017-09-15 11:47:23 -0400
committerLouis Williams <louis.williams@mongodb.com>2017-09-21 13:18:54 -0400
commit532ab3543012436e8274740301f29457ee4e9fdb (patch)
treeae5d32d58a2ed2c207f941ae1bb6baf58d117dac /jstests
parentdd71aa808cc60bace3fcd629353897883f034ee1 (diff)
downloadmongo-532ab3543012436e8274740301f29457ee4e9fdb.tar.gz
SERVER-30993 Always remove UUIDs when setting featureCompatibilityVersion to 3.4
Diffstat (limited to 'jstests')
-rw-r--r--jstests/multiVersion/incomplete_upgrade_downgrade.js150
1 files changed, 150 insertions, 0 deletions
diff --git a/jstests/multiVersion/incomplete_upgrade_downgrade.js b/jstests/multiVersion/incomplete_upgrade_downgrade.js
new file mode 100644
index 00000000000..5c1367b3e49
--- /dev/null
+++ b/jstests/multiVersion/incomplete_upgrade_downgrade.js
@@ -0,0 +1,150 @@
+/**
+ * This test verifies that if mongod exits after setting the FCV document to 3.4 before the
+ * collection UUIDs are removed, that re-running the downgrade to 3.4 is possible.
+ */
+(function() {
+ "use strict";
+
+ let checkFCV = function(adminDB, version) {
+ let res = adminDB.runCommand({getParameter: 1, featureCompatibilityVersion: 1});
+ assert.commandWorked(res);
+ assert.eq(res.featureCompatibilityVersion, version);
+ assert.eq(adminDB.system.version.findOne({_id: "featureCompatibilityVersion"}).version,
+ version);
+ };
+
+ let setFCV = function(adminDB, version) {
+ assert.commandWorked(adminDB.runCommand({setFeatureCompatibilityVersion: version}));
+ };
+
+ // Inserts test data
+ let insertDataForConn = function(conn, dbs) {
+ for (let i = 0; i < 20; i++) {
+ let doc = {id: i, a: "foo", conn: conn.name};
+ for (let j in dbs) {
+ assert.writeOK(conn.getDB(dbs[j]).foo.insert(doc));
+ }
+ }
+ };
+
+ // Verifies that UUIDs exist when uuidsExpected is true, and that UUIDs do not exist when
+ // uuidsExpected is false.
+ let checkCollectionUUIDs = function(adminDB, uuidsExpected, excludeLocal = true) {
+ let databaseList = adminDB.runCommand({"listDatabases": 1}).databases;
+
+ databaseList.forEach(function(database) {
+ if (excludeLocal && database.name == "local") {
+ jsTest.log("Skipping local");
+ return;
+ }
+ let currentDatabase = adminDB.getSiblingDB(database.name);
+ let collectionInfos = currentDatabase.getCollectionInfos();
+ for (let i = 0; i < collectionInfos.length; i++) {
+ // Always skip system.indexes due to SERVER-30500.
+ if (collectionInfos[i].name == "system.indexes") {
+ continue;
+ }
+ // Exclude checking all collections in local until SERVER-30131 is fixed.
+ if (!uuidsExpected) {
+ assert(!collectionInfos[i].info.uuid,
+ "Unexpected uuid for collection: " + tojson(collectionInfos[i]));
+ } else {
+ assert(collectionInfos[i].info.uuid,
+ "Expect uuid for collection: " + tojson(collectionInfos[i]));
+ }
+ }
+ });
+ };
+
+ jsTest.log("Testing Incomeplete Downgrade");
+
+ let dbpath = MongoRunner.dataPath + "incomplete_downgrade";
+ resetDbpath(dbpath);
+
+ let conn = MongoRunner.runMongod({dbpath: dbpath});
+ assert.neq(null, conn, "mongod was unable to start up");
+ let adminDB = conn.getDB("admin");
+
+ // Insert test data.
+ insertDataForConn(conn, ["admin", "local", "test"]);
+
+ // Ensure featureCompatibilityVersion is 3.6 and collections have UUIDs.
+ checkFCV(adminDB, "3.6");
+ checkCollectionUUIDs(adminDB, true);
+
+ // Set failure point to exit after setting featureCompatibilityVersion document before removing
+ // UUIDs from collections.
+ assert.commandWorked(
+ conn.adminCommand({configureFailPoint: "featureCompatibilityDowngrade", mode: "alwaysOn"}));
+
+ // Downgrade, which should trigger a shutdown, so don't check for result.
+ // Mongod should stop responding.
+ assert.soon(function() {
+ try {
+ adminDB.runCommand({setFeatureCompatibilityVersion: "3.4"});
+ } catch (e) {
+ return true;
+ }
+ }, "Mongod should stop responding", 10 * 1000);
+
+ // Check for clean exit.
+ MongoRunner.validateCollectionsCallback = function() {};
+ MongoRunner.stopMongod(conn);
+
+ // Start mongod again with the same dbpath
+ conn = MongoRunner.runMongod({dbpath: dbpath, noCleanData: true});
+ assert.neq(null, conn, "mongod was unable to start up");
+ adminDB = conn.getDB("admin");
+
+ // FeatureCompatibility document should be 3.4.
+ checkFCV(adminDB, "3.4");
+
+ // Check that collections still have UUIDs.
+ checkCollectionUUIDs(adminDB, /* uuidsExpected */ true);
+
+ // Now that failpoint is not set, resume downgrade.
+ setFCV(adminDB, "3.4");
+
+ // Verify no collections have UUIDS now.
+ checkCollectionUUIDs(adminDB, false);
+
+ jsTest.log("Testing Incomplete Upgrade");
+
+ // Set failure point to exit before setting featureCompatibilityVersion document and after
+ // creating UUIDs for collections.
+ assert.commandWorked(
+ conn.adminCommand({configureFailPoint: "featureCompatibilityUpgrade", mode: "alwaysOn"}));
+
+ // Try upgrade to 3.6, which triggers the failpoint to exit, immediately after creating UUIDs.
+ assert.soon(function() {
+ try {
+ adminDB.runCommand({setFeatureCompatibilityVersion: "3.6"});
+ } catch (e) {
+ return true;
+ }
+ }, "Mongod should stop responding", 10 * 1000);
+
+ // Verify mongod stopped cleanly
+ MongoRunner.stopMongod(conn);
+
+ // Start mongod again with the same dbpath
+ conn = MongoRunner.runMongod({dbpath: dbpath, noCleanData: true});
+ assert.neq(null, conn, "mongod was unable to start up");
+ adminDB = conn.getDB("admin");
+
+ // Check that collections have UUIDs.
+ checkCollectionUUIDs(adminDB, /* uuidsExpected */ true);
+
+ // The FCV document should not be updated yet.
+ checkFCV(adminDB, "3.4");
+
+ // Now that failpoint is not set, resume upgrade.
+ setFCV(adminDB, "3.6");
+
+ // Verify all collections still have UUIDS.
+ checkCollectionUUIDs(adminDB, true);
+
+ // Verify FCV.
+ checkFCV(adminDB, "3.6");
+
+})();