2014-11-20 23:52:17 +01:00
|
|
|
// SERVER-15310 Ensure that stepDown kills all other running operations
|
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
(function() {
|
2019-07-27 00:20:35 +02:00
|
|
|
"use strict";
|
|
|
|
var name = "stepdownKillOps";
|
|
|
|
var replSet = new ReplSetTest({name: name, nodes: 3});
|
|
|
|
var nodes = replSet.nodeList();
|
|
|
|
replSet.startSet();
|
|
|
|
replSet.initiate({
|
|
|
|
"_id": name,
|
|
|
|
"members": [
|
|
|
|
{"_id": 0, "host": nodes[0], "priority": 3},
|
|
|
|
{"_id": 1, "host": nodes[1]},
|
|
|
|
{"_id": 2, "host": nodes[2], "arbiterOnly": true}
|
|
|
|
]
|
|
|
|
});
|
2014-11-20 23:52:17 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
replSet.waitForState(replSet.nodes[0], ReplSetTest.State.PRIMARY);
|
2014-12-02 21:43:13 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
var primary = replSet.getPrimary();
|
|
|
|
assert.eq(primary.host, nodes[0], "primary assumed to be node 0");
|
2019-08-14 15:52:59 +02:00
|
|
|
assert.commandWorked(primary.getDB(name).foo.insert({x: 1}, {w: 2, wtimeout: 10000}));
|
2019-07-27 00:20:35 +02:00
|
|
|
replSet.awaitReplication();
|
2014-11-20 23:52:17 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
jsTestLog("Sleeping 30 seconds so the SECONDARY will be considered electable");
|
|
|
|
sleep(30000);
|
2014-11-20 23:52:17 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
// Run sleep in a separate thread to take the global write lock which would prevent stepdown
|
|
|
|
// from completing if it failed to kill all running operations.
|
|
|
|
jsTestLog("Running {sleep:1, lock: 'w'} to grab global write lock");
|
|
|
|
var sleepCmd = function() {
|
|
|
|
// Run for 10 minutes if not interrupted.
|
|
|
|
db.adminCommand({sleep: 1, lock: 'w', seconds: 60 * 10});
|
|
|
|
};
|
|
|
|
const startTime = new Date().getTime() / 1000;
|
|
|
|
var sleepRunner = startParallelShell(sleepCmd, primary.port);
|
2014-11-20 23:52:17 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
jsTestLog("Confirming that sleep() is running and has the global lock");
|
|
|
|
assert.soon(function() {
|
|
|
|
var res = primary.getDB('admin').currentOp();
|
|
|
|
for (var index in res.inprog) {
|
|
|
|
var entry = res.inprog[index];
|
|
|
|
if (entry["command"] && entry["command"]["sleep"]) {
|
|
|
|
if ("W" === entry["locks"]["Global"]) {
|
|
|
|
return true;
|
2016-03-09 18:17:50 +01:00
|
|
|
}
|
|
|
|
}
|
2019-07-27 00:20:35 +02:00
|
|
|
}
|
|
|
|
printjson(res);
|
|
|
|
return false;
|
|
|
|
}, "sleep never ran and grabbed the global write lock");
|
2014-11-20 23:52:17 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
jsTestLog("Stepping down");
|
|
|
|
assert.commandWorked(primary.getDB('admin').runCommand({replSetStepDown: 30}));
|
2014-11-20 23:52:17 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
jsTestLog("Waiting for former PRIMARY to become SECONDARY");
|
|
|
|
replSet.waitForState(primary, ReplSetTest.State.SECONDARY, 30000);
|
2014-11-20 23:52:17 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
var newPrimary = replSet.getPrimary();
|
|
|
|
assert.neq(primary, newPrimary, "SECONDARY did not become PRIMARY");
|
2014-11-20 23:52:17 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
sleepRunner({checkExitSuccess: false});
|
|
|
|
const endTime = new Date().getTime() / 1000;
|
|
|
|
const duration = endTime - startTime;
|
|
|
|
assert.lt(duration,
|
|
|
|
60 * 9, // In practice, this should be well under 1 minute.
|
|
|
|
"Sleep lock held longer than expected, possibly uninterrupted.");
|
2018-06-27 17:33:18 +02:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
replSet.stopSet();
|
2016-03-09 18:17:50 +01:00
|
|
|
})();
|