summaryrefslogtreecommitdiff
path: root/jstests/multiVersion/shard_collection_between_mixed_version_mongods.js
blob: 2fb86b9b8eb73133c890c6f4629bd86570dac6c2 (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
//
// Testing shardCollection between 4.0.1 and latest mongod versions for both config servers
// and shards.
//

load("./jstests/multiVersion/libs/verify_versions.js");

(function() {
    "use strict";

    var options = {
        shards: [{binVersion: "latest"}, {binVersion: "4.0.1"}, {binVersion: "4.0.1"}],
        mongos: 1,
        other: {
            mongosOptions: {binVersion: "latest"},
            configOptions: {binVersion: "latest"},
            shardAsReplicaSet: true
        }
    };

    var st = new ShardingTest(options);
    st.stopBalancer();

    assert.binVersion(st.shard0, "latest");
    assert.binVersion(st.shard1, "4.0.1");
    assert.binVersion(st.shard2, "4.0.1");
    assert.binVersion(st.s0, "latest");

    var mongos = st.s0;
    var admin = mongos.getDB('admin');
    var shards = mongos.getCollection('config.shards').find().toArray();
    const fooDB = "fooTest";
    const fooNS = fooDB + ".foo";
    const barDB = "barTest";
    const barNS = barDB + ".foo";

    assert.commandWorked(admin.runCommand({enableSharding: fooDB}));
    assert.commandWorked(admin.runCommand({enableSharding: barDB}));
    st.ensurePrimaryShard(fooDB, shards[0]._id);
    st.ensurePrimaryShard(barDB, shards[1]._id);

    // Test that shardCollection succeeds when both the config server and primary shard are
    // running with latest binVersion, but other shards are running with 4.0.1 which does not
    // have the new shardCollection protocol.
    assert.commandWorked(admin.runCommand({shardCollection: fooNS, key: {a: 1}}));

    // Test that shardCollection succeeds when the config server is running with the latest
    // binVersion, but the primary is running with 4.0.1.
    assert.commandWorked(admin.runCommand({shardCollection: barNS, key: {a: 1}}));

    mongos.getDB(fooDB).foo.drop();
    mongos.getDB(barDB).foo.drop();

    // Test that shardCollection with a hashed shard key succeeds when both the config server and
    // primary shard are running with latest binVersion, but other shards are running with 4.0.1
    // which does not have the new shardCollection protocol.
    assert.commandWorked(admin.runCommand({shardCollection: fooNS, key: {a: "hashed"}}));

    // Test that shardCollection with a hashed shard key succeeds when the config server is running
    // with the latest binVersion, but the primary is running with 4.0.1.
    assert.commandWorked(admin.runCommand({shardCollection: barNS, key: {a: "hashed"}}));

    st.stop();
})();