diff options
-rw-r--r-- | jstests/multiVersion/set_feature_compatibility_version.js | 24 | ||||
-rw-r--r-- | src/mongo/db/commands/set_feature_compatibility_version_command.cpp | 10 |
2 files changed, 34 insertions, 0 deletions
diff --git a/jstests/multiVersion/set_feature_compatibility_version.js b/jstests/multiVersion/set_feature_compatibility_version.js index 2ee29b36404..83c88ec77f5 100644 --- a/jstests/multiVersion/set_feature_compatibility_version.js +++ b/jstests/multiVersion/set_feature_compatibility_version.js @@ -398,6 +398,30 @@ TestData.skipCheckingUUIDsConsistentAcrossCluster = true; assert.eq(res.featureCompatibilityVersion.targetVersion, null, tojson(res)); rst.stopSet(); + // Test idempotency for setFeatureCompatibilityVersion. + rst = new ReplSetTest({nodes: 2, nodeOpts: {binVersion: latest}}); + rst.startSet(); + rst.initiate(); + + // Set FCV to 3.4 so that a 3.4 node can join the set. + primary = rst.getPrimary(); + assert.commandWorked(primary.adminCommand({setFeatureCompatibilityVersion: downgrade})); + rst.awaitReplication(); + + // Add a 3.4 node to the set. + secondary = rst.add({binVersion: downgrade}); + rst.reInitiate(); + + // Ensure the 3.4 node succeeded its initial sync. + assert.writeOK(primary.getDB("test").coll.insert({awaitRepl: true}, {writeConcern: {w: 3}})); + + // Run {setFCV: "3.4"}. This should be idempotent. + assert.commandWorked(primary.adminCommand({setFeatureCompatibilityVersion: downgrade})); + rst.awaitReplication(); + + // Ensure the secondary is still running. + rst.stopSet(); + // // Sharding tests. // diff --git a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp index ba418c0aac7..69aa3289d7d 100644 --- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp +++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp @@ -123,6 +123,11 @@ public: serverGlobalParams.featureCompatibility.getVersion() != ServerGlobalParams::FeatureCompatibility::Version::kDowngradingTo34); + if (serverGlobalParams.featureCompatibility.getVersion() == + ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo36) { + return true; + } + FeatureCompatibilityVersion::setTargetUpgrade(opCtx); // First put UUIDs in the storage layer metadata. UUIDs will be generated for unsharded @@ -162,6 +167,11 @@ public: serverGlobalParams.featureCompatibility.getVersion() != ServerGlobalParams::FeatureCompatibility::Version::kUpgradingTo36); + if (serverGlobalParams.featureCompatibility.getVersion() == + ServerGlobalParams::FeatureCompatibility::Version::kFullyDowngradedTo34) { + return true; + } + FeatureCompatibilityVersion::setTargetDowngrade(opCtx); // Fail after updating the FCV document but before removing UUIDs. |