diff options
author | Gabriel Marks <gabriel.marks@mongodb.com> | 2022-04-11 14:31:11 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-04-11 20:33:45 +0000 |
commit | 25377181476e4140c970afa5b018f9b4fcc951e8 (patch) | |
tree | 90fba94f67a0b140b0b03fae5d733a79800fea43 /src/mongo/db/index_builds_coordinator_mongod.cpp | |
parent | 6cbfcc07937a9bc2f4ea20e242a912fd5868647d (diff) | |
download | mongo-25377181476e4140c970afa5b018f9b4fcc951e8.tar.gz |
SERVER-65116 Abort active index builds when write blocking is enabled
Diffstat (limited to 'src/mongo/db/index_builds_coordinator_mongod.cpp')
-rw-r--r-- | src/mongo/db/index_builds_coordinator_mongod.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/mongo/db/index_builds_coordinator_mongod.cpp b/src/mongo/db/index_builds_coordinator_mongod.cpp index 1b98e9c5f67..efa563e6b03 100644 --- a/src/mongo/db/index_builds_coordinator_mongod.cpp +++ b/src/mongo/db/index_builds_coordinator_mongod.cpp @@ -46,6 +46,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/repl/tenant_migration_access_blocker_util.h" #include "mongo/db/s/forwardable_operation_metadata.h" +#include "mongo/db/s/global_user_write_block_state.h" #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/service_context.h" #include "mongo/db/stats/resource_consumption_metrics.h" @@ -163,6 +164,12 @@ IndexBuildsCoordinatorMongod::_startIndexBuild(OperationContext* opCtx, const boost::optional<ResumeIndexInfo>& resumeInfo) { const NamespaceStringOrUUID nssOrUuid{dbName, collectionUUID}; + auto writeBlockState = GlobalUserWriteBlockState::get(opCtx); + + invariant(!opCtx->lockState()->isRSTLExclusive(), buildUUID.toString()); + + const auto nss = CollectionCatalog::get(opCtx)->resolveNamespaceStringOrUUID(opCtx, nssOrUuid); + { // Only operations originating from user connections need to wait while there are more than // 'maxNumActiveUserIndexBuilds' index builds currently running. @@ -185,10 +192,11 @@ IndexBuildsCoordinatorMongod::_startIndexBuild(OperationContext* opCtx, replCoord->canAcceptWritesFor(opCtx, nssOrUuid)); } - // The check here catches empty index builds and also allows us to stop index + // The checks here catch empty index builds and also allow us to stop index // builds before waiting for throttling. It may race with the abort at the start // of migration so we do check again later. uassertStatusOK(tenant_migration_access_blocker::checkIfCanBuildIndex(opCtx, dbName)); + uassertStatusOK(writeBlockState->checkIfIndexBuildAllowedToStart(opCtx, nss)); stdx::unique_lock<Latch> lk(_throttlingMutex); bool messageLogged = false; @@ -273,13 +281,21 @@ IndexBuildsCoordinatorMongod::_startIndexBuild(OperationContext* opCtx, invariant(_getIndexBuild(buildUUID))); return migrationStatus; } + + auto buildBlockedStatus = writeBlockState->checkIfIndexBuildAllowedToStart(opCtx, nss); + if (!buildBlockedStatus.isOK()) { + LOGV2(6511603, + "Aborted index build due to user index builds being blocked", + "error"_attr = buildBlockedStatus, + "buildUUID"_attr = buildUUID, + "collectionUUID"_attr = collectionUUID); + activeIndexBuilds.unregisterIndexBuild(&_indexBuildsManager, + invariant(_getIndexBuild(buildUUID))); + return buildBlockedStatus; + } } } - invariant(!opCtx->lockState()->isRSTLExclusive(), buildUUID.toString()); - - const auto nss = CollectionCatalog::get(opCtx)->resolveNamespaceStringOrUUID(opCtx, nssOrUuid); - auto& oss = OperationShardingState::get(opCtx); // Task in thread pool should have similar CurOp representation to the caller so that it can be |