summaryrefslogtreecommitdiff
path: root/jstests/replsets/initial_sync3.js
blob: dc0455dd1082bbc7ff84edc8625ccb62529897bf (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
/* 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();

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 + ":" + nodes[0].port, priority: 10},
        {_id: 1, host: host + ":" + nodes[1].port, priority: 0},
        {_id: 2, host: host + ":" + nodes[2].port, 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);
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("0 should become primary");
master = replTest.getMaster();

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();