Files
mongo/jstests/replsets/kill_ttl_on_stepdown.js
Zac 591928c619 SERVER-108478 JS formatted by prettier and remove clang-format (#39656)
GitOrigin-RevId: 6c8f6aded47f260aa4f7c231b17dae3302cb1e04
2025-08-21 17:27:09 +00:00

65 lines
2.1 KiB
JavaScript

/**
* Ensure that a stepdown of the primary kills any TTLMonitor clients, but not the TTLMonitor
* thread itself and after stepdown finishes, the TTLMonitor resumes.
*
* @tags: [requires_replication]
*/
import {configureFailPoint} from "jstests/libs/fail_point_util.js";
import {ReplSetTest} from "jstests/libs/replsettest.js";
const dbName = "kill_ttl_on_stepdown";
const rst = new ReplSetTest({
nodes: [{}, {rsConfig: {priority: 0}}],
nodeOptions: {setParameter: "ttlMonitorSleepSecs=15"},
});
rst.startSet();
rst.initiate();
let primary = rst.getPrimary();
let db = primary.getDB(dbName);
// Create a TTL index.
const collName = jsTestName();
db.getCollection(collName).createIndex({x: 1}, {expireAfterSeconds: 3600});
function getNumTTLPasses() {
let serverStatus = assert.commandWorked(primary.adminCommand({serverStatus: 1}));
return serverStatus.metrics.ttl.passes;
}
// Let the TTLMonitor do some passes.
assert.soon(() => {
return getNumTTLPasses() > 0;
}, "TTLMonitor never did any passes.");
let failPoint = configureFailPoint(primary, "hangTTLMonitorWithLock");
failPoint.wait();
// See how many passes the TTLMonitor has done, before we stepdown the primary, killing it.
let ttlPassesBeforeStepdown = getNumTTLPasses();
// Force a stepdown of the primary.
assert.commandWorked(primary.getDB("admin").runCommand({replSetStepDown: 60 * 10 /* 10 minutes */, force: true}));
rst.awaitSecondaryNodes(null, [primary]);
assert.commandWorked(primary.adminCommand({replSetFreeze: 0}));
assert.commandWorked(primary.adminCommand({replSetStepUp: 1}));
primary = rst.getPrimary();
// Ensure the TTLMonitor was interrupted.
checkLog.contains(primary, "TTLMonitor was interrupted");
// Disable the failpoint on the node that stepped down.
failPoint.off();
// Wait until the number TTLMonitor passes increases, informing us that the TTLMonitor thread
// was not killed entirely and will continue to run after stepdown finishes.
assert.soon(() => {
if (getNumTTLPasses() > ttlPassesBeforeStepdown) {
return true;
}
}, "TTLMonitor was not running after stepdown");
rst.stopSet();