diff options
-rw-r--r-- | jstests/hooks/run_validate_collections.js | 51 | ||||
-rw-r--r-- | jstests/hooks/validate_collections.js | 29 | ||||
-rw-r--r-- | jstests/noPassthrough/validate_hook_resume_fcv_upgrade.js | 18 |
3 files changed, 63 insertions, 35 deletions
diff --git a/jstests/hooks/run_validate_collections.js b/jstests/hooks/run_validate_collections.js index eeabba7e10e..029e501cab5 100644 --- a/jstests/hooks/run_validate_collections.js +++ b/jstests/hooks/run_validate_collections.js @@ -10,14 +10,11 @@ assert.eq(typeof db, 'object', 'Invalid `db` object, is the shell connected to a 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); @@ -32,11 +29,53 @@ if (topology.type === Topology.kStandalone) { 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, setFCVHost); +const adminDB = db.getSiblingDB('admin'); +const requiredFCV = jsTest.options().forceValidationWithFeatureCompatibilityVersion; + +let originalFCV; +let originalTransactionLifetimeLimitSeconds; + +if (requiredFCV) { + // Running the setFeatureCompatibilityVersion command may implicitly involve running a + // multi-statement transaction. We temporarily raise the transactionLifetimeLimitSeconds to be + // 24 hours to avoid spurious failures from it having been set to a lower value. + originalTransactionLifetimeLimitSeconds = hostList.map(hostStr => { + const conn = new Mongo(hostStr); + const res = assert.commandWorked( + conn.adminCommand({setParameter: 1, transactionLifetimeLimitSeconds: 24 * 60 * 60})); + return {conn, originalValue: res.was}; + }); + + originalFCV = adminDB.system.version.findOne({_id: 'featureCompatibilityVersion'}); + + if (originalFCV.targetVersion) { + // If a previous FCV upgrade or downgrade was interrupted, then we run the + // setFeatureCompatibilityVersion command to complete it before attempting to set the + // feature compatibility version to 'requiredFCV'. + assert.commandWorked( + adminDB.runCommand({setFeatureCompatibilityVersion: originalFCV.targetVersion})); + checkFCV(adminDB, originalFCV.targetVersion); + } + + // Now that we are certain that an upgrade or downgrade of the FCV is not in progress, ensure + // the 'requiredFCV' is set. + assert.commandWorked(adminDB.runCommand({setFeatureCompatibilityVersion: requiredFCV})); +} + +new CollectionValidator().validateNodes(hostList); + +if (originalFCV && originalFCV.version !== requiredFCV) { + assert.commandWorked(adminDB.runCommand({setFeatureCompatibilityVersion: originalFCV.version})); +} + +if (originalTransactionLifetimeLimitSeconds) { + for (let {conn, originalValue} of originalTransactionLifetimeLimitSeconds) { + assert.commandWorked( + conn.adminCommand({setParameter: 1, transactionLifetimeLimitSeconds: originalValue})); + } +} })(); diff --git a/jstests/hooks/validate_collections.js b/jstests/hooks/validate_collections.js index 58e1c5bb276..cf7f1be9707 100644 --- a/jstests/hooks/validate_collections.js +++ b/jstests/hooks/validate_collections.js @@ -122,32 +122,10 @@ function CollectionValidator() { } }; - this.validateNodes = function(hostList, setFCVHost) { + this.validateNodes = function(hostList) { // 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; - - const requiredFCV = jsTest.options().forceValidationWithFeatureCompatibilityVersion; - if (requiredFCV) { - let conn = new Mongo(setFCVHost); - adminDB = conn.getDB('admin'); - originalFCV = adminDB.system.version.findOne({_id: 'featureCompatibilityVersion'}); - - if (originalFCV.targetVersion) { - // If a previous FCV upgrade or downgrade was interrupted, then we run the - // setFeatureCompatibilityVersion command to complete it before attempting to set - // the feature compatibility version to 'requiredFCV'. - assert.commandWorked(adminDB.runCommand( - {setFeatureCompatibilityVersion: originalFCV.targetVersion})); - checkFCV(adminDB, originalFCV.targetVersion); - } - - // Now that we are certain that an upgrade or downgrade of the FCV is not in progress, - // ensure the 'requiredFCV' is set. - assert.commandWorked(adminDB.runCommand({setFeatureCompatibilityVersion: requiredFCV})); - } try { hostList.forEach(host => { @@ -167,11 +145,6 @@ function CollectionValidator() { assert.commandWorked(res, 'Collection validation failed'); }); } - - if (originalFCV && originalFCV.version !== requiredFCV) { - assert.commandWorked( - adminDB.runCommand({setFeatureCompatibilityVersion: originalFCV.version})); - } }; } diff --git a/jstests/noPassthrough/validate_hook_resume_fcv_upgrade.js b/jstests/noPassthrough/validate_hook_resume_fcv_upgrade.js index 3da0114f73c..e13d3ef5886 100644 --- a/jstests/noPassthrough/validate_hook_resume_fcv_upgrade.js +++ b/jstests/noPassthrough/validate_hook_resume_fcv_upgrade.js @@ -42,6 +42,17 @@ function makePatternForSetFCV(targetVersion) { "g"); } +function makePatternForSetParameter(paramName) { + if (isJsonLogNoConn()) { + return new RegExp( + `slow query.*"appName":"MongoDB Shell","command":{"setParameter":1\\.0,"${paramName}":`, + "g"); + } + return new RegExp("COMMAND.*command.*appName: \"MongoDB Shell\" command: setParameter" + + " { setParameter: 1\\.0, " + paramName + ":", + "g"); +} + function countMatches(pattern, output) { assert(pattern.global, "the 'g' flag must be used to find all matches"); @@ -95,7 +106,7 @@ function testStandalone(additionalSetupFn, { } }); - const pattern = makePatternForValidate("test", "mycoll"); + let pattern = makePatternForValidate("test", "mycoll"); assert.eq(1, countMatches(pattern, output), "expected to find " + tojson(pattern) + " from mongod in the log output"); @@ -111,6 +122,11 @@ function testStandalone(additionalSetupFn, { countMatches(pattern, output), "expected to find " + tojson(pattern) + " from mongod in the log output"); } + + pattern = makePatternForSetParameter("transactionLifetimeLimitSeconds"); + assert.eq(2, + countMatches(pattern, output), + "expected to find " + tojson(pattern) + " from mongod in the log output twice"); } function forceInterruptedUpgradeOrDowngrade(conn, targetVersion) { |