mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 09:06:21 +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:
parent
fad0f06911
commit
fab432034d
@ -37,23 +37,16 @@ IndexBuildTest.waitForIndexBuildToStart(testDB, coll.getName(), 'a_1');
|
|||||||
// Stop the primary using the shutdown command without {force: true}.
|
// Stop the primary using the shutdown command without {force: true}.
|
||||||
try {
|
try {
|
||||||
assert.commandFailedWithCode(primary.adminCommand({shutdown: 1, force: false}),
|
assert.commandFailedWithCode(primary.adminCommand({shutdown: 1, force: false}),
|
||||||
ErrorCodes.ExceededTimeLimit);
|
ErrorCodes.ConflictingOperationInProgress);
|
||||||
} finally {
|
} finally {
|
||||||
IndexBuildTest.resumeIndexBuilds(primary);
|
IndexBuildTest.resumeIndexBuilds(primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexBuildTest.waitForIndexBuildToStop(testDB);
|
IndexBuildTest.waitForIndexBuildToStop(testDB);
|
||||||
|
|
||||||
const exitCode = createIdx({checkExitSuccess: false});
|
createIdx();
|
||||||
assert.neq(0, exitCode, 'expected shell to exit abnormally due to index build being terminated');
|
|
||||||
|
|
||||||
if (IndexBuildTest.supportsTwoPhaseIndexBuild(primary)) {
|
IndexBuildTest.assertIndexes(coll, 2, ['_id_', 'a_1']);
|
||||||
// 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_']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This runs the shutdown command without {force: true} with additional handling for expected
|
// This runs the shutdown command without {force: true} with additional handling for expected
|
||||||
// network errors when the command succeeds.
|
// network errors when the command succeeds.
|
||||||
|
@ -40,7 +40,8 @@ IndexBuildTest.waitForIndexBuildToStart(secondaryDB, secondaryColl.getName(), 'a
|
|||||||
|
|
||||||
// Stop the secondary using the shutdown command without {force: true}.
|
// Stop the secondary using the shutdown command without {force: true}.
|
||||||
try {
|
try {
|
||||||
// assert.commandWorked(secondary.adminCommand({shutdown: 1, force: false}));
|
assert.commandFailedWithCode(secondary.adminCommand({shutdown: 1, force: false}),
|
||||||
|
ErrorCodes.ConflictingOperationInProgress);
|
||||||
} finally {
|
} finally {
|
||||||
IndexBuildTest.resumeIndexBuilds(secondary);
|
IndexBuildTest.resumeIndexBuilds(secondary);
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,6 @@
|
|||||||
* it in the license file.
|
* it in the license file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kCommand
|
|
||||||
|
|
||||||
#include "mongo/platform/basic.h"
|
#include "mongo/platform/basic.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -36,7 +34,6 @@
|
|||||||
#include "mongo/db/commands/shutdown.h"
|
#include "mongo/db/commands/shutdown.h"
|
||||||
#include "mongo/db/index_builds_coordinator.h"
|
#include "mongo/db/index_builds_coordinator.h"
|
||||||
#include "mongo/db/repl/replication_coordinator.h"
|
#include "mongo/db/repl/replication_coordinator.h"
|
||||||
#include "mongo/util/log.h"
|
|
||||||
|
|
||||||
namespace mongo {
|
namespace mongo {
|
||||||
namespace {
|
namespace {
|
||||||
@ -63,11 +60,17 @@ public:
|
|||||||
timeoutSecs = cmdObj["timeoutSecs"].numberLong();
|
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) {
|
if (!force) {
|
||||||
auto indexBuildsCoord = IndexBuildsCoordinator::get(opCtx);
|
auto indexBuildsCoord = IndexBuildsCoordinator::get(opCtx);
|
||||||
auto numIndexBuilds = indexBuildsCoord->getActiveIndexBuildCount(opCtx);
|
auto numIndexBuilds = indexBuildsCoord->getActiveIndexBuildCount(opCtx);
|
||||||
log() << "Index builds in progress while processing shutdown command: "
|
uassert(ErrorCodes::ConflictingOperationInProgress,
|
||||||
<< numIndexBuilds;
|
str::stream() << "Index builds in progress while processing shutdown command "
|
||||||
|
"without {force: true}: "
|
||||||
|
<< numIndexBuilds,
|
||||||
|
numIndexBuilds == 0U);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user