summaryrefslogtreecommitdiff
path: root/jstests/replsets/force_reconfig_skips_config_replication.js
blob: fe3c10308f0977bb1557e2c5374ac14716deee0f (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
/**
 * Verify that a force replica set reconfig skips the config replication check.
 * The force reconfig should succeed even though the previous config has not
 * committed across a majority of nodes.
 */

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

const replTest = new ReplSetTest({nodes: 2, useBridge: true});
const nodes = replTest.startSet();
// Initiating with a high election timeout prevents unnecessary elections and also prevents
// the primary from stepping down if it cannot communicate with the secondary.
replTest.initiateWithHighElectionTimeout();
const primary = replTest.getPrimary();
const secondary = replTest.getSecondary();

jsTestLog("Test force reconfig skips config replication against primary");
// Disconnect the secondary from the primary.
secondary.disconnect(primary);

const C1 = primary.getDB("local").system.replset.findOne();
assert.commandWorked(primary.getDB("admin").runCommand({replSetReconfig: C1, force: true}));
const C2 = primary.getDB("local").system.replset.findOne();
// As this force reconfig will skip the config replication safety check,
// it should succeed even though C1 has not been replicated to a majority.
assert.commandWorked(primary.getDB("admin").runCommand({replSetReconfig: C2, force: true}));
secondary.reconnect(primary);

// Wait until the config has propagated to the secondary.
assert.soon(function() {
    const res = primary.adminCommand({replSetGetStatus: 1});
    return res.members[1].configVersion === replTest.getReplSetConfigFromNode().version;
});

jsTestLog("Test force reconfig skips config replication against secondary");
// Disconnect the secondary from the primary.
secondary.disconnect(primary);

const C3 = secondary.getDB("local").system.replset.findOne();
assert.commandWorked(secondary.getDB("admin").runCommand({replSetReconfig: C3, force: true}));
// As this force reconfig will skip the config replication safety check,
// it should succeed even though C1 has not been replicated to a majority.
const C4 = secondary.getDB("local").system.replset.findOne();
assert.commandWorked(secondary.getDB("admin").runCommand({replSetReconfig: C4, force: true}));
secondary.reconnect(primary);

replTest.awaitNodesAgreeOnConfigVersion();
replTest.stopSet();
}());