2017-10-30 15:46:36 -04:00
|
|
|
// Tests that a primary with upgrade featureCompatibilityVersion cannot connect with a secondary
|
|
|
|
|
// with a lower binary version.
|
2024-08-20 17:54:15 -04:00
|
|
|
import {ReplSetTest} from "jstests/libs/replsettest.js";
|
2017-10-30 15:46:36 -04:00
|
|
|
import {restartServerReplication, stopServerReplication} from "jstests/libs/write_concern_util.js";
|
|
|
|
|
|
|
|
|
|
const latest = "latest";
|
|
|
|
|
|
2020-07-28 13:49:54 +00:00
|
|
|
function runTest(downgradeVersion) {
|
|
|
|
|
jsTestLog("Running test with downgradeVersion: " + downgradeVersion);
|
|
|
|
|
const downgradeFCV = binVersionToFCV(downgradeVersion);
|
|
|
|
|
// Start a new replica set with two latest version nodes.
|
|
|
|
|
let rst = new ReplSetTest({
|
|
|
|
|
nodes: [{binVersion: latest}, {binVersion: latest, rsConfig: {priority: 0}}],
|
2025-08-21 10:17:44 -07:00
|
|
|
settings: {chainingAllowed: false},
|
2020-07-28 13:49:54 +00:00
|
|
|
});
|
|
|
|
|
rst.startSet();
|
2024-10-21 15:39:18 -07:00
|
|
|
rst.initiate(null, null, {initiateWithDefaultElectionTimeout: true});
|
2020-07-28 13:49:54 +00:00
|
|
|
|
|
|
|
|
let primary = rst.getPrimary();
|
|
|
|
|
let latestSecondary = rst.getSecondary();
|
|
|
|
|
|
2021-05-04 21:59:34 +00:00
|
|
|
// The default WC is majority and stopServerReplication will prevent satisfying any majority
|
|
|
|
|
// writes.
|
2025-08-21 10:17:44 -07:00
|
|
|
assert.commandWorked(
|
|
|
|
|
primary.adminCommand({setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}}),
|
|
|
|
|
);
|
2021-05-04 21:59:34 +00:00
|
|
|
|
2020-07-28 13:49:54 +00:00
|
|
|
// Set the featureCompatibilityVersion to the downgrade version so that a downgrade node can
|
|
|
|
|
// join the set.
|
2025-08-21 10:17:44 -07:00
|
|
|
assert.commandWorked(
|
|
|
|
|
primary.getDB("admin").runCommand({setFeatureCompatibilityVersion: downgradeFCV, confirm: true}),
|
|
|
|
|
);
|
2020-07-28 13:49:54 +00:00
|
|
|
|
|
|
|
|
// Add a downgrade node to the set.
|
|
|
|
|
let downgradeSecondary = rst.add({binVersion: downgradeVersion, rsConfig: {priority: 0}});
|
|
|
|
|
rst.reInitiate();
|
|
|
|
|
|
|
|
|
|
// Wait for the downgrade secondary to finish initial sync.
|
|
|
|
|
rst.awaitSecondaryNodes();
|
|
|
|
|
rst.awaitReplication();
|
2020-12-09 18:06:25 +00:00
|
|
|
rst.waitForAllNewlyAddedRemovals();
|
2020-07-28 13:49:54 +00:00
|
|
|
|
|
|
|
|
// Stop replication on the downgrade secondary.
|
|
|
|
|
stopServerReplication(downgradeSecondary);
|
|
|
|
|
|
|
|
|
|
// Set the featureCompatibilityVersion to the upgrade version. This will not replicate to
|
|
|
|
|
// the downgrade secondary, but the downgrade secondary will no longer be able to
|
|
|
|
|
// communicate with the rest of the set.
|
2025-08-21 10:17:44 -07:00
|
|
|
assert.commandWorked(primary.adminCommand({setFeatureCompatibilityVersion: latestFCV, confirm: true}));
|
2020-07-28 13:49:54 +00:00
|
|
|
|
|
|
|
|
// Shut down the latest version secondary.
|
|
|
|
|
rst.stop(latestSecondary);
|
|
|
|
|
|
|
|
|
|
// The primary should step down, since it can no longer see a majority of the replica set.
|
2024-12-05 10:46:06 -08:00
|
|
|
rst.awaitSecondaryNodes(null, [primary]);
|
2020-07-28 13:49:54 +00:00
|
|
|
|
|
|
|
|
restartServerReplication(downgradeSecondary);
|
|
|
|
|
rst.stopSet();
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-21 10:17:44 -07:00
|
|
|
runTest("last-continuous");
|
|
|
|
|
runTest("last-lts");
|