Skip to content

Commit 2bc1da6

Browse files
committed
SERVER-41986 add handling of unfinished indexes due to shutdown
1 parent 47c4ce9 commit 2bc1da6

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/mongo/db/index_builds_coordinator.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,11 +806,20 @@ void IndexBuildsCoordinator::_runIndexBuildInner(OperationContext* opCtx,
806806
status = ex.toStatus();
807807
}
808808

809-
if (replSetAndNotPrimary && status == ErrorCodes::InterruptedAtShutdown) {
809+
if (status == ErrorCodes::InterruptedAtShutdown) {
810810
// Leave it as-if kill -9 happened. This will be handled on restart.
811811
_indexBuildsManager.interruptIndexBuild(opCtx, replState->buildUUID, "shutting down");
812-
replState->stats.numIndexesAfter = replState->stats.numIndexesBefore;
813-
status = Status::OK();
812+
813+
// On secondaries, a shutdown interruption status is part of normal operation and
814+
// should be suppressed, unlike other errors which should be raised to the administrator's
815+
// attention via a server crash. The server will attempt to recover the index build during
816+
// the next startup.
817+
// On primary and standalone nodes, the failed index build will not be replicated so it is
818+
// okay to propagate the shutdown error to the client.
819+
if (replSetAndNotPrimary) {
820+
replState->stats.numIndexesAfter = replState->stats.numIndexesBefore;
821+
status = Status::OK();
822+
}
814823
} else if (IndexBuildProtocol::kTwoPhase == replState->protocol) {
815824
// TODO (SERVER-40807): disabling the following code for the v4.2 release so it does not
816825
// have downstream impact.

0 commit comments

Comments
 (0)