summaryrefslogtreecommitdiff
path: root/jstests/replsets/chaining_removal.js
blob: 027de0215d6e91fc25baa29f5c840c4dfdd76739 (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
// ensure removing a chained node does not break reporting of replication progress (SERVER-15849)

(function() {
    "use strict";
    load("jstests/replsets/rslib.js");

    var numNodes = 5;
    var host = getHostName();
    var name = "chaining_removal";

    var replTest = new ReplSetTest({name: name, nodes: numNodes});
    var nodes = replTest.startSet();
    var port = replTest.ports;
    replTest.initiate({
        _id: name,
        members: [
            {_id: 0, host: nodes[0].host, priority: 3},
            {_id: 1, host: nodes[1].host, priority: 0},
            {_id: 2, host: nodes[2].host, priority: 0},
            {_id: 3, host: nodes[3].host, priority: 0},
            {_id: 4, host: nodes[4].host, priority: 0},
        ],
    });
    replTest.waitForState(nodes[0], ReplSetTest.State.PRIMARY, 60 * 1000);
    replTest.awaitNodesAgreeOnPrimary();
    var primary = replTest.getPrimary();
    replTest.awaitReplication();

    // Force node 1 to sync directly from node 0.
    syncFrom(nodes[1], nodes[0], replTest);

    // Force node 4 to sync through node 1.
    syncFrom(nodes[4], nodes[1], replTest);

    // write that should reach all nodes
    var timeout = 60 * 1000;
    var options = {
        writeConcern: {w: numNodes, wtimeout: timeout}
    };
    assert.writeOK(primary.getDB(name).foo.insert({x: 1}, options));

    var config = primary.getDB("local").system.replset.findOne();
    config.members.pop();
    config.version++;
    // remove node 4
    replTest.stop(4);
    try {
        primary.adminCommand({replSetReconfig: config});
    } catch (e) {
        print("error: " + e);
    }

    // ensure writing to all four nodes still works
    primary = replTest.getPrimary();
    replTest.awaitReplication();
    options.writeConcern.w = 4;
    assert.writeOK(primary.getDB(name).foo.insert({x: 2}, options));

    replTest.stopSet();
}());