1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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();
}());
|