summaryrefslogtreecommitdiff
path: root/jstests/multiVersion
diff options
context:
space:
mode:
authorNicholas Zolnierz <nicholas.zolnierz@mongodb.com>2020-02-18 16:33:39 +0000
committerevergreen <evergreen@mongodb.com>2020-02-18 16:33:39 +0000
commit14240d538a74be094badf4936a56cb3232d89f1d (patch)
tree3be346db9d13eea3fa49f85abbbd59ea7f70bd7d /jstests/multiVersion
parenteb284b042c71edf0eac445d3ceb79f7fdeabc5d1 (diff)
downloadmongo-14240d538a74be094badf4936a56cb3232d89f1d.tar.gz
SERVER-45540 Gate $unionWith behind FCV check and test upgrade/downgrade
Diffstat (limited to 'jstests/multiVersion')
-rw-r--r--jstests/multiVersion/genericSetFCVUsage/view_definition_feature_compatibility_version.js6
-rw-r--r--jstests/multiVersion/unionWith_fcv.js78
2 files changed, 83 insertions, 1 deletions
diff --git a/jstests/multiVersion/genericSetFCVUsage/view_definition_feature_compatibility_version.js b/jstests/multiVersion/genericSetFCVUsage/view_definition_feature_compatibility_version.js
index d7e6ce36bfc..2a575367b64 100644
--- a/jstests/multiVersion/genericSetFCVUsage/view_definition_feature_compatibility_version.js
+++ b/jstests/multiVersion/genericSetFCVUsage/view_definition_feature_compatibility_version.js
@@ -36,6 +36,10 @@ const pipelinesWithNewFeatures = [
[{$project: {x: {$replaceAll: {input: '', find: '', replacement: ''}}}}],
[{$project: {x: {$first: {$literal: ['a']}}}}],
[{$project: {x: {$last: {$literal: ['a']}}}}],
+ [{$unionWith: "A"}],
+ [{$unionWith: {coll: "A", pipeline: [{$match: {b: 1}}]}}],
+ [{$lookup: {from: "A", pipeline: [{$unionWith: "B"}], as: "result"}}],
+ [{$facet: {sub_pipe_invalid: [{$unionWith: "B"}], sub_pipe_valid: [{$match: {b: 1}}]}}],
];
let conn = MongoRunner.runMongod({dbpath: dbpath, binVersion: "latest"});
@@ -55,7 +59,7 @@ pipelinesWithNewFeatures.forEach(
`Expected to be able to create view with pipeline ${tojson(pipe)} while in FCV` +
` ${latestFCV}`));
-// Test that we are able to create a new view with any of the new features.
+// Test that we are able to update an existing view with any of the new features.
pipelinesWithNewFeatures.forEach(function(pipe, i) {
assert(testDB["firstView" + i].drop(), `Drop of view with pipeline ${tojson(pipe)} failed`);
assert.commandWorked(testDB.createView("firstView" + i, "coll", []));
diff --git a/jstests/multiVersion/unionWith_fcv.js b/jstests/multiVersion/unionWith_fcv.js
new file mode 100644
index 00000000000..35b9a3c15f2
--- /dev/null
+++ b/jstests/multiVersion/unionWith_fcv.js
@@ -0,0 +1,78 @@
+/**
+ * Test the behavior of the $unionWith aggregation stage against a standalone/sharded cluster during
+ * upgrade.
+ *
+ * Checking UUID consistency uses cached connections, which are not valid across restarts or
+ * stepdowns.
+ */
+TestData.skipCheckingUUIDsConsistentAcrossCluster = true;
+
+(function() {
+"use strict";
+
+load("jstests/multiVersion/libs/multi_cluster.js"); // For upgradeCluster.
+
+let conn = MongoRunner.runMongod({binVersion: "latest"});
+assert.neq(null, conn, "mongod was unable to start up");
+let testDB = conn.getDB(jsTestName());
+
+// Set the feature compatibility version to the last-stable version.
+assert.commandWorked(testDB.adminCommand({setFeatureCompatibilityVersion: lastStableFCV}));
+
+// Seed the two involved collections.
+assert.commandWorked(testDB.collA.insert({fromA: 1}));
+assert.commandWorked(testDB.collB.insert({fromB: 1}));
+
+// Verify that we can still use $unionWith since the binary version is 4.4.
+const pipeline = [{$unionWith: "collB"}, {$project: {_id: 0}}];
+assert.sameMembers([{fromA: 1}, {fromB: 1}], testDB.collA.aggregate(pipeline).toArray());
+
+// Set the feature compatibility version to the latest version.
+assert.commandWorked(testDB.adminCommand({setFeatureCompatibilityVersion: latestFCV}));
+
+// Verify that we can still use $unionWith.
+assert.sameMembers([{fromA: 1}, {fromB: 1}], testDB.collA.aggregate(pipeline).toArray());
+
+MongoRunner.stopMongod(conn);
+
+// Start a sharded cluster in which all mongod and mongos processes are "last-stable" binVersion.
+let st = new ShardingTest({
+ shards: 2,
+ rs: {nodes: 2, binVersion: "last-stable"},
+ other: {mongosOptions: {binVersion: "last-stable"}}
+});
+
+testDB = st.s.getDB(jsTestName());
+assert.commandWorked(testDB.runCommand({create: "collA"}));
+st.ensurePrimaryShard(testDB.getName(), st.shard0.shardName);
+
+// Seed the two involved collections.
+assert.commandWorked(testDB.collA.insert({fromA: 1}));
+assert.commandWorked(testDB.collB.insert({fromB: 1}));
+
+// Aggregations with $unionWith should fail against older binary versions.
+assert.commandFailedWithCode(
+ testDB.runCommand({aggregate: "collA", pipeline: pipeline, cursor: {}}), 40324);
+
+// Upgrade the config servers and the shards to the "latest" binVersion.
+st.upgradeCluster("latest", {upgradeShards: true, upgradeConfigs: true, upgradeMongos: false});
+
+// Since mongos is still on 4.2, $unionWith should fail to parse.
+assert.commandFailedWithCode(
+ testDB.runCommand({aggregate: "collA", pipeline: pipeline, cursor: {}}), 40324);
+
+// Upgrade mongos to the "latest" binVersion but keep the old FCV.
+st.upgradeCluster("latest", {upgradeShards: false, upgradeConfigs: false, upgradeMongos: true});
+testDB = st.s.getDB(jsTestName());
+
+// Now an aggregation containing $unionWith should pass because all nodes are on binary version 4.4.
+assert.sameMembers([{fromA: 1}, {fromB: 1}], testDB.collA.aggregate(pipeline).toArray());
+
+// For completeness, set the FCV to the latest.
+assert.commandWorked(testDB.adminCommand({setFeatureCompatibilityVersion: latestFCV}));
+
+// Verify that $unionWith is allowed in a fully upgraded cluster.
+assert.sameMembers([{fromA: 1}, {fromB: 1}], testDB.collA.aggregate(pipeline).toArray());
+
+st.stop();
+}());