blob: 7303e849b17cc1c4ade0c72838ffdaffaaddc8a5 (
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
|
/**
* Test that replSetReconfig ignores the term value provided by a user.
*/
(function() {
// Start a 2 node replica set where one of the nodes has priority 0 to
// prevent unnecessary elections.
var replTest = new ReplSetTest({nodes: 1});
var nodes = replTest.startSet();
replTest.initiate();
// After the first election, the term should be 1.
var primary = replTest.getPrimary();
jsTestLog("Reconfig command ignores user provided term, 50");
var config = primary.getDB("local").system.replset.findOne();
printjson(config);
config.version++;
config.members[nodes.indexOf(primary)].priority = 1; // Legal reconfig.
config.term = 50;
assert.commandWorked(primary.getDB("admin").runCommand({replSetReconfig: config}));
replTest.awaitReplication();
config = primary.getDB("local").system.replset.findOne();
assert.eq(config.term, 1);
jsTestLog("Force reconfig ignores user provided term");
config.term = 55;
config.version++;
assert.commandWorked(primary.getDB("admin").runCommand({replSetReconfig: config, force: true}));
config = primary.getDB("local").system.replset.findOne();
// Force reconfig sets the config term to -1. During config
// serialization, a -1 term is treated as a missing field.
assert(!config.hasOwnProperty("term"));
jsTestLog("Force reconfig with missing term results in term -1");
delete config.term;
config.version++;
assert.commandWorked(primary.getDB("admin").runCommand({replSetReconfig: config, force: true}));
config = primary.getDB("local").system.replset.findOne();
// Force reconfig sets the config term to -1. During config
// serialization, a -1 term is treated as a missing field.
assert(!config.hasOwnProperty("term"));
replTest.stopSet();
}());
|