summaryrefslogtreecommitdiff
path: root/jstests/replsets/initial_sync3.js
blob: 4456cfbd498ddcff7d8c10d1a40fa84d0efacf5f (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
54
55
56
57
58
59
60
/* test initial sync options
 *
 * Make sure member can't sync from a member with a different buildIndexes setting.
 *
 * If all nodes in a replica set are using an ephemeral storage engine, the set will not be able to
 * survive a scenario where all index-building members are down simultaneously. In such a
 * scenario, none of the members will have any data, and upon restart will each look for a member to
 * inital sync from. They cannot sync from a member which does not build indexes, so no primary will
 * be elected. This test induces such a scenario, so cannot be run on ephemeral storage engines.
 * @tags: [requires_persistence]
 */


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

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

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