2015-11-19 14:01:59 -05:00
|
|
|
// Test that GLE asserts when the primary steps down while we're waiting for a replicated write.
|
|
|
|
|
//
|
|
|
|
|
// This test requires the fsync command to force a secondary to be stale.
|
|
|
|
|
// @tags: [requires_fsync]
|
2013-04-29 13:34:43 -04:00
|
|
|
|
|
|
|
|
var replTest = new ReplSetTest({ name: 'testSet', nodes: 2 });
|
|
|
|
|
var nodes = replTest.startSet();
|
|
|
|
|
replTest.initiate();
|
2015-11-25 11:20:43 -05:00
|
|
|
var master = replTest.getPrimary();
|
2013-04-29 13:34:43 -04:00
|
|
|
|
|
|
|
|
// do a write to allow stepping down of the primary;
|
|
|
|
|
// otherwise, the primary will refuse to step down
|
|
|
|
|
print("\ndo a write");
|
|
|
|
|
master.getDB("test").foo.insert({x:1});
|
|
|
|
|
replTest.awaitReplication();
|
|
|
|
|
|
2013-06-14 14:58:46 -04:00
|
|
|
// do another write, because the first one might be longer than 10 seconds ago
|
|
|
|
|
// on the secondary (due to starting up), and we need to be within 10 seconds
|
|
|
|
|
// to step down.
|
2014-03-03 11:27:18 -05:00
|
|
|
var options = { writeConcern: { w: 2, wtimeout: 30000 }};
|
|
|
|
|
assert.writeOK(master.getDB("test").foo.insert({ x: 2 }, options));
|
2013-04-29 13:34:43 -04:00
|
|
|
// lock secondary, to pause replication
|
|
|
|
|
print("\nlock secondary");
|
|
|
|
|
var locked = replTest.liveNodes.slaves[0];
|
|
|
|
|
printjson( locked.getDB("admin").runCommand({fsync : 1, lock : 1}) );
|
|
|
|
|
|
|
|
|
|
// do a write
|
|
|
|
|
print("\ndo a write");
|
2013-06-14 14:58:46 -04:00
|
|
|
master.getDB("test").foo.insert({x:3});
|
2013-04-29 13:34:43 -04:00
|
|
|
|
|
|
|
|
// step down the primary asyncronously
|
|
|
|
|
print("stepdown");
|
2013-06-17 09:26:38 -04:00
|
|
|
var command = "sleep(4000); tojson(db.adminCommand( { replSetStepDown : 60, force : 1 } ));"
|
2015-06-23 22:22:52 -04:00
|
|
|
var awaitShell = startParallelShell(command, master.port);
|
2013-04-29 13:34:43 -04:00
|
|
|
|
2013-05-15 11:26:32 -04:00
|
|
|
print("getlasterror; should assert or return an error, depending on timing");
|
2013-12-04 10:16:10 -05:00
|
|
|
var gleFunction = function() {
|
2013-05-10 16:02:12 -04:00
|
|
|
var result = master.getDB("test").runCommand({getLastError : 1, w: 2 , wtimeout :30000 });
|
2014-11-20 17:52:17 -05:00
|
|
|
if (result.errmsg === "not master" ||
|
|
|
|
|
result.code == 10107 ||
|
|
|
|
|
result.code == 11601 /*interrupted*/ ) {
|
2013-05-15 11:26:32 -04:00
|
|
|
throw new Error("satisfy assert.throws()");
|
|
|
|
|
}
|
2013-05-10 16:02:12 -04:00
|
|
|
print("failed to throw exception; GLE returned: ");
|
|
|
|
|
printjson(result);
|
2013-04-29 13:34:43 -04:00
|
|
|
};
|
|
|
|
|
var result = assert.throws(gleFunction);
|
|
|
|
|
print("result of gle:");
|
|
|
|
|
printjson(result);
|
|
|
|
|
|
2015-06-23 22:22:52 -04:00
|
|
|
var exitCode = awaitShell({checkExitSuccess: false});
|
|
|
|
|
assert.neq(0, exitCode, "expected replSetStepDown to close the shell's connection");
|
|
|
|
|
|
2013-04-29 13:34:43 -04:00
|
|
|
// unlock and shut down
|
2015-03-26 10:03:29 -04:00
|
|
|
printjson(locked.getDB("admin").fsyncUnlock());
|
2013-04-29 13:34:43 -04:00
|
|
|
replTest.stopSet();
|