diff --git a/jstests/noPassthrough/index_shutdown_cmd_primary.js b/jstests/noPassthrough/index_shutdown_cmd_primary.js index aff009756bb..c0c482ee490 100644 --- a/jstests/noPassthrough/index_shutdown_cmd_primary.js +++ b/jstests/noPassthrough/index_shutdown_cmd_primary.js @@ -37,23 +37,16 @@ IndexBuildTest.waitForIndexBuildToStart(testDB, coll.getName(), 'a_1'); // Stop the primary using the shutdown command without {force: true}. try { assert.commandFailedWithCode(primary.adminCommand({shutdown: 1, force: false}), - ErrorCodes.ExceededTimeLimit); + ErrorCodes.ConflictingOperationInProgress); } finally { IndexBuildTest.resumeIndexBuilds(primary); } IndexBuildTest.waitForIndexBuildToStop(testDB); -const exitCode = createIdx({checkExitSuccess: false}); -assert.neq(0, exitCode, 'expected shell to exit abnormally due to index build being terminated'); +createIdx(); -if (IndexBuildTest.supportsTwoPhaseIndexBuild(primary)) { - // Two phased index build would resume after stepped down primary node is re-elected. - IndexBuildTest.assertIndexes(coll, 2, ['_id_', 'a_1']); -} else { - // Single-phased ndex build would be aborted by step down triggered by the shutdown command. - IndexBuildTest.assertIndexes(coll, 1, ['_id_']); -} +IndexBuildTest.assertIndexes(coll, 2, ['_id_', 'a_1']); // This runs the shutdown command without {force: true} with additional handling for expected // network errors when the command succeeds. diff --git a/jstests/noPassthrough/index_shutdown_cmd_secondary.js b/jstests/noPassthrough/index_shutdown_cmd_secondary.js index 9928179e5c3..bc3bf82da79 100644 --- a/jstests/noPassthrough/index_shutdown_cmd_secondary.js +++ b/jstests/noPassthrough/index_shutdown_cmd_secondary.js @@ -40,7 +40,8 @@ IndexBuildTest.waitForIndexBuildToStart(secondaryDB, secondaryColl.getName(), 'a // Stop the secondary using the shutdown command without {force: true}. try { - // assert.commandWorked(secondary.adminCommand({shutdown: 1, force: false})); + assert.commandFailedWithCode(secondary.adminCommand({shutdown: 1, force: false}), + ErrorCodes.ConflictingOperationInProgress); } finally { IndexBuildTest.resumeIndexBuilds(secondary); } diff --git a/src/mongo/db/commands/shutdown_d.cpp b/src/mongo/db/commands/shutdown_d.cpp index 67e5572125d..320c028dcb1 100644 --- a/src/mongo/db/commands/shutdown_d.cpp +++ b/src/mongo/db/commands/shutdown_d.cpp @@ -27,8 +27,6 @@ * it in the license file. */ -#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kCommand - #include "mongo/platform/basic.h" #include @@ -36,7 +34,6 @@ #include "mongo/db/commands/shutdown.h" #include "mongo/db/index_builds_coordinator.h" #include "mongo/db/repl/replication_coordinator.h" -#include "mongo/util/log.h" namespace mongo { namespace { @@ -63,11 +60,17 @@ public: timeoutSecs = cmdObj["timeoutSecs"].numberLong(); } + // This code may race with a new index build starting up. We may get 0 active index builds + // from the IndexBuildsCoordinator shutdown to proceed, but there is nothing to prevent a + // new index build from starting after that check. if (!force) { auto indexBuildsCoord = IndexBuildsCoordinator::get(opCtx); auto numIndexBuilds = indexBuildsCoord->getActiveIndexBuildCount(opCtx); - log() << "Index builds in progress while processing shutdown command: " - << numIndexBuilds; + uassert(ErrorCodes::ConflictingOperationInProgress, + str::stream() << "Index builds in progress while processing shutdown command " + "without {force: true}: " + << numIndexBuilds, + numIndexBuilds == 0U); } try {