diff options
author | Louis Williams <louis.williams@mongodb.com> | 2017-09-13 16:16:56 -0400 |
---|---|---|
committer | Louis Williams <louis.williams@mongodb.com> | 2017-09-15 16:09:48 -0400 |
commit | ca0e39792df88e2e9054d9d6349c4669f58ae7f8 (patch) | |
tree | b98706ee6d44285dcc0874cbcb00ee8a25d42661 /jstests | |
parent | 7b7de197a787073ecf47f89d1f9976758f24390a (diff) | |
download | mongo-ca0e39792df88e2e9054d9d6349c4669f58ae7f8.tar.gz |
SERVER-30429 Multiversion upgrade/downgrade testing for UUIDs
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/multiVersion/set_schema_version.js | 297 |
1 files changed, 184 insertions, 113 deletions
diff --git a/jstests/multiVersion/set_schema_version.js b/jstests/multiVersion/set_schema_version.js index 5f2efbf82b4..fe1a8a52cea 100644 --- a/jstests/multiVersion/set_schema_version.js +++ b/jstests/multiVersion/set_schema_version.js @@ -37,129 +37,200 @@ }); }; + let checkFCV = function(adminDB, version, is34) { + if (!is34) { + 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})); + checkFCV(adminDB, version); + }; + + 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)); + } + } + } + + // Create and clear dbpath + let sharedDbPath = MongoRunner.dataPath + "set_schema_version"; + resetDbpath(sharedDbPath); + + // Return a mongodb connection with version and dbpath options + let startMongodWithVersion = function(ver, path) { + let version = ver || latest; + let dbpath = path || sharedDbPath; + let conn = MongoRunner.runMongod({dbpath: dbpath, binVersion: version}); + assert.neq(null, + conn, + "mongod was unable to start up with version=" + version + " and path=" + dbpath); + return conn; + }; + // // Standalone tests. // + let standaloneTest = function() { - let dbpath = MongoRunner.dataPath + "feature_compatibility_version"; - resetDbpath(dbpath); - - // New 3.6 standalone. - let conn = MongoRunner.runMongod({dbpath: dbpath, binVersion: latest}); - assert.neq( - null, conn, "mongod was unable to start up with version=" + latest + " and no data files"); - let adminDB = conn.getDB("admin"); - - // Initially featureCompatibilityVersion is 3.6. - let res = adminDB.runCommand({getParameter: 1, featureCompatibilityVersion: 1}); - assert.commandWorked(res); - assert.eq(res.featureCompatibilityVersion, "3.6"); - assert.eq(adminDB.system.version.findOne({_id: "featureCompatibilityVersion"}).version, "3.6"); - - // Ensure all collections have UUIDs in 3.6 mode. - checkCollectionUUIDs(adminDB, false, true); - - // Set featureCompatibilityVersion to 3.4. - assert.commandWorked(adminDB.runCommand({setFeatureCompatibilityVersion: "3.4"})); - res = adminDB.runCommand({getParameter: 1, featureCompatibilityVersion: 1}); - assert.commandWorked(res); - assert.eq(res.featureCompatibilityVersion, "3.4"); - - // Ensure no collections in a featureCompatibilityVersion 3.4 database have UUIDs. - adminDB = conn.getDB("admin"); - checkCollectionUUIDs(adminDB, true, false); - - // Ensure all collections have UUIDs after switching back to featureCompatibilityVersion 3.6. - assert.commandWorked(adminDB.runCommand({setFeatureCompatibilityVersion: "3.6"})); - res = adminDB.runCommand({getParameter: 1, featureCompatibilityVersion: 1}); - assert.commandWorked(res); - assert.eq(res.featureCompatibilityVersion, "3.6"); - checkCollectionUUIDs(adminDB, false, false); + // New 3.6 standalone. + let conn = startMongodWithVersion(latest); + let adminDB = conn.getDB("admin"); - // - // Replica set tests. - // + // Initially featureCompatibilityVersion is 3.6. + checkFCV(adminDB, "3.6"); - // New 3.6 replica set. - let rst = new ReplSetTest({nodes: 3, nodeOpts: {binVersion: latest}}); - rst.startSet(); - rst.initiate(); - let primaryAdminDB = rst.getPrimary().getDB("admin"); - let secondaries = rst.getSecondaries(); - - // Initially featureCompatibilityVersion is 3.6 on primary and secondaries. - res = primaryAdminDB.runCommand({getParameter: 1, featureCompatibilityVersion: 1}); - assert.commandWorked(res); - assert.eq(res.featureCompatibilityVersion, "3.6"); - assert.eq(primaryAdminDB.system.version.findOne({_id: "featureCompatibilityVersion"}).version, - "3.6"); - rst.awaitReplication(); - for (let j = 0; j < secondaries.length; j++) { - let secondaryAdminDB = secondaries[j].getDB("admin"); - res = secondaryAdminDB.runCommand({getParameter: 1, featureCompatibilityVersion: 1}); - assert.commandWorked(res); - assert.eq(res.featureCompatibilityVersion, "3.6"); - assert.eq( - secondaryAdminDB.system.version.findOne({_id: "featureCompatibilityVersion"}).version, - "3.6"); - } + // Insert some data + insertDataForConn(conn, ["admin", "local", "test"]); - // Ensure all collections have UUIDs in 3.6 mode on both primary and secondaries. - checkCollectionUUIDs(primaryAdminDB, false, true); - for (let j = 0; j < secondaries.length; j++) { - let secondaryAdminDB = secondaries[j].getDB("admin"); - checkCollectionUUIDs(secondaryAdminDB, false, true); - } + // Ensure all collections have UUIDs in 3.6 mode. + checkCollectionUUIDs(adminDB, false, true); - // Change featureCompatibilityVersion to 3.4. - assert.commandWorked(primaryAdminDB.runCommand({setFeatureCompatibilityVersion: "3.4"})); - res = primaryAdminDB.runCommand({getParameter: 1, featureCompatibilityVersion: 1}); - assert.commandWorked(res); - assert.eq(res.featureCompatibilityVersion, "3.4"); - assert.eq(primaryAdminDB.system.version.findOne({_id: "featureCompatibilityVersion"}).version, - "3.4"); - rst.awaitReplication(); - for (let j = 0; j < secondaries.length; j++) { - let secondaryAdminDB = secondaries[j].getDB("admin"); - res = secondaryAdminDB.runCommand({getParameter: 1, featureCompatibilityVersion: 1}); - assert.commandWorked(res); - assert.eq(res.featureCompatibilityVersion, "3.4"); - assert.eq( - secondaryAdminDB.system.version.findOne({_id: "featureCompatibilityVersion"}).version, - "3.4"); - } + // Set featureCompatibilityVersion to 3.4. + setFCV(adminDB, "3.4"); - // Ensure no collections have UUIDs in 3.4 mode on both primary and secondaries. - checkCollectionUUIDs(primaryAdminDB, true, false); - for (let j = 0; j < secondaries.length; j++) { - let secondaryAdminDB = secondaries[j].getDB("admin"); - checkCollectionUUIDs(secondaryAdminDB, true, false); - } + // Ensure no collections in a featureCompatibilityVersion 3.4 database have UUIDs. + checkCollectionUUIDs(adminDB, true, false); - // Ensure all collections have UUIDs after switching back to featureCompatibilityVersion 3.6 on - // both primary and secondaries. - assert.commandWorked(primaryAdminDB.runCommand({setFeatureCompatibilityVersion: "3.6"})); - res = primaryAdminDB.runCommand({getParameter: 1, featureCompatibilityVersion: 1}); - assert.commandWorked(res); - assert.eq(res.featureCompatibilityVersion, "3.6"); - assert.eq(primaryAdminDB.system.version.findOne({_id: "featureCompatibilityVersion"}).version, - "3.6"); - rst.awaitReplication(); - for (let j = 0; j < secondaries.length; j++) { - let secondaryAdminDB = secondaries[j].getDB("admin"); - res = secondaryAdminDB.runCommand({getParameter: 1, featureCompatibilityVersion: 1}); - assert.commandWorked(res); - assert.eq(res.featureCompatibilityVersion, "3.6"); - assert.eq( - secondaryAdminDB.system.version.findOne({_id: "featureCompatibilityVersion"}).version, - "3.6"); - } + // Stop Mongod 3.6 + MongoRunner.stopMongod(conn); - checkCollectionUUIDs(primaryAdminDB, false, false); - for (let j = 0; j < secondaries.length; j++) { - let secondaryAdminDB = secondaries[j].getDB("admin"); - checkCollectionUUIDs(secondaryAdminDB, false, false); - } + // Start Mongod 3.4 with same dbpath + jsTest.log("Starting MongoDB 3.4 to test downgrade"); + let downgradeConn = startMongodWithVersion(downgrade); + let downgradeAdminDB = downgradeConn.getDB("admin"); + + // Check FCV document + checkFCV(downgradeAdminDB, "3.4", true); + + // Ensure there are no UUIDs + checkCollectionUUIDs(downgradeAdminDB, true, false); + + // Stop 3.4 + MongoRunner.stopMongod(downgradeConn); + + // Start 3.6 again + jsTest.log("Starting MongoDB 3.6 to test upgrade"); + conn = startMongodWithVersion(latest); + adminDB = conn.getDB("admin"); + + // Ensure all collections have UUIDs after switching back to featureCompatibilityVersion + // 3.6. + setFCV(adminDB, "3.6"); + checkCollectionUUIDs(adminDB, false, true); + + // Stop Mongod 3.6 for the last time + MongoRunner.stopMongod(conn); + }; + + // + // Replica set tests. + // + let replicaSetTest = function() { + + // New 3.6 replica set. + let rst = new ReplSetTest({nodes: 3, binVersion: latest}); + rst.startSet(); + rst.initiate(); + let primaryAdminDB = rst.getPrimary().getDB("admin"); + let secondaries = rst.getSecondaries(); + + // Initially featureCompatibilityVersion is 3.6 on primary and secondaries, and insert some + // data. + checkFCV(primaryAdminDB, "3.6"); + insertDataForConn(rst.getPrimary(), ["admin", "local", "test"]); + rst.awaitReplication(); + + for (let j = 0; j < secondaries.length; j++) { + let secondaryAdminDB = secondaries[j].getDB("admin"); + checkFCV(secondaryAdminDB, "3.6"); + // Insert some data into the local DB + insertDataForConn(secondaries[j], ["local"]); + } + + // Ensure all collections have UUIDs in 3.6 mode on both primary and secondaries. + checkCollectionUUIDs(primaryAdminDB, false, true); + for (let j = 0; j < secondaries.length; j++) { + let secondaryAdminDB = secondaries[j].getDB("admin"); + checkCollectionUUIDs(secondaryAdminDB, false, true); + } + + // Change featureCompatibilityVersion to 3.4. + setFCV(primaryAdminDB, "3.4"); + rst.awaitReplication(); + for (let j = 0; j < secondaries.length; j++) { + let secondaryAdminDB = secondaries[j].getDB("admin"); + checkFCV(secondaryAdminDB, "3.4"); + } + + // Ensure no collections have UUIDs in 3.4 mode on both primary and secondaries. + checkCollectionUUIDs(primaryAdminDB, true, false); + for (let j = 0; j < secondaries.length; j++) { + let secondaryAdminDB = secondaries[j].getDB("admin"); + checkCollectionUUIDs(secondaryAdminDB, true, false); + } + + // Stop 3.6 RS + rst.stopSet(); + + // Downgrade RS the 3.4 binary, and make sure everything is okay + let downgradeRst = new ReplSetTest({nodes: 3, nodeOptions: {binVersion: downgrade}}); + downgradeRst.startSet(); + downgradeRst.initiate(); + + // Check that the featureCompatiblityDocument is set to 3.4 and that there are no UUIDs + let downgradePrimaryAdminDB = downgradeRst.getPrimary().getDB("admin"); + let downgradeSecondaries = downgradeRst.getSecondaries(); + + // Initially featureCompatibilityVersion document is 3.4 on primary and secondaries. + checkCollectionUUIDs(downgradePrimaryAdminDB, true, false); + checkFCV(downgradePrimaryAdminDB, "3.4", true); + for (let j = 0; j < downgradeSecondaries.length; j++) { + let secondaryAdminDB = downgradeSecondaries[j].getDB("admin"); + checkFCV(secondaryAdminDB, "3.4", true); + + // Ensure no collections have UUIDs + checkCollectionUUIDs(secondaryAdminDB, true, false); + } + + downgradeRst.stopSet(); + + // Start 3.6 cluster again + rst = new ReplSetTest({nodes: 3, binVersion: latest}); + rst.startSet(); + rst.initiate(); + primaryAdminDB = rst.getPrimary().getDB("admin"); + secondaries = rst.getSecondaries(); + + // Ensure all collections have UUIDs after switching back to featureCompatibilityVersion 3.6 + // on both primary and secondaries. + setFCV(primaryAdminDB, "3.6"); + rst.awaitReplication(); + for (let j = 0; j < secondaries.length; j++) { + let secondaryAdminDB = secondaries[j].getDB("admin"); + checkFCV(secondaryAdminDB, "3.6"); + } + + checkCollectionUUIDs(primaryAdminDB, false, true); + for (let j = 0; j < secondaries.length; j++) { + let secondaryAdminDB = secondaries[j].getDB("admin"); + checkCollectionUUIDs(secondaryAdminDB, false, true); + } + + rst.stopSet(); + }; + + // Do tests + standaloneTest(); + replicaSetTest(); - rst.stopSet(); })(); |