diff options
author | Louis Williams <louis.williams@mongodb.com> | 2020-12-07 16:24:53 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-12-09 18:03:35 +0000 |
commit | 5b5f27e90884b12748b2527e1263b04981bad2af (patch) | |
tree | 8ddf8df59a35a5fd2c4271b32682b1ea25896c14 /src/mongo/db/index_builds_coordinator.cpp | |
parent | 4ba4acbe4a16e18af4b59eed59686902806b8f49 (diff) | |
download | mongo-5b5f27e90884b12748b2527e1263b04981bad2af.tar.gz |
SERVER-52563 Ensure index builds collect resource consumption metrics when interrupted
Diffstat (limited to 'src/mongo/db/index_builds_coordinator.cpp')
-rw-r--r-- | src/mongo/db/index_builds_coordinator.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp index 72e37ca7def..1c6196afc6b 100644 --- a/src/mongo/db/index_builds_coordinator.cpp +++ b/src/mongo/db/index_builds_coordinator.cpp @@ -2079,15 +2079,28 @@ void IndexBuildsCoordinator::_runIndexBuildInner( return; } - { - // If the index build has already been cleaned-up because it encountered an error at - // commit-time, there is no work to do. This is the most routine case, since index - // constraint checking happens at commit-time for index builds. - if (replState->isAborted()) { - uassertStatusOK(status); + if (status.code() == ErrorCodes::IndexBuildAborted) { + auto replCoord = repl::ReplicationCoordinator::get(opCtx); + auto& collector = ResourceConsumption::MetricsCollector::get(opCtx); + + // Only report metrics for index builds on primaries. We are being aborted by an external + // thread, thus we can assume it is holding the RSTL while waiting for us to exit. + bool wasCollecting = collector.endScopedCollecting(); + bool isPrimary = replCoord->canAcceptWritesFor_UNSAFE( + opCtx, {replState->dbName, replState->collectionUUID}); + if (isPrimary && wasCollecting && ResourceConsumption::isMetricsAggregationEnabled()) { + ResourceConsumption::get(opCtx).merge( + opCtx, collector.getDbName(), collector.getMetrics()); } } + // If the index build has already been cleaned-up because it encountered an error at + // commit-time, there is no work to do. This is the most routine case, since index + // constraint checking happens at commit-time for index builds. + if (replState->isAborted()) { + uassertStatusOK(status); + } + // We do not hold a collection lock here, but we are protected against the collection being // dropped while the index build is still registered for the collection -- until abortIndexBuild // is called. The collection can be renamed, but it is OK for the name to be stale just for @@ -2450,13 +2463,9 @@ IndexBuildsCoordinator::CommitResult IndexBuildsCoordinator::_insertKeysFromSide // While we are still holding the RSTL and before returning, ensure the metrics collected for // this index build are attributed to the primary that commits or aborts the index build. auto metricsGuard = makeGuard([&]() { - if (!isPrimary) { - return; - } - auto& collector = ResourceConsumption::MetricsCollector::get(opCtx); bool wasCollecting = collector.endScopedCollecting(); - if (!wasCollecting || !ResourceConsumption::isMetricsAggregationEnabled()) { + if (!isPrimary || !wasCollecting || !ResourceConsumption::isMetricsAggregationEnabled()) { return; } |