summaryrefslogtreecommitdiff
path: root/jstests/multiVersion/migration_between_mixed_version_mongods.js
blob: bedd0e628ef69b0d1a0b36f33dab860a3da9e732 (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
//
// Testing migrations between latest and last-stable mongod versions, where the
// donor is the latest version and the recipient the last-stable, and vice versa.
// Migrations should be successful.
//
// @tags: [fix_for_fcv_46]

// Checking UUID consistency involves talking to a shard node, which in this test is shutdown
TestData.skipCheckingUUIDsConsistentAcrossCluster = true;

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

(function() {
"use strict";

var options = {
    shards: [
        {binVersion: "last-stable"},
        {binVersion: "last-stable"},
        {binVersion: "latest"},
        {binVersion: "latest"}
    ],
    mongos: 1,
    other: {mongosOptions: {binVersion: "last-stable"}}
};

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

assert.binVersion(st.shard0, "last-stable");
assert.binVersion(st.shard1, "last-stable");
assert.binVersion(st.shard2, "latest");
assert.binVersion(st.shard3, "latest");
assert.binVersion(st.s0, "last-stable");

var mongos = st.s0, admin = mongos.getDB('admin'),
    shards = mongos.getCollection('config.shards').find().toArray(),

    fooDB = "fooTest", fooNS = fooDB + ".foo", fooColl = mongos.getCollection(fooNS),
    fooDonor = st.shard0, fooRecipient = st.shard2, fooDonorColl = fooDonor.getCollection(fooNS),
    fooRecipientColl = fooRecipient.getCollection(fooNS),

    barDB = "barTest", barNS = barDB + ".foo", barColl = mongos.getCollection(barNS),
    barDonor = st.shard3, barRecipient = st.shard1, barDonorColl = barDonor.getCollection(barNS),
    barRecipientColl = barRecipient.getCollection(barNS);

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

assert.commandWorked(admin.runCommand({shardCollection: fooNS, key: {a: 1}}));
assert.commandWorked(admin.runCommand({split: fooNS, middle: {a: 10}}));
assert.commandWorked(admin.runCommand({shardCollection: barNS, key: {a: 1}}));
assert.commandWorked(admin.runCommand({split: barNS, middle: {a: 10}}));

fooColl.insert({a: 0});
assert.eq(null, fooColl.getDB().getLastError());
fooColl.insert({a: 10});
assert.eq(null, fooColl.getDB().getLastError());
assert.eq(0, fooRecipientColl.count());
assert.eq(2, fooDonorColl.count());
assert.eq(2, fooColl.count());

barColl.insert({a: 0});
assert.eq(null, barColl.getDB().getLastError());
barColl.insert({a: 10});
assert.eq(null, barColl.getDB().getLastError());
assert.eq(0, barRecipientColl.count());
assert.eq(2, barDonorColl.count());
assert.eq(2, barColl.count());

/**
 * Perform two migrations:
 *      shard0 (last-stable) -> foo chunk -> shard2 (latest)
 *      shard3 (latest)      -> bar chunk -> shard1 (last-stable)
 */

assert.commandWorked(
    admin.runCommand({moveChunk: fooNS, find: {a: 10}, to: shards[2]._id, _waitForDelete: true}));
assert.commandWorked(
    admin.runCommand({moveChunk: barNS, find: {a: 10}, to: shards[1]._id, _waitForDelete: true}));
assert.eq(1,
          fooRecipientColl.count(),
          "Foo collection migration failed. " +
              "Last-stable -> latest mongod version migration failure.");
assert.eq(1,
          fooDonorColl.count(),
          "Foo donor lost its document. " +
              "Last-stable -> latest mongod version migration failure.");
assert.eq(2,
          fooColl.count(),
          "Incorrect number of documents in foo collection. " +
              "Last-stable -> latest mongod version migration failure.");
assert.eq(1,
          barRecipientColl.count(),
          "Bar collection migration failed. " +
              "Latest -> last-stable mongod version migration failure.");
assert.eq(1,
          barDonorColl.count(),
          "Bar donor lost its document. " +
              "Latest -> last-stable mongod version migration failure.");
assert.eq(2,
          barColl.count(),
          "Incorrect number of documents in bar collection. " +
              "Latest -> last-stable mongod version migration failure.");

st.stop();
})();