0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 00:56:44 +01:00

SERVER-43988 shutdown with {force: false} should refuse to shut down the server if there is an index build in progress

This commit is contained in:
Benety Goh 2020-01-20 08:23:49 -05:00 committed by Evergreen Agent
parent fad0f06911
commit fab432034d
3 changed files with 13 additions and 16 deletions

View File

@ -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.

View File

@ -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);
}

View File

@ -27,8 +27,6 @@
* it in the license file.
*/
#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kCommand
#include "mongo/platform/basic.h"
#include <string>
@ -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 {