diff options
-rw-r--r-- | src/mongo/db/active_index_builds.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator.cpp | 59 | ||||
-rw-r--r-- | src/mongo/db/repl_index_build_state.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/repl_index_build_state.h | 4 |
4 files changed, 22 insertions, 50 deletions
diff --git a/src/mongo/db/active_index_builds.cpp b/src/mongo/db/active_index_builds.cpp index 70dd6d56057..e9041058530 100644 --- a/src/mongo/db/active_index_builds.cpp +++ b/src/mongo/db/active_index_builds.cpp @@ -174,9 +174,7 @@ std::vector<std::shared_ptr<ReplIndexBuildState>> ActiveIndexBuilds::_filterInde void ActiveIndexBuilds::awaitNoBgOpInProgForDb(OperationContext* opCtx, const DatabaseName& dbName) { stdx::unique_lock<Latch> lk(_mutex); - auto indexBuildFilter = [dbName](const auto& replState) { - return dbName.toStringWithTenantId() == replState.dbName; - }; + auto indexBuildFilter = [dbName](const auto& replState) { return dbName == replState.dbName; }; auto pred = [&, this]() { auto dbIndexBuilds = _filterIndexBuilds_inlock(lk, indexBuildFilter); return dbIndexBuilds.empty(); diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp index 4e0eb2f7451..8ac5864889e 100644 --- a/src/mongo/db/index_builds_coordinator.cpp +++ b/src/mongo/db/index_builds_coordinator.cpp @@ -630,7 +630,7 @@ Status IndexBuildsCoordinator::_startIndexBuildForRecovery(OperationContext* opC } auto replIndexBuildState = std::make_shared<ReplIndexBuildState>( - buildUUID, collection->uuid(), nss.dbName().toStringWithTenantId(), specs, protocol); + buildUUID, collection->uuid(), nss.dbName(), specs, protocol); Status status = activeIndexBuilds.registerIndexBuild(replIndexBuildState); if (!status.isOK()) { @@ -714,7 +714,7 @@ Status IndexBuildsCoordinator::_setUpResumeIndexBuild(OperationContext* opCtx, auto protocol = IndexBuildProtocol::kTwoPhase; auto replIndexBuildState = std::make_shared<ReplIndexBuildState>( - buildUUID, collection->uuid(), dbName.toStringWithTenantId(), specs, protocol); + buildUUID, collection->uuid(), dbName, specs, protocol); Status status = activeIndexBuilds.registerIndexBuild(replIndexBuildState); if (!status.isOK()) { @@ -778,9 +778,7 @@ void IndexBuildsCoordinator::abortDatabaseIndexBuilds(OperationContext* opCtx, "reason"_attr = reason); auto builds = [&]() -> std::vector<std::shared_ptr<ReplIndexBuildState>> { - auto indexBuildFilter = [=](const auto& replState) { - return dbName.toStringWithTenantId() == replState.dbName; - }; + auto indexBuildFilter = [=](const auto& replState) { return dbName == replState.dbName; }; return activeIndexBuilds.filterIndexBuilds(indexBuildFilter); }(); for (auto replState : builds) { @@ -809,7 +807,8 @@ void IndexBuildsCoordinator::abortTenantIndexBuilds(OperationContext* opCtx, auto indexBuildFilter = [=](const auto& replState) { // Abort *all* index builds at the start of shard merge. return protocol == MigrationProtocolEnum::kShardMerge || - repl::ClonerUtils::isDatabaseForTenant(replState.dbName, tenantId); + repl::ClonerUtils::isDatabaseForTenant(replState.dbName.toStringWithTenantId(), + tenantId); }; return activeIndexBuilds.filterIndexBuilds(indexBuildFilter); }(); @@ -1244,10 +1243,7 @@ bool IndexBuildsCoordinator::abortIndexBuildByBuildUUID(OperationContext* opCtx, LOGV2(4656010, "Attempting to abort index build", "buildUUID"_attr = replState->buildUUID); const NamespaceStringOrUUID dbAndUUID(replState->dbName, replState->collectionUUID); - // TODO SERVER-67437 Once ReplIndexBuildState holds DatabaseName, use dbName directly for - // lock - DatabaseName dbName(boost::none, replState->dbName); - Lock::DBLock dbLock(opCtx, dbName, MODE_IX); + Lock::DBLock dbLock(opCtx, replState->dbName, MODE_IX); if (IndexBuildProtocol::kSinglePhase == replState->protocol) { // Unlock RSTL to avoid deadlocks with prepare conflicts and state transitions caused by @@ -1652,9 +1648,7 @@ bool IndexBuildsCoordinator::noIndexBuildInProgress() const { } int IndexBuildsCoordinator::numInProgForDb(const DatabaseName& dbName) const { - auto indexBuildFilter = [dbName](const auto& replState) { - return dbName.toStringWithTenantId() == replState.dbName; - }; + auto indexBuildFilter = [dbName](const auto& replState) { return dbName == replState.dbName; }; auto dbIndexBuilds = activeIndexBuilds.filterIndexBuilds(indexBuildFilter); return int(dbIndexBuilds.size()); } @@ -1704,7 +1698,7 @@ void IndexBuildsCoordinator::assertNoIndexBuildInProgForCollection( void IndexBuildsCoordinator::assertNoBgOpInProgForDb(const DatabaseName& dbName) const { boost::optional<UUID> firstIndexBuildUUID; auto indexBuilds = activeIndexBuilds.filterIndexBuilds([&](const auto& replState) { - auto isIndexBuildForCollection = (dbName.toStringWithTenantId() == replState.dbName); + auto isIndexBuildForCollection = (dbName == replState.dbName); if (isIndexBuildForCollection && !firstIndexBuildUUID) { firstIndexBuildUUID = replState.buildUUID; }; @@ -1978,7 +1972,7 @@ IndexBuildsCoordinator::_filterSpecsAndRegisterBuild(OperationContext* opCtx, } auto replIndexBuildState = std::make_shared<ReplIndexBuildState>( - buildUUID, collectionUUID, dbName.toStringWithTenantId(), filteredSpecs, protocol); + buildUUID, collectionUUID, dbName, filteredSpecs, protocol); replIndexBuildState->stats.numIndexesBefore = getNumIndexesTotal(opCtx, collection.get()); auto status = activeIndexBuilds.registerIndexBuild(replIndexBuildState); @@ -2247,10 +2241,7 @@ void IndexBuildsCoordinator::_cleanUpSinglePhaseAfterFailure( runOnAlternateContext( opCtx, "self-abort", [this, replState, status](OperationContext* abortCtx) { ShouldNotConflictWithSecondaryBatchApplicationBlock noConflict(abortCtx->lockState()); - // TODO SERVER-67437 Once ReplIndexBuildState holds DatabaseName, use dbName directly - // for lock - DatabaseName dbName(boost::none, replState->dbName); - Lock::DBLock dbLock(abortCtx, dbName, MODE_IX); + Lock::DBLock dbLock(abortCtx, replState->dbName, MODE_IX); // Unlock RSTL to avoid deadlocks with prepare conflicts and state transitions caused by // taking a strong collection lock. See SERVER-42621. @@ -2284,10 +2275,7 @@ void IndexBuildsCoordinator::_cleanUpTwoPhaseAfterFailure( // Take RSTL (implicitly by DBLock) to observe and prevent replication state from // changing. - // TODO SSERVER-67437 Once ReplIndexBuildState holds DatabaseName, use dbName directly - // for lock - DatabaseName dbName(boost::none, replState->dbName); - Lock::DBLock dbLock(abortCtx, dbName, MODE_IX); + Lock::DBLock dbLock(abortCtx, replState->dbName, MODE_IX); // Index builds may not fail on secondaries. If a primary replicated an abortIndexBuild // oplog entry, then this index build would have received an IndexBuildAborted error @@ -2564,10 +2552,7 @@ void IndexBuildsCoordinator::_scanCollectionAndInsertSortedKeysIntoIndex( // if it waited. _awaitLastOpTimeBeforeInterceptorsMajorityCommitted(opCtx, replState); - // TODO SERVER-67437 Once ReplIndexBuildState holds DatabaseName, use dbName directly for - // lock - DatabaseName dbName(boost::none, replState->dbName); - Lock::DBLock autoDb(opCtx, dbName, MODE_IX); + Lock::DBLock autoDb(opCtx, replState->dbName, MODE_IX); const NamespaceStringOrUUID dbAndUUID(replState->dbName, replState->collectionUUID); Lock::CollectionLock collLock(opCtx, dbAndUUID, MODE_IX); @@ -2586,10 +2571,7 @@ void IndexBuildsCoordinator::_scanCollectionAndInsertSortedKeysIntoIndex( void IndexBuildsCoordinator::_insertSortedKeysIntoIndexForResume( OperationContext* opCtx, std::shared_ptr<ReplIndexBuildState> replState) { { - // TODO SERVER-67437 Once ReplIndexBuildState holds DatabaseName, use dbName directly for - // lock - DatabaseName dbName(boost::none, replState->dbName); - Lock::DBLock autoDb(opCtx, dbName, MODE_IX); + Lock::DBLock autoDb(opCtx, replState->dbName, MODE_IX); const NamespaceStringOrUUID dbAndUUID(replState->dbName, replState->collectionUUID); Lock::CollectionLock collLock(opCtx, dbAndUUID, MODE_IX); @@ -2630,10 +2612,7 @@ void IndexBuildsCoordinator::_insertKeysFromSideTablesWithoutBlockingWrites( // Perform the first drain while holding an intent lock. const NamespaceStringOrUUID dbAndUUID(replState->dbName, replState->collectionUUID); { - // TODO SERVER-67437 Once ReplIndexBuildState holds DatabaseName, use dbName directly for - // lock - DatabaseName dbName(boost::none, replState->dbName); - Lock::DBLock autoDb(opCtx, dbName, MODE_IX); + Lock::DBLock autoDb(opCtx, replState->dbName, MODE_IX); Lock::CollectionLock collLock(opCtx, dbAndUUID, MODE_IX); uassertStatusOK(_indexBuildsManager.drainBackgroundWrites( @@ -2658,10 +2637,7 @@ void IndexBuildsCoordinator::_insertKeysFromSideTablesBlockingWrites( const NamespaceStringOrUUID dbAndUUID(replState->dbName, replState->collectionUUID); // Perform the second drain while stopping writes on the collection. { - // TODO SERVER-67437 Once ReplIndexBuildState holds DatabaseName, use dbName directly for - // lock - DatabaseName dbName(boost::none, replState->dbName); - Lock::DBLock autoDb(opCtx, dbName, MODE_IX); + Lock::DBLock autoDb(opCtx, replState->dbName, MODE_IX); // Unlock RSTL to avoid deadlocks with prepare conflicts and state transitions. See // SERVER-42621. @@ -2697,10 +2673,7 @@ IndexBuildsCoordinator::CommitResult IndexBuildsCoordinator::_insertKeysFromSide hangIndexBuildBeforeCommit.pauseWhileSet(); } - // TODO SERVER-67437 Once ReplIndexBuildState holds DatabaseName, use dbName directly for - // lock - DatabaseName dbName(boost::none, replState->dbName); - AutoGetDb autoDb(opCtx, dbName, MODE_IX); + AutoGetDb autoDb(opCtx, replState->dbName, MODE_IX); // Unlock RSTL to avoid deadlocks with prepare conflicts and state transitions caused by waiting // for a a strong collection lock. See SERVER-42621. diff --git a/src/mongo/db/repl_index_build_state.cpp b/src/mongo/db/repl_index_build_state.cpp index 0a22f8a48f3..ecc932e9c96 100644 --- a/src/mongo/db/repl_index_build_state.cpp +++ b/src/mongo/db/repl_index_build_state.cpp @@ -131,7 +131,7 @@ void IndexBuildState::appendBuildInfo(BSONObjBuilder* builder) const { ReplIndexBuildState::ReplIndexBuildState(const UUID& indexBuildUUID, const UUID& collUUID, - const std::string& dbName, + const DatabaseName& dbName, const std::vector<BSONObj>& specs, IndexBuildProtocol protocol) : buildUUID(indexBuildUUID), @@ -348,7 +348,8 @@ ReplIndexBuildState::TryAbortResult ReplIndexBuildState::tryAbort(OperationConte opCtx->recoveryUnit()->getCommitTimestamp()); auto skipCheck = _shouldSkipIndexBuildStateTransitionCheck(opCtx); Status abortStatus = signalAction == IndexBuildAction::kTenantMigrationAbort - ? tenant_migration_access_blocker::checkIfCanBuildIndex(opCtx, dbName) + ? tenant_migration_access_blocker::checkIfCanBuildIndex(opCtx, + dbName.toStringWithTenantId()) : Status(ErrorCodes::IndexBuildAborted, reason); invariant(!abortStatus.isOK()); _indexBuildState.setState(IndexBuildState::kAborted, skipCheck, abortTimestamp, abortStatus); diff --git a/src/mongo/db/repl_index_build_state.h b/src/mongo/db/repl_index_build_state.h index fadcc67896b..43c97b242ec 100644 --- a/src/mongo/db/repl_index_build_state.h +++ b/src/mongo/db/repl_index_build_state.h @@ -239,7 +239,7 @@ class ReplIndexBuildState { public: ReplIndexBuildState(const UUID& indexBuildUUID, const UUID& collUUID, - const std::string& dbName, + const DatabaseName& dbName, const std::vector<BSONObj>& specs, IndexBuildProtocol protocol); @@ -388,7 +388,7 @@ public: // Identifies the database containing the index being built. Unlike collections, databases // cannot be renamed. - const std::string dbName; + const DatabaseName dbName; // The names of the indexes being built. const std::vector<std::string> indexNames; |