summaryrefslogtreecommitdiff
path: root/jstests/replsets/reconfig_only_counts_voting_nodes_for_oplog_commitment.js
blob: 62b368e0f9660fbbf8644c62b4eeddc51eff8b63 (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
/**
 * Test that replSetReconfig waits for a majority of voting nodes to commit all oplog
 * entries from the previous config in the current config.
 */

(function() {
"use strict";

load("jstests/replsets/rslib.js");
load("jstests/libs/write_concern_util.js");

// Start a 3 node replica set with two non-voting nodes. In this case, only one node is
// needed to satisfy the oplog commitment check.
var replTest = new ReplSetTest({
    nodes: [
        {rsConfig: {priority: 1, votes: 1}},
        {rsConfig: {priority: 0, votes: 0}},
        {rsConfig: {priority: 0, votes: 0}},
    ]
});
var nodes = replTest.startSet();
replTest.initiate();
var primary = replTest.getPrimary();

// Do a write that should not be able to replicate to node1 since we stopped replication.
stopServerReplication(nodes[1]);
assert.commandWorked(primary.getDB("test")["test"].insert({x: 1}));

// Run a reconfig that changes node1's votes to 1. The reconfig succeeds when it replicates
// to a majority of nodes.
jsTestLog("Doing reconfig.");
var config = primary.getDB("local").system.replset.findOne();
config.version++;
config.members[1].votes = 1;
assert.commandWorked(primary.adminCommand({replSetReconfig: config}));

// Node1 must replicate the previous write in order for a current reconfig to succeed.
// This new reconfig has a timeout of 5 seconds, and should fail with a CurrentConfigNotCommittedYet
// error.
config.version++;
assert.commandFailedWithCode(primary.adminCommand({replSetReconfig: config, maxTimeMS: 5000}),
                             ErrorCodes.CurrentConfigNotCommittedYet);
// Check the latest reconfig is rejected.
assert.gt(config.version, replTest.getReplSetConfigFromNode().version);
restartServerReplication(nodes[1]);

replTest.awaitReplication();

replTest.stopSet();
}());