summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--etc/backports_required_for_multiversion_tests.yml2
-rw-r--r--jstests/replsets/force_shutdown_primary.js7
-rw-r--r--src/mongo/db/commands/shutdown_d.cpp9
3 files changed, 18 insertions, 0 deletions
diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml
index f493237c0ac..3421495d9d6 100644
--- a/etc/backports_required_for_multiversion_tests.yml
+++ b/etc/backports_required_for_multiversion_tests.yml
@@ -98,6 +98,8 @@ all:
test_file: jstests/replsets/election_handoff_not_immediately_electable.js
- ticket: SERVER-53932
test_file: jstests/replsets/rollback_reconstructs_transactions_prepared_before_stable.js
+ - ticket: SERVER-54366
+ test_file: jstests/replsets/force_shutdown_primary.js
# Tests that should only be excluded from particular suites should be listed under that suite.
suites:
diff --git a/jstests/replsets/force_shutdown_primary.js b/jstests/replsets/force_shutdown_primary.js
index 9e578c8efd2..46cdd1ef4e1 100644
--- a/jstests/replsets/force_shutdown_primary.js
+++ b/jstests/replsets/force_shutdown_primary.js
@@ -14,6 +14,7 @@
(function() {
"use strict";
+load("jstests/libs/fail_point_util.js");
load("jstests/libs/write_concern_util.js"); // for stopReplicationOnSecondaries.
const replTest = new ReplSetTest({nodes: 3});
replTest.startSet();
@@ -29,10 +30,16 @@ stopReplicationOnSecondaries(replTest);
jsTestLog("Executing write to primary.");
assert.commandWorked(testDB.foo.insert({x: 2}));
+// To ensure that we kill the shutdown operation during step down, we wait
+// until we hit the 'hangInShutdownBeforeStepdown' failpoint.
+const failPoint = configureFailPoint(primary, 'hangInShutdownBeforeStepdown');
+
jsTestLog("Shutting down primary in a parallel shell");
const shutdownShell = startParallelShell(function() {
db.adminCommand({shutdown: 1, timeoutSecs: 60, force: true});
}, primary.port);
+failPoint.wait();
+failPoint.off();
let shutdownOpID = -1;
let res = {};
diff --git a/src/mongo/db/commands/shutdown_d.cpp b/src/mongo/db/commands/shutdown_d.cpp
index bed8d258d0a..157ff7b7fa9 100644
--- a/src/mongo/db/commands/shutdown_d.cpp
+++ b/src/mongo/db/commands/shutdown_d.cpp
@@ -40,6 +40,10 @@
namespace mongo {
+namespace {
+MONGO_FAIL_POINT_DEFINE(hangInShutdownBeforeStepdown);
+} // namespace
+
Status stepDownForShutdown(OperationContext* opCtx,
const Milliseconds& waitTime,
bool forceShutdown) noexcept {
@@ -48,6 +52,11 @@ Status stepDownForShutdown(OperationContext* opCtx,
// for any secondaries. Ignore stepdown.
if (replCoord->getConfig().getNumMembers() != 1) {
try {
+ if (MONGO_FAIL_POINT(hangInShutdownBeforeStepdown)) {
+ log() << "hangInShutdownBeforeStepdown failpoint enabled";
+ MONGO_FAIL_POINT_PAUSE_WHILE_SET(hangInShutdownBeforeStepdown);
+ }
+
replCoord->stepDown(opCtx, false /* force */, waitTime, Seconds(120));
} catch (const ExceptionFor<ErrorCodes::NotWritablePrimary>&) {
// Ignore NotWritablePrimary errors.