2010-11-17 18:30:24 -05:00
|
|
|
/* test initial sync options
|
|
|
|
|
*
|
2011-10-27 11:25:25 -04:00
|
|
|
* Make sure member can't sync from a member with a different buildIndexes setting.
|
2015-11-19 14:01:59 -05:00
|
|
|
*
|
|
|
|
|
* 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]
|
2010-11-17 18:30:24 -05:00
|
|
|
*/
|
|
|
|
|
|
2012-02-14 15:58:53 -05:00
|
|
|
|
2010-11-17 18:30:24 -05:00
|
|
|
load("jstests/replsets/rslib.js");
|
|
|
|
|
var name = "initialsync3";
|
|
|
|
|
var host = getHostName();
|
|
|
|
|
|
|
|
|
|
print("Start set with three nodes");
|
2011-10-27 11:25:25 -04:00
|
|
|
var replTest = new ReplSetTest( {name: name, nodes: 3} );
|
2010-11-17 18:30:24 -05:00
|
|
|
var nodes = replTest.startSet();
|
|
|
|
|
replTest.initiate({
|
2015-09-01 16:19:57 -04:00
|
|
|
_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},
|
|
|
|
|
]
|
|
|
|
|
});
|
2010-11-17 18:30:24 -05:00
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
var master = replTest.getPrimary();
|
2010-11-17 18:30:24 -05:00
|
|
|
|
|
|
|
|
print("Initial sync");
|
|
|
|
|
master.getDB("foo").bar.baz.insert({x:1});
|
2011-10-27 11:25:25 -04:00
|
|
|
replTest.awaitReplication();
|
2010-11-17 18:30:24 -05:00
|
|
|
|
2011-10-27 11:25:25 -04:00
|
|
|
replTest.stop(0);
|
|
|
|
|
replTest.stop(1);
|
2010-11-17 18:30:24 -05:00
|
|
|
|
2011-10-27 11:25:25 -04:00
|
|
|
print("restart 1, clearing its data directory so it has to resync");
|
|
|
|
|
replTest.start(1);
|
2011-07-13 14:08:54 -04:00
|
|
|
|
2011-10-27 11:25:25 -04:00
|
|
|
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));
|
2011-07-13 14:08:54 -04:00
|
|
|
|
2011-10-27 11:25:25 -04:00
|
|
|
print("bring 0 back up");
|
|
|
|
|
replTest.restart(0);
|
2012-09-10 12:46:25 -04:00
|
|
|
print("0 should become primary");
|
2015-11-25 11:20:43 -05:00
|
|
|
master = replTest.getPrimary();
|
2010-11-17 18:30:24 -05:00
|
|
|
|
2011-10-27 11:25:25 -04:00
|
|
|
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;
|
|
|
|
|
});
|
2011-02-05 23:18:23 -05:00
|
|
|
|
2010-11-17 18:30:24 -05:00
|
|
|
replTest.stopSet();
|