summaryrefslogtreecommitdiff
path: root/jstests/hooks/run_validate_collections.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/hooks/run_validate_collections.js')
-rw-r--r--jstests/hooks/run_validate_collections.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/jstests/hooks/run_validate_collections.js b/jstests/hooks/run_validate_collections.js
index 525003148e1..e0292740b97 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,6 +32,8 @@
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));
}
@@ -44,6 +49,18 @@
conn.setSlaveOk();
jsTest.authenticate(conn);
+ if (jsTest.options().forceValidationWithFeatureCompatibilityVersion) {
+ let adminDB = conn.getDB('admin');
+ // Make sure this node has the desired FCV.
+ assert.soon(() => {
+ const res =
+ adminDB.system.version.findOne({_id: "featureCompatibilityVersion"});
+ return res !== null &&
+ res.version ===
+ jsTest.options().forceValidationWithFeatureCompatibilityVersion;
+ });
+ }
+
const dbNames = conn.getDBNames();
for (let dbName of dbNames) {
if (!validateCollections(conn.getDB(dbName), {full: true})) {
@@ -61,6 +78,43 @@
// 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;
+
+ function getFeatureCompatibilityVersion(adminDB) {
+ const res = adminDB.system.version.findOne({_id: "featureCompatibilityVersion"});
+ if (res === null) {
+ return "3.2";
+ }
+ return res.version;
+ }
+
+ if (jsTest.options().forceValidationWithFeatureCompatibilityVersion) {
+ let conn = new Mongo(setFCVHost);
+ adminDB = conn.getDB('admin');
+ try {
+ originalFCV = getFeatureCompatibilityVersion(adminDB);
+ } catch (e) {
+ if (jsTest.options().skipValidationOnInvalidViewDefinitions &&
+ e.code === ErrorCodes.InvalidViewDefinition) {
+ print("Reading the featureCompatibilityVersion from the admin.system.version" +
+ " collection failed due to an invalid view definition on the admin database");
+ // The view catalog would only have been resolved if the namespace doesn't exist as
+ // a collection. The absence of the admin.system.version collection is equivalent to
+ // having featureCompatibilityVersion=3.2.
+ originalFCV = "3.2";
+ } else {
+ throw e;
+ }
+ }
+
+ if (originalFCV !== jsTest.options().forceValidationWithFeatureCompatibilityVersion) {
+ assert.commandWorked(adminDB.adminCommand({
+ setFeatureCompatibilityVersion:
+ jsTest.options().forceValidationWithFeatureCompatibilityVersion
+ }));
+ }
+ }
try {
hostList.forEach(host => {
@@ -79,4 +133,8 @@
assert.commandWorked(res, 'Collection validation failed');
});
}
+
+ if (jsTest.options().forceValidationWithFeatureCompatibilityVersion !== originalFCV) {
+ assert.commandWorked(adminDB.runCommand({setFeatureCompatibilityVersion: originalFCV}));
+ }
})();