diff options
author | Maria van Keulen <maria@mongodb.com> | 2017-11-02 11:24:50 -0400 |
---|---|---|
committer | Maria van Keulen <maria@mongodb.com> | 2017-11-15 17:24:18 -0500 |
commit | c030499c794451bb94846f2e297270890ea2ad0a (patch) | |
tree | 52e8e280b52d1683d6f74712de62f4c2deed7f9d | |
parent | 2b27f4a1feb595b1ee96dd1f62db98741a17695f (diff) | |
download | mongo-c030499c794451bb94846f2e297270890ea2ad0a.tar.gz |
SERVER-31792 Generate UUIDs for config servers during initiate
(cherry picked from commit bf03a51f20694b0b80aea4e7390db1fbd1274a5f)
-rw-r--r-- | jstests/multiVersion/set_schema_version.js | 139 | ||||
-rw-r--r-- | src/mongo/db/repl/initial_syncer.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_external_state_impl.cpp | 18 |
3 files changed, 100 insertions, 62 deletions
diff --git a/jstests/multiVersion/set_schema_version.js b/jstests/multiVersion/set_schema_version.js index 3290cf53ce0..ab198fb264e 100644 --- a/jstests/multiVersion/set_schema_version.js +++ b/jstests/multiVersion/set_schema_version.js @@ -36,11 +36,21 @@ checkFCV(adminDB, version); }; - let insertDataForConn = function(conn, dbs) { + let insertDataForConn = function(conn, dbs, nodeOptions) { 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)); + if (nodeOptions.hasOwnProperty("configsvr")) { + if (j !== "admin" && j !== "local") { + // We can't create user databases on a --configsvr instance. + continue; + } + // Config servers have a majority write concern. + assert.writeOK( + conn.getDB(dbs[j]).foo.insert(doc, {writeConcern: {w: "majority"}})); + } else { + assert.writeOK(conn.getDB(dbs[j]).foo.insert(doc)); + } } } }; @@ -49,11 +59,12 @@ let sharedDbPath = MongoRunner.dataPath + "set_schema_version"; resetDbpath(sharedDbPath); - // Return a mongodb connection with version and dbpath options - let startMongodWithVersion = function(ver, path) { + // Return a mongodb connection with startup options, version and dbpath options + let startMongodWithVersion = function(nodeOptions, ver, path) { let version = ver || latest; let dbpath = path || sharedDbPath; - let conn = MongoRunner.runMongod({dbpath: dbpath, binVersion: version}); + let conn = MongoRunner.runMongod( + Object.assign({}, nodeOptions, {dbpath: dbpath, binVersion: version})); assert.neq(null, conn, "mongod was unable to start up with version=" + version + " and path=" + dbpath); @@ -63,23 +74,31 @@ // // Standalone tests. // - let standaloneTest = function() { + let standaloneTest = function(nodeOptions) { + let noCleanDataOptions = Object.assign({noCleanData: true}, nodeOptions); // New 3.6 standalone. - let conn = startMongodWithVersion(latest); + jsTest.log("Starting a binVersion 3.6 standalone"); + let conn = startMongodWithVersion(nodeOptions, latest); let adminDB = conn.getDB("admin"); - // Initially featureCompatibilityVersion is 3.6. - checkFCV(adminDB, "3.6"); + // Insert some data. + insertDataForConn(conn, ["admin", "local", "test"], nodeOptions); - // Insert some data - insertDataForConn(conn, ["admin", "local", "test"]); + if (!nodeOptions.hasOwnProperty("shardsvr")) { + // Initially featureCompatibilityVersion is 3.6 except for when we run with shardsvr. + // We expect featureCompatibilityVersion to be 3.4 for shardsvr. + checkFCV(adminDB, "3.6"); - // Ensure all collections have UUIDs in 3.6 mode. - checkCollectionUUIDs(adminDB, false); + // Ensure all collections have UUIDs in 3.6 mode. + checkCollectionUUIDs(adminDB, false); + + // Set featureCompatibilityVersion to 3.4. + setFCV(adminDB, "3.4"); + } - // Set featureCompatibilityVersion to 3.4. - setFCV(adminDB, "3.4"); + // Ensure featureCompatibilityVersion is 3.4. + checkFCV(adminDB, "3.4"); // Ensure no collections in a featureCompatibilityVersion 3.4 database have UUIDs. checkCollectionUUIDs(adminDB, true); @@ -88,8 +107,8 @@ MongoRunner.stopMongod(conn); // Start Mongod 3.4 with same dbpath - jsTest.log("Starting MongoDB 3.4 to test downgrade"); - let downgradeConn = startMongodWithVersion(downgrade); + jsTest.log("Starting a binVersion 3.4 standalone to test downgrade"); + let downgradeConn = startMongodWithVersion(noCleanDataOptions, downgrade); let downgradeAdminDB = downgradeConn.getDB("admin"); // Check FCV document @@ -102,8 +121,8 @@ MongoRunner.stopMongod(downgradeConn); // Start 3.6 again - jsTest.log("Starting MongoDB 3.6 to test upgrade"); - conn = startMongodWithVersion(latest); + jsTest.log("Starting a binVersion 3.6 standalone to test upgrade"); + conn = startMongodWithVersion(noCleanDataOptions, latest); adminDB = conn.getDB("admin"); // Ensure all collections have UUIDs after switching back to featureCompatibilityVersion @@ -118,38 +137,50 @@ // // Replica set tests. // - let replicaSetTest = function() { + let replicaSetTest = function(nodeOptions) { // New 3.6 replica set. - let rst = new ReplSetTest({nodes: 3, binVersion: latest}); + jsTest.log("Starting a binVersion 3.6 ReplSetTest"); + let rst = new ReplSetTest({nodes: 3, nodeOptions: nodeOptions}); 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"]); + // Insert some data. + insertDataForConn(rst.getPrimary(), ["admin", "local", "test"], nodeOptions); 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"]); + // Insert some data into the local DB. + insertDataForConn(secondaries[j], ["local"], nodeOptions); } - // Ensure all collections have UUIDs in 3.6 mode on both primary and secondaries. - checkCollectionUUIDs(primaryAdminDB, false); - for (let j = 0; j < secondaries.length; j++) { - let secondaryAdminDB = secondaries[j].getDB("admin"); - checkCollectionUUIDs(secondaryAdminDB, false); + if (!nodeOptions.hasOwnProperty("shardsvr")) { + // Initially featureCompatibilityVersion is 3.6 on primary and secondaries except for + // when we run with shardsvr. We expect featureCompatibilityVersion to be 3.4 for + // shardsvr. + checkFCV(primaryAdminDB, "3.6"); + + for (let j = 0; j < secondaries.length; j++) { + let secondaryAdminDB = secondaries[j].getDB("admin"); + checkFCV(secondaryAdminDB, "3.6"); + } + + // Ensure all collections have UUIDs in 3.6 mode on both primary and secondaries. + checkCollectionUUIDs(primaryAdminDB, false); + for (let j = 0; j < secondaries.length; j++) { + let secondaryAdminDB = secondaries[j].getDB("admin"); + checkCollectionUUIDs(secondaryAdminDB, false); + } + + // Change featureCompatibilityVersion to 3.4. + setFCV(primaryAdminDB, "3.4"); + rst.awaitReplication(); } - // Change featureCompatibilityVersion to 3.4. - setFCV(primaryAdminDB, "3.4"); - rst.awaitReplication(); + // Ensure featureCompatibilityVersion is 3.4. for (let j = 0; j < secondaries.length; j++) { let secondaryAdminDB = secondaries[j].getDB("admin"); checkFCV(secondaryAdminDB, "3.4"); @@ -163,16 +194,15 @@ } // Stop 3.6 RS - rst.stopSet(); + rst.stopSet(null /* signal */, true /* forRestart */); // 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(); + jsTest.log("Starting a binVersion 3.4 ReplSetTest to test downgrade"); + rst.startSet({restart: true, binVersion: downgrade}); // 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(); + let downgradePrimaryAdminDB = rst.getPrimary().getDB("admin"); + let downgradeSecondaries = rst.getSecondaries(); // Initially featureCompatibilityVersion document is 3.4 on primary and secondaries. checkCollectionUUIDs(downgradePrimaryAdminDB, true); @@ -185,12 +215,11 @@ checkCollectionUUIDs(secondaryAdminDB, true); } - downgradeRst.stopSet(); + rst.stopSet(null /* signal */, true /* forRestart */); - // Start 3.6 cluster again - rst = new ReplSetTest({nodes: 3, binVersion: latest}); - rst.startSet(); - rst.initiate(); + // Start 3.6 replica set again + jsTest.log("Starting a binVersion 3.6 ReplSetTest to test upgrade"); + rst.startSet({restart: true, binVersion: latest}); primaryAdminDB = rst.getPrimary().getDB("admin"); secondaries = rst.getSecondaries(); @@ -212,8 +241,18 @@ rst.stopSet(); }; - // Do tests - standaloneTest(); - replicaSetTest(); + // Do tests for regular standalones and replica sets. + standaloneTest({}); + replicaSetTest({}); + + // Do tests for standalones and replica sets started with --shardsvr. + standaloneTest({shardsvr: ""}); + replicaSetTest({shardsvr: ""}); + // Do tests for standalones and replica sets started with --configsvr. + if (jsTest.options().storageEngine !== "mmapv1") { + // We don't allow starting config servers with the MMAP storage engine. + standaloneTest({configsvr: ""}); + replicaSetTest({configsvr: ""}); + } })(); diff --git a/src/mongo/db/repl/initial_syncer.cpp b/src/mongo/db/repl/initial_syncer.cpp index f3a84eb2ad3..66f01046277 100644 --- a/src/mongo/db/repl/initial_syncer.cpp +++ b/src/mongo/db/repl/initial_syncer.cpp @@ -1098,14 +1098,13 @@ void InitialSyncer::_rollbackCheckerCheckForRollbackCallback( // Set UUIDs for all non-replicated collections on secondaries. See comment in // ReplicationCoordinatorExternalStateImpl::initializeReplSetStorage() for the explanation of // why we do this and why it is not necessary for sharded clusters. - if (serverGlobalParams.clusterRole != ClusterRole::ShardServer && - serverGlobalParams.clusterRole != ClusterRole::ConfigServer) { + if (serverGlobalParams.clusterRole != ClusterRole::ShardServer) { const NamespaceString nss("admin", "system.version"); auto opCtx = makeOpCtx(); auto statusWithUUID = _storage->getCollectionUUID(opCtx.get(), nss); if (!statusWithUUID.isOK()) { // If the admin database does not exist, we intentionally fail initial sync. As part of - // SERVER-29448, we will disallow dropping the admin database, so failing here is fine. + // SERVER-29448, we disallow dropping the admin database, so failing here is fine. onCompletionGuard->setResultAndCancelRemainingWork_inlock(lock, statusWithUUID.getStatus()); return; diff --git a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp index f9c5ce13b78..8c31e36eb8e 100644 --- a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp @@ -402,15 +402,15 @@ Status ReplicationCoordinatorExternalStateImpl::initializeReplSetStorage(Operati }); // Set UUIDs for all non-replicated collections. This is necessary for independent replica - // sets started with no data files because collections in local are created prior to the - // featureCompatibilityVersion being set to 3.6, so the collections are not created with - // UUIDs. This is not an issue for sharded clusters because the config server sends a - // setFeatureCompatibilityVersion command with the featureCompatibilityVersion equal to the - // cluster's featureCompatibilityVersion during addShard, which will add UUIDs to all - // collections that do not already have them. Here, we add UUIDs to the non-replicated - // collections on the primary. We add them on the secondaries during InitialSync. - if (serverGlobalParams.clusterRole != ClusterRole::ShardServer && - serverGlobalParams.clusterRole != ClusterRole::ConfigServer) { + // sets and config server replica sets started with no data files because collections in + // local are created prior to the featureCompatibilityVersion being set to 3.6, so the + // collections are not created with UUIDs. This is not an issue for shard servers because + // the config server sends a setFeatureCompatibilityVersion command with the + // featureCompatibilityVersion equal to the cluster's featureCompatibilityVersion during + // addShard, which will add UUIDs to all collections that do not already have them. Here, + // we add UUIDs to the non-replicated collections on the primary. We add them on the + // secondaries during InitialSync. + if (serverGlobalParams.clusterRole != ClusterRole::ShardServer) { auto schemaStatus = updateUUIDSchemaVersionNonReplicated(opCtx, true); if (!schemaStatus.isOK()) { return schemaStatus; |