summaryrefslogtreecommitdiff
path: root/jstests/replsets/two_nodes_priority_take_over.js
blob: 1fba2350e8f6db20d89a38415fc028610dd7c6d5 (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
// SERVER-20812 Current primary rejects vote request from higher-priority node
// because of stepping down. In a two node replset, this rejection will prevent
// smooth priority takeover.

// TODO: We have to disable this test until SERVER-21456 is fixed, due to the
// race of tagging and closing connections on stepdown.
if (false) {
    load("jstests/replsets/rslib.js");

    (function() {
        "use strict";
        var name = "two_nodes_priority_take_over";
        var rst = new ReplSetTest({name: name, nodes: 2});

        rst.startSet();
        var conf = rst.getReplSetConfig();
        conf.members[0].priority = 2;
        conf.members[1].priority = 1;
        rst.initiate(conf);
        rst.awaitSecondaryNodes();
        // Set verbosity for replication on all nodes.
        var verbosity = {
            "setParameter": 1,
            "logComponentVerbosity": {"verbosity": 4, "storage": {"verbosity": 1}}
        };
        rst.nodes.forEach(function(node) {
            node.adminCommand(verbosity);
        });

        // The first node will be the primary at the beginning.
        rst.waitForState(rst.nodes[0], ReplSetTest.State.PRIMARY);

        // Get the term when replset is stable.
        var res = rst.getPrimary().adminCommand("replSetGetStatus");
        assert.commandWorked(res);
        var stableTerm = res.term;

        // Reconfig to change priorities. The current primary remains the same until
        // the higher priority node takes over.
        var conf = rst.getReplSetConfig();
        conf.members[0].priority = 1;
        conf.members[1].priority = 2;
        conf.version = 2;
        reconfig(rst, conf);

        // The second node will take over the primary.
        rst.waitForState(rst.nodes[1], ReplSetTest.State.PRIMARY, 60 * 1000);

        res = rst.getPrimary().adminCommand("replSetGetStatus");
        assert.commandWorked(res);
        var newTerm = res.term;

        // Priority takeover should happen smoothly without failed election as there is
        // no current candidate. If vote requests failed (wrongly) for some reason,
        // nodes have to start new elections, which increase the term unnecessarily.
        assert.eq(newTerm, stableTerm + 1);
    })();
}