2014-02-26 17:22:07 -08:00
|
|
|
// Test that setting maxSyncSourceLagSecs causes the set to change sync target
|
2015-11-19 14:01:59 -05:00
|
|
|
//
|
|
|
|
|
// This test requires the fsync command to ensure members experience a delay.
|
|
|
|
|
// @tags: [requires_fsync]
|
2014-11-14 06:27:02 -05:00
|
|
|
(function() {
|
|
|
|
|
"use strict";
|
|
|
|
|
var name = "maxSyncSourceLagSecs";
|
|
|
|
|
var replTest = new ReplSetTest({name: name,
|
|
|
|
|
nodes: 3,
|
|
|
|
|
oplogSize: 5,
|
|
|
|
|
nodeOptions: {setParameter: "maxSyncSourceLagSecs=3"}});
|
|
|
|
|
var nodes = replTest.nodeList();
|
|
|
|
|
replTest.startSet();
|
|
|
|
|
replTest.initiate({"_id": name,
|
|
|
|
|
"members": [
|
|
|
|
|
{ "_id": 0, "host": nodes[0], priority: 3 },
|
2014-12-02 15:43:13 -05:00
|
|
|
{ "_id": 1, "host": nodes[1], priority: 0 },
|
|
|
|
|
{ "_id": 2, "host": nodes[2], priority: 0 }],
|
2014-11-14 06:27:02 -05:00
|
|
|
});
|
2014-02-26 17:22:07 -08:00
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
var master = replTest.getPrimary();
|
2014-11-14 06:27:02 -05:00
|
|
|
master.getDB("foo").bar.save({a: 1});
|
|
|
|
|
replTest.awaitReplication();
|
|
|
|
|
var slaves = replTest.liveNodes.slaves;
|
2014-02-26 17:22:07 -08:00
|
|
|
|
2014-11-14 06:27:02 -05:00
|
|
|
// need to put at least maxSyncSourceLagSecs b/w first op and subsequent ops
|
|
|
|
|
// so that the shouldChangeSyncSource logic goes into effect
|
|
|
|
|
sleep(4000);
|
2014-03-14 17:40:15 -04:00
|
|
|
|
2014-11-14 06:27:02 -05:00
|
|
|
jsTestLog("Setting sync target of slave 2 to slave 1");
|
|
|
|
|
assert.commandWorked(slaves[1].getDB("admin").runCommand({replSetSyncFrom: slaves[0].name}));
|
|
|
|
|
assert.soon(function() {
|
2015-11-12 07:53:10 -05:00
|
|
|
var res = slaves[1].getDB("admin").runCommand({"replSetGetStatus": 1});
|
|
|
|
|
return res.syncingTo === slaves[0].name;
|
2014-11-14 06:27:02 -05:00
|
|
|
}, "sync target not changed to other slave");
|
|
|
|
|
printjson(replTest.status());
|
2014-02-26 17:22:07 -08:00
|
|
|
|
2014-11-14 06:27:02 -05:00
|
|
|
jsTestLog("Lock slave 1 and add some docs. Force sync target for slave 2 to change to primary");
|
|
|
|
|
assert.commandWorked(slaves[0].getDB("admin").runCommand({fsync:1, lock: 1}));
|
|
|
|
|
master.getDB("foo").bar.save({a: 2});
|
2014-02-26 17:22:07 -08:00
|
|
|
|
2014-11-14 06:27:02 -05:00
|
|
|
assert.soon(function() {
|
2015-11-12 07:53:10 -05:00
|
|
|
var res = slaves[1].getDB("admin").runCommand({"replSetGetStatus": 1});
|
|
|
|
|
return res.syncingTo === master.name;
|
2014-11-14 06:27:02 -05:00
|
|
|
}, "sync target not changed back to primary");
|
|
|
|
|
printjson(replTest.status());
|
2014-02-26 17:22:07 -08:00
|
|
|
|
2014-11-14 06:27:02 -05:00
|
|
|
assert.soon(function() {
|
|
|
|
|
return (slaves[1].getDB("foo").bar.count() === 2);
|
|
|
|
|
}, "slave should have caught up after syncing to primary.");
|
2014-02-26 17:22:07 -08:00
|
|
|
|
2015-03-26 10:03:29 -04:00
|
|
|
assert.commandWorked(slaves[0].getDB("admin").fsyncUnlock());
|
2014-11-14 06:27:02 -05:00
|
|
|
replTest.stopSet();
|
|
|
|
|
}());
|