summaryrefslogtreecommitdiff
path: root/jstests/multiVersion/genericSetFCVUsage
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/multiVersion/genericSetFCVUsage')
-rw-r--r--jstests/multiVersion/genericSetFCVUsage/1_test_launching_replset.js55
-rw-r--r--jstests/multiVersion/genericSetFCVUsage/2_test_launching_cluster.js103
-rw-r--r--jstests/multiVersion/genericSetFCVUsage/major_version_upgrade.js2
-rw-r--r--jstests/multiVersion/genericSetFCVUsage/move_primary_setFCV.js84
-rw-r--r--jstests/multiVersion/genericSetFCVUsage/setfcv_aborts_reshard_collection.js (renamed from jstests/multiVersion/genericSetFCVUsage/setfcv_reshard_collection.js)33
5 files changed, 188 insertions, 89 deletions
diff --git a/jstests/multiVersion/genericSetFCVUsage/1_test_launching_replset.js b/jstests/multiVersion/genericSetFCVUsage/1_test_launching_replset.js
index 2d2fcbe85ae..69c110df30f 100644
--- a/jstests/multiVersion/genericSetFCVUsage/1_test_launching_replset.js
+++ b/jstests/multiVersion/genericSetFCVUsage/1_test_launching_replset.js
@@ -45,41 +45,42 @@ for (let versions of [["last-lts", "latest"], ["last-continuous", "latest"]]) {
rst.stopSet();
}
-// TODO(SERVER-61100): Re-enable this test.
-if (true) {
- jsTestLog("Skipping test as it is currently disabled.");
+if (MongoRunner.areBinVersionsTheSame("last-continuous", "last-lts")) {
+ jsTest.log("Skipping test because 'last-continuous' == 'last-lts'");
return;
}
for (let versions of [["last-lts", "last-continuous"], ["last-continuous", "last-lts"]]) {
jsTestLog("Testing mixed versions: " + tojson(versions));
- try {
- var rst = new ReplSetTest({nodes: 2});
- rst.startSet({binVersion: versions});
- rst.initiate();
- } catch (e) {
- if (e instanceof Error) {
- if (e.message.includes(
- "Can only specify one of 'last-lts' and 'last-continuous' in binVersion, not both.")) {
- continue;
- }
- }
- throw e;
- }
- assert(
- MongoRunner.areBinVersionsTheSame("last-continuous", "last-lts"),
- "Should have thrown error in creating ReplSetTest because can only specify one of 'last-lts' and 'last-continuous' in binVersion, not both.");
-
- var nodes = rst.nodes;
-
- // Make sure we have hosts of all the different versions
- var versionsFound = [];
- for (var j = 0; j < nodes.length; j++)
- versionsFound.push(nodes[j].getBinVersion());
+ var rst = new ReplSetTest({nodes: 2});
+ rst.startSet({binVersion: versions});
+ let err = assert.throws(() => rst.initiate());
+ assert(err.message.includes(
+ "Can only specify one of 'last-lts' and 'last-continuous' in binVersion, not both."),
+ err);
+ rst.stopSet();
+}
- assert.allBinVersions(versions, versionsFound);
+for (let versions of [["last-lts", "last-continuous"], ["last-continuous", "last-lts"]]) {
+ jsTestLog("Testing mixed versions: " + tojson(versions));
+ const rst = new ReplSetTest({
+ nodes: [
+ {
+ binVersion: versions[0],
+ },
+ {
+ binVersion: versions[1],
+ },
+ ]
+ });
+ rst.startSet();
+
+ let err = assert.throws(() => rst.initiate());
+ assert(err.message.includes(
+ "Can only specify one of 'last-lts' and 'last-continuous' in binVersion, not both."),
+ err);
rst.stopSet();
}
diff --git a/jstests/multiVersion/genericSetFCVUsage/2_test_launching_cluster.js b/jstests/multiVersion/genericSetFCVUsage/2_test_launching_cluster.js
index 69f228875cc..00e025e910d 100644
--- a/jstests/multiVersion/genericSetFCVUsage/2_test_launching_cluster.js
+++ b/jstests/multiVersion/genericSetFCVUsage/2_test_launching_cluster.js
@@ -8,71 +8,60 @@ load('./jstests/multiVersion/libs/verify_versions.js');
(function() {
"use strict";
-// TODO(SERVER-61100): Re-enable this test.
-if (true) {
- jsTestLog("Skipping test as it is currently disabled.");
- return;
-}
-
-// Sharded cluster upgrade order: config servers -> shards -> mongos.
-const mixedVersionsToCheck = [
- {config: ["latest"], shard: ["last-lts", "latest"], mongos: ["last-lts"]},
- {config: ["latest"], shard: ["last-continuous", "latest"], mongos: ["last-continuous"]},
- {config: ["latest"], shard: ["last-continuous", "last-lts"], mongos: ["last-continuous"]},
- {config: ["latest"], shard: ["last-lts", "last-continuous"], mongos: ["last-lts"]},
-];
-
-for (let versions of mixedVersionsToCheck) {
- jsTest.log("Testing mixed versions: " + tojson(versions));
- try {
- // Set up a multi-version cluster
- var st = new ShardingTest({
- shards: 2,
- mongos: 2,
- other: {
- mongosOptions: {binVersion: versions.mongos},
- configOptions: {binVersion: versions.config},
- shardOptions: {binVersion: versions.shard},
- enableBalancer: true
- }
- });
- } catch (e) {
- if (e instanceof Error) {
- if (e.message.includes(
- "Can only specify one of 'last-lts' and 'last-continuous' in binVersion, not both.")) {
- continue;
- }
- }
- throw e;
+function checkEquivalent(testConfig, st) {
+ var expectedVersions = [testConfig.other.mongosOptions.binVersion];
+ var expectedNodes = [...testConfig.shards.rs0.nodes, ...testConfig.shards.rs1.nodes];
+ for (j = 0; j < expectedNodes.length; j++) {
+ expectedVersions.push(expectedNodes[j].binVersion);
}
- if ((versions.shard[0] === "last-continuous" && versions.shard[1] === "last-lts") ||
- (versions.shard[1] === "last-continuous" && versions.shard[0] === "last-lts")) {
- assert(
- MongoRunner.areBinVersionsTheSame("last-continuous", "last-lts"),
- "Should have thrown error in creating ShardingTest because can only specify one of 'last-lts' and 'last-continuous' in binVersion, not both.");
+
+ var versionsFound = [st.s0.getBinVersion()];
+ var nodes = [...st._rs[0].test.nodes, ...st._rs[1].test.nodes];
+ for (var j = 0; j < nodes.length; j++) {
+ versionsFound.push(nodes[j].getBinVersion());
}
- var shards = [st.shard0, st.shard1];
- var mongoses = [st.s0, st.s1];
- var configs = [st.config0, st.config1, st.config2];
+ assert.allBinVersions(expectedVersions, versionsFound);
+}
- // Make sure we have hosts of all the different versions
- var versionsFound = [];
- for (var j = 0; j < shards.length; j++)
- versionsFound.push(shards[j].getBinVersion());
+if (MongoRunner.areBinVersionsTheSame("last-continuous", "last-lts")) {
+ jsTest.log("Skipping test because 'last-continuous' == 'last-lts'");
+ return;
+}
- assert.allBinVersions(versions.shard, versionsFound);
+const invalidMixedVersionsToCheck = [
+ {
+ shards: {
+ rs0: {nodes: [{binVersion: "last-continuous"}, {binVersion: "last-lts"}]},
+ rs1: {nodes: [{binVersion: "last-lts"}]}
+ },
+ other: {mongosOptions: {binVersion: "last-lts"}}
+ },
+];
- versionsFound = [];
- for (var j = 0; j < mongoses.length; j++)
- versionsFound.push(mongoses[j].getBinVersion());
+for (let config of invalidMixedVersionsToCheck) {
+ jsTest.log("Testing invalid mixed versions: " + tojson(config));
- assert.allBinVersions(versions.mongos, versionsFound);
+ let err = assert.throws(
+ () => new ShardingTest({shouldFailInit: true, shards: config.shards, other: config.other}));
+ assert.eq(
+ true,
+ err.message.includes(
+ "Can only specify one of 'last-lts' and 'last-continuous' in binVersion, not both."),
+ "Unexpected Error");
+}
- versionsFound = [];
- for (var j = 0; j < configs.length; j++)
- versionsFound.push(configs[j].getBinVersion());
+const validMixedVersionsToCheck = [
+ {
+ shards: {rs0: {nodes: [{binVersion: "latest"}]}, rs1: {nodes: [{binVersion: "last-lts"}]}},
+ other: {mongosOptions: {binVersion: "last-lts"}}
+ },
+];
- assert.allBinVersions(versions.config, versionsFound);
+for (let config of validMixedVersionsToCheck) {
+ jsTest.log("Testing valid mixed versions: " + tojson(config));
+ var st = new ShardingTest({shards: config.shards, other: config.other});
+ var configs = [st.config0, st.config1, st.config2];
+ checkEquivalent(config, st);
st.stop();
}
diff --git a/jstests/multiVersion/genericSetFCVUsage/major_version_upgrade.js b/jstests/multiVersion/genericSetFCVUsage/major_version_upgrade.js
index e2c9ba0feab..9b8f9978f11 100644
--- a/jstests/multiVersion/genericSetFCVUsage/major_version_upgrade.js
+++ b/jstests/multiVersion/genericSetFCVUsage/major_version_upgrade.js
@@ -8,7 +8,7 @@
* - Insert a document into the new collection.
* - Create an index on the new collection.
*
- * @tags: [requires_v4.0]
+ * @tags: [requires_v4_0]
*/
(function() {
diff --git a/jstests/multiVersion/genericSetFCVUsage/move_primary_setFCV.js b/jstests/multiVersion/genericSetFCVUsage/move_primary_setFCV.js
new file mode 100644
index 00000000000..34eea8fedb9
--- /dev/null
+++ b/jstests/multiVersion/genericSetFCVUsage/move_primary_setFCV.js
@@ -0,0 +1,84 @@
+/**
+ * Test that `movePrimary` works for databases created under a different FCV
+ */
+(function() {
+
+"use strict";
+
+let st = new ShardingTest({shards: 2, mongos: 1, rs: {nodes: 1}});
+
+const mongos = st.s;
+const kBeforeDowngradingDbName = 'createdBeforeDowngrading';
+const kBeforeUpgradingDbName = 'createdBeforeUpgrading';
+const shard0 = st.shard0.shardName;
+const shard1 = st.shard1.shardName;
+
+const createdBeforeDowngradingDB = mongos.getDB(kBeforeDowngradingDbName);
+const createdBeforeUpgradingDB = mongos.getDB(kBeforeUpgradingDbName);
+const fcvValues = [lastLTSFCV, lastContinuousFCV];
+
+function testMovePrimary(db) {
+ const dbName = db.getName();
+ // The following pipeline update modifies the config.databases entry to simulate its database
+ // version field order as having come from running {setFeatureCompatibility: "5.0"} as part of
+ // upgrading from MongoDB 4.4. See SERVER-68511 for more details of the original issue.
+ mongos.getDB('config').databases.update({_id: dbName}, [{
+ $replaceWith: {
+ $mergeObjects: [
+ "$$ROOT",
+ {
+ version: {
+ uuid: "$version.uuid",
+ lastMod: "$version.lastMod",
+ timestamp: "$version.timestamp"
+ }
+ }
+ ]
+ }
+ }]);
+
+ const currentPrimary = mongos.getDB('config').databases.findOne({_id: dbName}).primary;
+ const newPrimary = currentPrimary == shard0 ? shard1 : shard0;
+ assert.eq(db.coll.countDocuments({}), 1);
+ assert.commandWorked(mongos.adminCommand({movePrimary: dbName, to: newPrimary}));
+ assert.eq(newPrimary, mongos.getDB('config').databases.findOne({_id: dbName}).primary);
+ assert.eq(db.coll.countDocuments({}), 1);
+}
+
+for (var i = 0; i < fcvValues.length; i++) {
+ // Latest FCV
+ assert.commandWorked(mongos.adminCommand({setFeatureCompatibilityVersion: latestFCV}));
+
+ // Create database `createdBeforeDowngrading` under latest FCV
+ assert.commandWorked(
+ mongos.adminCommand({enableSharding: kBeforeDowngradingDbName, primaryShard: shard0}));
+ assert.commandWorked(createdBeforeDowngradingDB.coll.insert({_id: 'foo'}));
+
+ // Downgrade FCV
+ assert.commandWorked(mongos.adminCommand({setFeatureCompatibilityVersion: fcvValues[i]}));
+
+ // Make sure movePrimary works for `createdBeforeDowngrading`
+ testMovePrimary(createdBeforeDowngradingDB);
+
+ // Create database `createdBeforeUpgrading` under downgraded FCV
+ assert.commandWorked(mongos.adminCommand({setFeatureCompatibilityVersion: latestFCV}));
+ assert.commandWorked(
+ mongos.adminCommand({enableSharding: kBeforeUpgradingDbName, primaryShard: shard0}));
+ assert.commandWorked(createdBeforeUpgradingDB.coll.insert({_id: 'foo'}));
+
+ // Upgrade FCV
+ assert.commandWorked(mongos.adminCommand({setFeatureCompatibilityVersion: latestFCV}));
+
+ // Make sure movePrimary works (again) for `createdBeforeDowngrading`
+ testMovePrimary(createdBeforeDowngradingDB);
+
+ // Make sure movePrimary works for `createdBeforeUpgrading`
+ testMovePrimary(createdBeforeUpgradingDB);
+
+ // Drop databases for next round
+ assert.commandWorked(createdBeforeDowngradingDB.dropDatabase());
+ assert.commandWorked(createdBeforeUpgradingDB.dropDatabase());
+}
+
+st.stop();
+})();
diff --git a/jstests/multiVersion/genericSetFCVUsage/setfcv_reshard_collection.js b/jstests/multiVersion/genericSetFCVUsage/setfcv_aborts_reshard_collection.js
index 7fa818f7f99..82d7d62b8f7 100644
--- a/jstests/multiVersion/genericSetFCVUsage/setfcv_reshard_collection.js
+++ b/jstests/multiVersion/genericSetFCVUsage/setfcv_aborts_reshard_collection.js
@@ -1,6 +1,10 @@
+/**
+ * Tests that setFeatureCompatibilityVersion command aborts an ongoing reshardCollection command
+ */
(function() {
"use strict";
+load("jstests/libs/parallel_shell_helpers.js");
load("jstests/sharding/libs/resharding_test_fixture.js");
load('jstests/libs/discover_topology.js');
load('jstests/libs/fail_point_util.js');
@@ -21,6 +25,8 @@ function runTest(forcePooledConnectionsDropped) {
],
});
+ const sourceNamespace = inputCollection.getFullName();
+
let mongos = inputCollection.getMongo();
for (let x = 0; x < 1000; x++) {
@@ -37,7 +43,17 @@ function runTest(forcePooledConnectionsDropped) {
pauseBeforeCloseCxns = configureFailPoint(config, "pauseBeforeCloseCxns");
}
+ function checkCoordinatorDoc() {
+ assert.soon(() => {
+ const coordinatorDoc =
+ mongos.getCollection("config.reshardingOperations").findOne({ns: sourceNamespace});
+
+ return coordinatorDoc === null || coordinatorDoc.state === "aborting";
+ });
+ }
+
const recipientShardNames = reshardingTest.recipientShardNames;
+ let awaitShell;
reshardingTest.withReshardingInBackground(
{
newShardKeyPattern: {newKey: 1},
@@ -63,7 +79,7 @@ function runTest(forcePooledConnectionsDropped) {
assert.commandWorked(db.adminCommand({setFeatureCompatibilityVersion: lastLTSFCV}));
}`;
- let awaitShell = startParallelShell(codeToRunInParallelShell, mongos.port);
+ awaitShell = startParallelShell(codeToRunInParallelShell, mongos.port);
if (forcePooledConnectionsDropped) {
pauseBeforeCloseCxns.wait();
@@ -88,8 +104,7 @@ function runTest(forcePooledConnectionsDropped) {
jsTestLog("Turn off pause before pauseBeforeMarkKeepOpen failpoint");
pauseBeforeMarkKeepOpen.off();
}
-
- awaitShell();
+ checkCoordinatorDoc();
},
{
expectedErrorCode: [
@@ -98,6 +113,8 @@ function runTest(forcePooledConnectionsDropped) {
]
});
+ awaitShell();
+
reshardingTest.withReshardingInBackground(
{
newShardKeyPattern: {newKey: 1},
@@ -107,7 +124,14 @@ function runTest(forcePooledConnectionsDropped) {
],
},
() => {
- assert.commandWorked(mongos.adminCommand({setFeatureCompatibilityVersion: latestFCV}));
+ assert.soon(() => {
+ return mongos.getDB('config').reshardingOperations.findOne() != null;
+ }, "timed out waiting for coordinator doc to be written", 30 * 1000);
+ awaitShell = startParallelShell(funWithArgs(function(latestFCV) {
+ assert.commandWorked(db.adminCommand(
+ {setFeatureCompatibilityVersion: latestFCV}));
+ }, latestFCV), mongos.port);
+ checkCoordinatorDoc();
},
{
expectedErrorCode: [
@@ -117,6 +141,7 @@ function runTest(forcePooledConnectionsDropped) {
]
});
+ awaitShell();
reshardingTest.teardown();
}