summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Mir <ali.mir@mongodb.com>2021-02-08 16:00:15 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-02-23 16:11:11 +0000
commitb964c7a249cd2329203e6dffeec18da716235b71 (patch)
treeabbd32ba1657993d2ae2a426bcdf60f718abc7c7
parent567b7b59849dc2ecd10d6899b9b31c1aba5f7bd1 (diff)
downloadmongo-b964c7a249cd2329203e6dffeec18da716235b71.tar.gz
SERVER-54366 Wait for node to start stepdown before killing shutdown operation in force_shutdown_primary.js
(cherry picked from commit 2f3010a29bed0d3733a428021a9cc66c83580fd0)
-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.