summaryrefslogtreecommitdiff
path: root/jstests/multiVersion/upgrade_cluster.js
blob: 09a8c86d3d84db41502919e24b11b4d969a6f1e8 (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
/**
 * Tests upgrading a cluster from last stable to current version.
 */

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

(function() {

    /**
     * @param isRSCluster {bool} use replica set shards.
     */
    var runTest = function(isRSCluster) {
        "use strict";

        jsTest.log("Starting" + (isRSCluster ? " (replica set)" : "") + " cluster" + "...");

        var options = {
            mongosOptions: {binVersion: "last-stable"},
            configOptions: {binVersion: "last-stable"},
            shardOptions: {binVersion: "last-stable"},

            rsOptions: {binVersion: "last-stable"},
            rs: isRSCluster
        };

        var testCRUD = function(mongos) {
            assert.commandWorked(mongos.getDB('test').runCommand({dropDatabase: 1}));
            assert.commandWorked(mongos.getDB('unsharded').runCommand({dropDatabase: 1}));

            var unshardedDB = mongos.getDB('unshareded');
            assert.commandWorked(unshardedDB.runCommand({insert: 'foo', documents: [{x: 1}]}));
            assert.commandWorked(unshardedDB.runCommand(
                {update: 'foo', updates: [{q: {x: 1}, u: {$set: {y: 1}}}]}));
            var doc = unshardedDB.foo.findOne({x: 1});
            assert.eq(1, doc.y);
            assert.commandWorked(
                unshardedDB.runCommand({delete: 'foo', deletes: [{q: {x: 1}, limit: 1}]}));
            doc = unshardedDB.foo.findOne();
            assert.eq(null, doc);

            assert.commandWorked(mongos.adminCommand({enableSharding: 'test'}));
            assert.commandWorked(mongos.adminCommand({shardCollection: 'test.user', key: {x: 1}}));

            var shardedDB = mongos.getDB('shareded');
            assert.commandWorked(shardedDB.runCommand({insert: 'foo', documents: [{x: 1}]}));
            assert.commandWorked(
                shardedDB.runCommand({update: 'foo', updates: [{q: {x: 1}, u: {$set: {y: 1}}}]}));
            doc = shardedDB.foo.findOne({x: 1});
            assert.eq(1, doc.y);
            assert.commandWorked(
                shardedDB.runCommand({delete: 'foo', deletes: [{q: {x: 1}, limit: 1}]}));
            doc = shardedDB.foo.findOne();
            assert.eq(null, doc);
        };

        var st = new ShardingTest({shards: 2, mongos: 1, other: options});

        var version = st.s.getCollection('config.version').findOne();

        assert.eq(version.minCompatibleVersion, 5);
        assert.eq(version.currentVersion, 6);
        var clusterID = version.clusterId;
        assert.neq(null, clusterID);
        assert.eq(version.excluding, undefined);

        // upgrade everything except for mongos
        st.upgradeCluster("latest", {upgradeMongos: false});
        st.restartMongoses();

        testCRUD(st.s);

        // upgrade mongos
        st.upgradeCluster("latest", {upgradeConfigs: false, upgradeShards: false});
        st.restartMongoses();

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

        testCRUD(st.s);

        st.stop();
    };

    runTest(false);
    runTest(true);

})();