diff options
Diffstat (limited to 'src/mongo/db/commands/create_indexes.cpp')
-rw-r--r-- | src/mongo/db/commands/create_indexes.cpp | 78 |
1 files changed, 36 insertions, 42 deletions
diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp index 6be62b121f1..9dbb6a8cef7 100644 --- a/src/mongo/db/commands/create_indexes.cpp +++ b/src/mongo/db/commands/create_indexes.cpp @@ -585,24 +585,47 @@ CreateIndexesReply runCreateIndexesWithCoordinator(OperationContext* opCtx, // Throws on error. try { stats = buildIndexFuture.get(opCtx); - } catch (const ExceptionForCat<ErrorCategory::Interruption>& interruptionEx) { + } catch (const ExceptionForCat<ErrorCategory::NotPrimaryError>& ex) { + LOGV2(20444, + "Index build: received interrupt signal due to change in replication state", + "buildUUID"_attr = buildUUID, + "ex"_attr = ex); + + // If this node is no longer a primary, the index build will continue to run in the + // background and will complete when this node receives a commitIndexBuild oplog + // entry from the new primary. + if (IndexBuildProtocol::kTwoPhase == protocol) { + shouldContinueInBackground = true; + throw; + } + + std::string abortReason(str::stream() << "Index build aborted: " << buildUUID << ": " + << ex.toString()); + if (indexBuildsCoord->abortIndexBuildByBuildUUID( + opCtx, buildUUID, IndexBuildAction::kPrimaryAbort, abortReason)) { + LOGV2(20446, + "Index build: aborted due to NotPrimary error", + "buildUUID"_attr = buildUUID); + } else { + // The index build may already be in the midst of tearing down. + LOGV2(5010501, + "Index build: failed to abort index build", + "buildUUID"_attr = buildUUID); + } + + throw; + } catch (const DBException& ex) { + if (!opCtx->isKillPending()) { + throw; + } + LOGV2(20441, "Index build: received interrupt signal", "buildUUID"_attr = buildUUID, - "signal"_attr = interruptionEx); + "signal"_attr = ex); hangBeforeIndexBuildAbortOnInterrupt.pauseWhileSet(); - if (IndexBuildProtocol::kTwoPhase == protocol) { - // If this node is no longer a primary, the index build will continue to run in the - // background and will complete when this node receives a commitIndexBuild oplog - // entry from the new primary. - if (ErrorCodes::InterruptedDueToReplStateChange == interruptionEx.code()) { - shouldContinueInBackground = true; - throw; - } - } - // It is unclear whether the interruption originated from the current opCtx instance // for the createIndexes command or that the IndexBuildsCoordinator task was interrupted // independently of this command invocation. We'll defensively abort the index build @@ -616,7 +639,7 @@ CreateIndexesReply runCreateIndexesWithCoordinator(OperationContext* opCtx, const auto abortCtx = cc().makeOperationContext(); std::string abortReason(str::stream() << "Index build aborted: " << buildUUID - << ": " << interruptionEx.toString()); + << ": " << ex.toString()); if (indexBuildsCoord->abortIndexBuildByBuildUUID( abortCtx.get(), buildUUID, IndexBuildAction::kPrimaryAbort, abortReason)) { LOGV2(20443, @@ -630,35 +653,6 @@ CreateIndexesReply runCreateIndexesWithCoordinator(OperationContext* opCtx, } } throw; - } catch (const ExceptionForCat<ErrorCategory::NotPrimaryError>& ex) { - LOGV2(20444, - "Index build: received interrupt signal due to change in replication state", - "buildUUID"_attr = buildUUID, - "ex"_attr = ex); - - // If this node is no longer a primary, the index build will continue to run in the - // background and will complete when this node receives a commitIndexBuild oplog - // entry from the new primary. - if (IndexBuildProtocol::kTwoPhase == protocol) { - shouldContinueInBackground = true; - throw; - } - - std::string abortReason(str::stream() << "Index build aborted: " << buildUUID << ": " - << ex.toString()); - if (indexBuildsCoord->abortIndexBuildByBuildUUID( - opCtx, buildUUID, IndexBuildAction::kPrimaryAbort, abortReason)) { - LOGV2(20446, - "Index build: aborted due to NotPrimary error", - "buildUUID"_attr = buildUUID); - } else { - // The index build may already be in the midst of tearing down. - LOGV2(5010501, - "Index build: failed to abort index build", - "buildUUID"_attr = buildUUID); - } - - throw; } LOGV2(20447, "Index build: completed", "buildUUID"_attr = buildUUID); |