summaryrefslogtreecommitdiff
path: root/jstests/multiVersion/agg_with_comment_during_upgrade.js
blob: aefccc55f41c9613e747d99d30571910348ea3e7 (plain)
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
79
80
81
82
83
84
85
86
87
// Test that aggregations with the "comment" field succeed during the upgrade, in particular when
// there are mixed version shards. When a 4.4 shard is nominated as the merger during upgrade, it
// cannot propagate the comment on getMore commands. This is because any 4.2 nodes involved in the
// query are unprepared to handle the "comment" field.
//
// This is designed as a regression test for SERVER-45002.
//
// TODO SERVER-45579: Remove this test after branching for 4.5, since this is specific to the
// 4.2/4.4 upgrade/downgrade process.
//
// Checking UUID consistency uses cached connections, which are not valid across the server restarts
// done during upgrade.
TestData.skipCheckingUUIDsConsistentAcrossCluster = true;

(function() {
"use strict";

load("jstests/multiVersion/libs/multi_cluster.js");  // For upgradeCluster().
load("jstests/multiVersion/libs/multi_rs.js");       // For upgradeSet().

// Start with a last-stable cluster with two shards.
const st = new ShardingTest({
    shards: 2,
    mongos: 1,
    rs: {nodes: 3},
    other: {
        mongosOptions: {binVersion: "last-stable"},
        configOptions: {binVersion: "last-stable"},
        rsOptions: {binVersion: "last-stable"},
    }
});

let testDb = st.s.getDB("testDb");
assert.commandWorked(testDb.source.insert({_id: -1}));
assert.commandWorked(testDb.source.insert({_id: 1}));

// Shard a collection and ensure that there are chunks on both shards.
st.ensurePrimaryShard("testDb", st.shard1.shardName);
st.shardColl("source", {_id: 1}, {_id: 0}, {_id: -1}, "testDb", true);

// Runs a $merge which will use the 4.4 node as the merger, specifying the "comment" parameter.
// Ensures that the command succeeds and that the correct results are written to the output
// collection. Cleans up afterwards by dropping the $merge destination collection.
const runAggregateWithPrimaryShardMerger = function() {
    testDb = st.s.getDB("testDb");
    assert.eq(
        0,
        testDb.source
            .aggregate(
                [
                    {$_internalInhibitOptimization: {}},
                    {
                        $merge:
                            {into: "destination", whenMatched: "replace", whenNotMatched: "insert"}
                    }
                ],
                {comment: "my comment"})
            .itcount());
    assert.eq(2, testDb.destination.find().itcount());

    assert(testDb.destination.drop());
};

runAggregateWithPrimaryShardMerger();

// Upgrade the primary shard to "latest", and verify that the agg command still works correctly.
st.rs1.upgradeSet({binVersion: "latest"});
runAggregateWithPrimaryShardMerger();

// Upgrade the other shard and repeat the test.
st.rs0.upgradeSet({binVersion: "latest"});
runAggregateWithPrimaryShardMerger();

// Upgrade the config servers and repeat the test.
st.upgradeCluster("latest", {upgradeConfigs: true, upgradeMongos: false, upgradeShards: false});
runAggregateWithPrimaryShardMerger();

// Upgrade the mongos and repeat the test.
st.upgradeCluster("latest", {upgradeConfigs: false, upgradeMongos: true, upgradeShards: false});
runAggregateWithPrimaryShardMerger();

// Set the FCV to "4.4" to complete the upgrade and repeat the test.
assert.commandWorked(st.s.getDB("admin").runCommand({setFeatureCompatibilityVersion: "4.4"}));
runAggregateWithPrimaryShardMerger();

st.stop();
})();