summaryrefslogtreecommitdiff
path: root/jstests/multiVersion/upgrade_downgrade_cluster.js
blob: f699d3df981576548c2df32c8b7c0cd9b3a7dddf (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/**
 * Tests that CRUD and aggregation commands through the mongos continue to work as expected on both
 * sharded and unsharded collection at each step of cluster upgrade from last-stable to latest.
 */
(function() {
"use strict";

load('./jstests/multiVersion/libs/multi_rs.js');
load('./jstests/multiVersion/libs/multi_cluster.js');

// When checking UUID consistency, the shell attempts to run a command on the node it believes is
// primary in each shard. However, this test restarts shards, and the node that is elected primary
// after the restart may be different from the original primary. Since the shell does not retry on
// NotMaster errors, and whether or not it detects the new primary before issuing the command is
// nondeterministic, skip the consistency check for this test.
TestData.skipCheckingUUIDsConsistentAcrossCluster = true;

const kMinVersion = 5;
const kCurrentVerion = 6;

var testCRUDAndAgg = function(db) {
    assert.commandWorked(db.foo.insert({x: 1}));
    assert.commandWorked(db.foo.insert({x: -1}));
    assert.commandWorked(db.foo.update({x: 1}, {$set: {y: 1}}));
    assert.commandWorked(db.foo.update({x: -1}, {$set: {y: 1}}));
    var doc1 = db.foo.findOne({x: 1});
    assert.eq(1, doc1.y);
    var doc2 = db.foo.findOne({x: -1});
    assert.eq(1, doc2.y);

    assert.commandWorked(db.foo.remove({x: 1}, true));
    assert.commandWorked(db.foo.remove({x: -1}, true));
    assert.eq(null, db.foo.findOne());
};

var st = new ShardingTest({
    shards: 2,
    mongos: 1,
    other: {
        mongosOptions: {binVersion: "last-stable"},
        configOptions: {binVersion: "last-stable"},
        shardOptions: {binVersion: "last-stable"},

        rsOptions: {binVersion: "last-stable"},
        rs: true,
    }
});
st.configRS.awaitReplication();

// check that config.version document gets initialized properly
var version = st.s.getCollection('config.version').findOne();
assert.eq(version.minCompatibleVersion, kMinVersion);
assert.eq(version.currentVersion, kCurrentVerion);
var clusterID = version.clusterId;
assert.neq(null, clusterID);
assert.eq(version.excluding, undefined);

// Setup sharded collection
assert.commandWorked(st.s.adminCommand({enableSharding: 'sharded'}));
st.ensurePrimaryShard('sharded', st.shard0.shardName);

assert.commandWorked(st.s.adminCommand({shardCollection: 'sharded.foo', key: {x: 1}}));
assert.commandWorked(st.s.adminCommand({split: 'sharded.foo', middle: {x: 0}}));
assert.commandWorked(
    st.s.adminCommand({moveChunk: 'sharded.foo', find: {x: 1}, to: st.shard1.shardName}));

testCRUDAndAgg(st.s.getDB('unsharded'));
testCRUDAndAgg(st.s.getDB('sharded'));

// upgrade the config servers first
jsTest.log('upgrading config servers');
st.upgradeCluster("latest", {upgradeMongos: false, upgradeShards: false});

testCRUDAndAgg(st.s.getDB('unsharded'));
testCRUDAndAgg(st.s.getDB('sharded'));

// Restart mongos to clear all cache and force it to do remote calls.
st.restartMongoses();

testCRUDAndAgg(st.s.getDB('unsharded'));
testCRUDAndAgg(st.s.getDB('sharded'));

// Then upgrade the shards.
jsTest.log('upgrading shard servers');
st.upgradeCluster("latest", {upgradeMongos: false, upgradeConfigs: false});

awaitRSClientHosts(st.s, st.rs0.getPrimary(), {ok: true, ismaster: true});
awaitRSClientHosts(st.s, st.rs1.getPrimary(), {ok: true, ismaster: true});

testCRUDAndAgg(st.s.getDB('unsharded'));
testCRUDAndAgg(st.s.getDB('sharded'));

// Restart mongos to clear all cache and force it to do remote calls.
st.restartMongoses();

testCRUDAndAgg(st.s.getDB('unsharded'));
testCRUDAndAgg(st.s.getDB('sharded'));

// Finally, upgrade mongos
jsTest.log('upgrading mongos servers');
st.upgradeCluster("latest", {upgradeConfigs: false, upgradeShards: false});

testCRUDAndAgg(st.s.getDB('unsharded'));
testCRUDAndAgg(st.s.getDB('sharded'));

// Restart mongos to clear all cache and force it to do remote calls.
st.restartMongoses();

testCRUDAndAgg(st.s.getDB('unsharded'));
testCRUDAndAgg(st.s.getDB('sharded'));

// Check that version document is unmodified.
version = st.s.getCollection('config.version').findOne();
assert.eq(version.minCompatibleVersion, kMinVersion);
assert.eq(version.currentVersion, kCurrentVerion);
assert.eq(clusterID, version.clusterId);
assert.eq(version.excluding, undefined);

///////////////////////////////////////////////////////////////////////////////////////////
// Downgrade back

jsTest.log('downgrading mongos servers');
st.upgradeCluster("last-stable", {upgradeConfigs: false, upgradeShards: false});

testCRUDAndAgg(st.s.getDB('unsharded'));
testCRUDAndAgg(st.s.getDB('sharded'));

// Restart mongos to clear all cache and force it to do remote calls.
st.restartMongoses();

testCRUDAndAgg(st.s.getDB('unsharded'));
testCRUDAndAgg(st.s.getDB('sharded'));

jsTest.log('downgrading shard servers');
st.upgradeCluster("last-stable", {upgradeMongos: false, upgradeConfigs: false});

awaitRSClientHosts(st.s, st.rs0.getPrimary(), {ok: true, ismaster: true});
awaitRSClientHosts(st.s, st.rs1.getPrimary(), {ok: true, ismaster: true});

testCRUDAndAgg(st.s.getDB('unsharded'));
testCRUDAndAgg(st.s.getDB('sharded'));

// Restart mongos to clear all cache and force it to do remote calls.
st.restartMongoses();

testCRUDAndAgg(st.s.getDB('unsharded'));
testCRUDAndAgg(st.s.getDB('sharded'));

jsTest.log('downgrading config servers');
st.upgradeCluster("last-stable", {upgradeMongos: false, upgradeShards: false});

testCRUDAndAgg(st.s.getDB('unsharded'));
testCRUDAndAgg(st.s.getDB('sharded'));

// Restart mongos to clear all cache and force it to do remote calls.
st.restartMongoses();

testCRUDAndAgg(st.s.getDB('unsharded'));
testCRUDAndAgg(st.s.getDB('sharded'));

// Check that version document is unmodified.
version = st.s.getCollection('config.version').findOne();
assert.eq(version.minCompatibleVersion, kMinVersion);
assert.eq(version.currentVersion, kCurrentVerion);
assert.eq(clusterID, version.clusterId);
assert.eq(version.excluding, undefined);

st.stop();
})();