2014-11-07 10:48:38 -08:00
|
|
|
// Test the downgrade of a replica set from latest version
|
2015-04-08 06:35:11 -04:00
|
|
|
// to last-stable version succeeds, while reads and writes continue.
|
2014-11-07 10:48:38 -08:00
|
|
|
|
2016-02-04 12:29:45 -05:00
|
|
|
load('./jstests/multiVersion/libs/multi_rs.js');
|
|
|
|
|
load('./jstests/libs/test_background_ops.js');
|
2018-01-29 11:02:11 -05:00
|
|
|
load('./jstests/libs/feature_compatibility_version.js');
|
2014-11-07 10:48:38 -08:00
|
|
|
|
2018-01-29 11:02:11 -05:00
|
|
|
let newVersion = "latest";
|
|
|
|
|
let oldVersion = "last-stable";
|
2014-11-07 10:48:38 -08:00
|
|
|
|
2018-01-29 11:02:11 -05:00
|
|
|
let name = "replsetdowngrade";
|
|
|
|
|
let nodes = {
|
2016-03-09 12:17:50 -05:00
|
|
|
n1: {binVersion: newVersion},
|
|
|
|
|
n2: {binVersion: newVersion},
|
|
|
|
|
n3: {binVersion: newVersion}
|
|
|
|
|
};
|
2014-11-07 10:48:38 -08:00
|
|
|
|
2018-03-13 15:38:09 -04:00
|
|
|
function runDowngradeTest() {
|
2018-01-29 11:02:11 -05:00
|
|
|
let rst = new ReplSetTest({name: name, nodes: nodes, waitForKeys: true});
|
2017-04-20 15:28:38 -04:00
|
|
|
rst.startSet();
|
2018-03-13 15:38:09 -04:00
|
|
|
rst.initiate();
|
2017-04-20 15:28:38 -04:00
|
|
|
|
2018-01-29 11:02:11 -05:00
|
|
|
let primary = rst.getPrimary();
|
|
|
|
|
let coll = "test.foo";
|
2017-04-20 15:28:38 -04:00
|
|
|
|
2018-02-08 18:15:57 -05:00
|
|
|
// The default FCV is latestFCV for non-shard replica sets.
|
|
|
|
|
let primaryAdminDB = rst.getPrimary().getDB("admin");
|
|
|
|
|
checkFCV(primaryAdminDB, latestFCV);
|
2018-01-29 11:02:11 -05:00
|
|
|
|
|
|
|
|
// We wait for the feature compatibility version to be set to lastStableFCV on all nodes of the
|
|
|
|
|
// replica set in order to ensure that all nodes can be successfully downgraded. This
|
|
|
|
|
// effectively allows us to emulate upgrading to the latest version with existing data files and
|
|
|
|
|
// then trying to downgrade back to lastStableFCV.
|
|
|
|
|
assert.commandWorked(primary.adminCommand({setFeatureCompatibilityVersion: lastStableFCV}));
|
2017-06-02 15:29:32 -04:00
|
|
|
rst.awaitReplication();
|
|
|
|
|
|
2017-04-20 15:28:38 -04:00
|
|
|
jsTest.log("Inserting documents into collection.");
|
2018-01-29 11:02:11 -05:00
|
|
|
for (let i = 0; i < 10; i++) {
|
2017-04-20 15:28:38 -04:00
|
|
|
primary.getCollection(coll).insert({_id: i, str: "hello world"});
|
|
|
|
|
}
|
2014-11-07 10:48:38 -08:00
|
|
|
|
2018-01-29 11:02:11 -05:00
|
|
|
function insertDocuments(rsURL, collParam) {
|
|
|
|
|
let coll = new Mongo(rsURL).getCollection(collParam);
|
|
|
|
|
let count = 10;
|
2017-04-20 15:28:38 -04:00
|
|
|
while (!isFinished()) {
|
|
|
|
|
assert.writeOK(coll.insert({_id: count, str: "hello world"}));
|
|
|
|
|
count++;
|
|
|
|
|
}
|
2014-11-07 10:48:38 -08:00
|
|
|
}
|
|
|
|
|
|
2017-04-20 15:28:38 -04:00
|
|
|
jsTest.log("Starting parallel operations during downgrade..");
|
2018-01-29 11:02:11 -05:00
|
|
|
let joinFindInsert = startParallelOps(primary, insertDocuments, [rst.getURL(), coll]);
|
2014-11-07 10:48:38 -08:00
|
|
|
|
2017-04-20 15:28:38 -04:00
|
|
|
jsTest.log("Downgrading replica set..");
|
|
|
|
|
rst.upgradeSet({binVersion: oldVersion});
|
|
|
|
|
jsTest.log("Downgrade complete.");
|
2017-03-23 01:25:09 -04:00
|
|
|
|
2017-09-20 14:15:00 -04:00
|
|
|
// We save a reference to the old primary so that we can call reconnect() on it before
|
|
|
|
|
// joinFindInsert() would attempt to send the node an update operation that signals the parallel
|
|
|
|
|
// shell running the background operations to stop.
|
2018-01-29 11:02:11 -05:00
|
|
|
let oldPrimary = primary;
|
2017-09-20 14:15:00 -04:00
|
|
|
|
2017-04-20 15:28:38 -04:00
|
|
|
primary = rst.getPrimary();
|
|
|
|
|
printjson(rst.status());
|
|
|
|
|
|
2017-09-20 14:15:00 -04:00
|
|
|
// Since the old primary was restarted as part of the downgrade process, we explicitly reconnect
|
|
|
|
|
// to it so that sending it an update operation silently fails with an unchecked NotMaster error
|
|
|
|
|
// rather than a network error.
|
|
|
|
|
reconnect(oldPrimary.getDB("admin"));
|
2017-04-20 15:28:38 -04:00
|
|
|
joinFindInsert();
|
|
|
|
|
rst.stopSet();
|
|
|
|
|
}
|
2014-11-07 10:48:38 -08:00
|
|
|
|
2018-03-13 15:38:09 -04:00
|
|
|
runDowngradeTest();
|