diff options
author | Xiangyu Yao <xiangyu.yao@mongodb.com> | 2018-08-23 15:54:59 -0400 |
---|---|---|
committer | Xiangyu Yao <xiangyu.yao@mongodb.com> | 2018-08-27 18:44:05 -0400 |
commit | bdb7951bc48accda8368f5893bdf2627fc2588bf (patch) | |
tree | eefb70e0f1a89ddf85dc992c8b5c987fc2587d66 /jstests | |
parent | 4d124b7f3634da1fc5230bf18662a1004054a8ff (diff) | |
download | mongo-bdb7951bc48accda8368f5893bdf2627fc2588bf.tar.gz |
SERVER-36718 Add forceValidationWithFeatureCompatibilityVersion to collection validation hook
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/hooks/run_validate_collections.js | 7 | ||||
-rw-r--r-- | jstests/hooks/validate_collections.js | 35 | ||||
-rw-r--r-- | jstests/libs/discover_topology.js | 16 |
3 files changed, 51 insertions, 7 deletions
diff --git a/jstests/hooks/run_validate_collections.js b/jstests/hooks/run_validate_collections.js index 6f9b9be0581..171e3cd7c00 100644 --- a/jstests/hooks/run_validate_collections.js +++ b/jstests/hooks/run_validate_collections.js @@ -10,11 +10,14 @@ const topology = DiscoverTopology.findConnectedNodes(db.getMongo()); const hostList = []; + let setFCVHost; if (topology.type === Topology.kStandalone) { hostList.push(topology.mongod); + setFCVHost = topology.mongod; } else if (topology.type === Topology.kReplicaSet) { hostList.push(...topology.nodes); + setFCVHost = topology.primary; } else if (topology.type === Topology.kShardedCluster) { hostList.push(...topology.configsvr.nodes); @@ -29,10 +32,12 @@ throw new Error('Unrecognized topology format: ' + tojson(topology)); } } + // Any of the mongos instances can be used for setting FCV. + setFCVHost = topology.mongos.nodes[0]; } else { throw new Error('Unrecognized topology format: ' + tojson(topology)); } - new CollectionValidator().validateNodes(hostList); + new CollectionValidator().validateNodes(hostList, setFCVHost); })(); diff --git a/jstests/hooks/validate_collections.js b/jstests/hooks/validate_collections.js index fc1ffed3ea1..dec184ce78d 100644 --- a/jstests/hooks/validate_collections.js +++ b/jstests/hooks/validate_collections.js @@ -30,7 +30,7 @@ function CollectionValidator() { let full_res = {ok: 1, failed_res: []}; // Don't run validate on view namespaces. - let filter = {type: "collection"}; + let filter = {type: 'collection'}; if (jsTest.options().skipValidationOnInvalidViewDefinitions) { // If skipValidationOnInvalidViewDefinitions=true, then we avoid resolving the view // catalog on the admin database. @@ -57,7 +57,7 @@ function CollectionValidator() { let collInfo = db.getCollectionInfos(filter); for (let collDocument of collInfo) { - const coll = db.getCollection(collDocument["name"]); + const coll = db.getCollection(collDocument['name']); const res = coll.validate(full); if (!res.ok || !res.valid) { @@ -93,6 +93,16 @@ function CollectionValidator() { conn.setSlaveOk(); jsTest.authenticate(conn); + if (jsTest.options().forceValidationWithFeatureCompatibilityVersion) { + let adminDB = conn.getDB('admin'); + // Make sure this node has the desired FCV. + assert.soon(() => { + return adminDB.system.version.findOne({_id: 'featureCompatibilityVersion'}) + .version === + jsTest.options().forceValidationWithFeatureCompatibilityVersion; + }); + } + const dbNames = conn.getDBNames(); for (let dbName of dbNames) { if (!validatorFunc(conn.getDB(dbName), {full: true})) { @@ -107,10 +117,25 @@ function CollectionValidator() { } }; - this.validateNodes = function(hostList) { + this.validateNodes = function(hostList, setFCVHost) { // We run the scoped threads in a try/finally block in case any thread throws an exception, // in which case we want to still join all the threads. let threads = []; + let adminDB; + let originalFCV; + + if (jsTest.options().forceValidationWithFeatureCompatibilityVersion) { + let conn = new Mongo(setFCVHost); + adminDB = conn.getDB('admin'); + originalFCV = + adminDB.system.version.findOne({_id: 'featureCompatibilityVersion'}).version; + if (originalFCV !== jsTest.options().forceValidationWithFeatureCompatibilityVersion) { + assert.commandWorked(adminDB.adminCommand({ + setFeatureCompatibilityVersion: + jsTest.options().forceValidationWithFeatureCompatibilityVersion + })); + } + } try { hostList.forEach(host => { @@ -130,6 +155,10 @@ function CollectionValidator() { assert.commandWorked(res, 'Collection validation failed'); }); } + + if (jsTest.options().forceValidationWithFeatureCompatibilityVersion !== originalFCV) { + assert.commandWorked(adminDB.runCommand({setFeatureCompatibilityVersion: originalFCV})); + } }; } diff --git a/jstests/libs/discover_topology.js b/jstests/libs/discover_topology.js index f005053790b..7bd104ce65e 100644 --- a/jstests/libs/discover_topology.js +++ b/jstests/libs/discover_topology.js @@ -23,7 +23,11 @@ var DiscoverTopology = (function() { // The "passives" field contains the list of unelectable (priority=0) secondaries // and is omitted from the server's response when there are none. res.passives = res.passives || []; - return {type: Topology.kReplicaSet, nodes: [...res.hosts, ...res.passives]}; + return { + type: Topology.kReplicaSet, + primary: res.primary, + nodes: [...res.hosts, ...res.passives] + }; } function findConnectedNodesViaMongos(conn, options) { @@ -87,7 +91,11 @@ var DiscoverTopology = (function() { * is returned. * * For a replica set, an object of the form - * {type: Topology.kReplicaSet, nodes: [<conn-string1>, <conn-string2>, ...]} + * { + * type: Topology.kReplicaSet, + * primary: <primary-conn-string>, + * nodes: [<conn-string1>, <conn-string2>, ...], + * } * is returned. * * For a sharded cluster, an object of the form @@ -96,7 +104,9 @@ var DiscoverTopology = (function() { * configsvr: {nodes: [...]}, * shards: { * <shard-name1>: {type: Topology.kStandalone, mongod: ...}, - * <shard-name2>: {type: Topology.kReplicaSet, nodes: [...]}, + * <shard-name2>: {type: Topology.kReplicaSet, + * primary: <primary-conn-string>, + * nodes: [...]}, * ... * }, * mongos: { |