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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/* test initial sync options
*
* Make sure member can't sync from a member with a different buildIndexes setting.
*/
load("jstests/replsets/rslib.js");
var name = "initialsync3";
var host = getHostName();
var port = allocatePorts(7);
print("Start set with three nodes");
var replTest = new ReplSetTest( {name: name, nodes: 3} );
var nodes = replTest.startSet();
replTest.initiate({
_id : name,
members : [
{_id:0, host : host+":"+port[0]},
{_id:1, host : host+":"+port[1]},
{_id:2, host : host+":"+port[2], priority : 0, buildIndexes : false},
]});
var master = replTest.getMaster();
print("Initial sync");
master.getDB("foo").bar.baz.insert({x:1});
replTest.awaitReplication();
replTest.stop(0);
replTest.stop(1);
print("restart 1, clearing its data directory so it has to resync");
replTest.start(1);
print("make sure 1 does not become a secondary (because it cannot clone from 2)");
sleep(10000);
reconnect(nodes[1]);
var result = nodes[1].getDB("admin").runCommand({isMaster : 1});
assert(!result.ismaster, tojson(result));
assert(!result.secondary, tojson(result));
print("bring 0 back up");
replTest.restart(0);
print("now 1 should be able to initial sync");
assert.soon(function() {
var result = nodes[1].getDB("admin").runCommand({isMaster : 1});
printjson(result);
return result.secondary;
});
replTest.stopSet();
print("reconfig");
var rs2 = new ReplSetTest( {name: 'reconfig-isync3', nodes: 3} );
rs2.startSet();
rs2.initiate();
master = rs2.getMaster();
var config = master.getDB("local").system.replset.findOne();
config.version++;
config.members[0].priority = 2;
config.members[0].initialSync = {state : 2};
config.members[1].initialSync = {state : 1};
try {
master.getDB("admin").runCommand({replSetReconfig : config});
}
catch(e) {
print("trying to reconfigure: "+e);
}
// wait for a heartbeat, too, just in case sync happens before hb
assert.soon(function() {
try {
for (var n in rs2.nodes) {
if (rs2.nodes[n].getDB("local").system.replset.findOne().version != 2) {
return false;
}
}
}
catch (e) {
return false;
}
return true;
});
rs2.awaitReplication();
// test partitioning
master = rs2.bridge();
rs2.partition(0, 2);
master.getDB("foo").bar.baz.insert({x:1});
rs2.awaitReplication();
master.getDB("foo").bar.baz.insert({x:2});
var x = master.getDB("foo").runCommand({getLastError : 1, w : 3, wtimeout : 5000});
printjson(x);
assert.eq(null, x.err);
rs2.stopSet();
print("initialSync3 success!");
|