summaryrefslogtreecommitdiff
path: root/jstests/hooks
diff options
context:
space:
mode:
authorXiangyu Yao <xiangyu.yao@mongodb.com>2018-08-23 15:54:59 -0400
committerXiangyu Yao <xiangyu.yao@mongodb.com>2018-08-27 18:44:05 -0400
commitbdb7951bc48accda8368f5893bdf2627fc2588bf (patch)
treeeefb70e0f1a89ddf85dc992c8b5c987fc2587d66 /jstests/hooks
parent4d124b7f3634da1fc5230bf18662a1004054a8ff (diff)
downloadmongo-bdb7951bc48accda8368f5893bdf2627fc2588bf.tar.gz
SERVER-36718 Add forceValidationWithFeatureCompatibilityVersion to collection validation hook
Diffstat (limited to 'jstests/hooks')
-rw-r--r--jstests/hooks/run_validate_collections.js7
-rw-r--r--jstests/hooks/validate_collections.js35
2 files changed, 38 insertions, 4 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}));
+ }
};
}