diff options
author | Christopher Caplinger <christopher.caplinger@mongodb.com> | 2022-12-06 21:55:41 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-12-06 23:46:16 +0000 |
commit | 0e9ed24634b025de8b7a0f275be7c9303ccc7b1c (patch) | |
tree | 783e535c4dc5de8688e2217f8baf0400dd1ad7c2 /src | |
parent | a76507d369a9f3ff7db64896763151b025072897 (diff) | |
download | mongo-0e9ed24634b025de8b7a0f275be7c9303ccc7b1c.tar.gz |
SERVER-71873: Update access blocker util methods to use DatabaseName
Diffstat (limited to 'src')
22 files changed, 92 insertions, 68 deletions
diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp index fc6c914e603..f2f06d1c9c7 100644 --- a/src/mongo/db/commands/run_aggregate.cpp +++ b/src/mongo/db/commands/run_aggregate.cpp @@ -487,7 +487,7 @@ void _adjustChangeStreamReadConcern(OperationContext* opCtx) { } // Wait for read concern again since we changed the original read concern. - uassertStatusOK(waitForReadConcern(opCtx, readConcernArgs, StringData(), true)); + uassertStatusOK(waitForReadConcern(opCtx, readConcernArgs, DatabaseName(), true)); setPrepareConflictBehaviorForReadConcern( opCtx, readConcernArgs, PrepareConflictBehavior::kIgnoreConflicts); } diff --git a/src/mongo/db/index_builds_coordinator_mongod.cpp b/src/mongo/db/index_builds_coordinator_mongod.cpp index 2f2c3f2d108..70d0965d490 100644 --- a/src/mongo/db/index_builds_coordinator_mongod.cpp +++ b/src/mongo/db/index_builds_coordinator_mongod.cpp @@ -197,8 +197,7 @@ IndexBuildsCoordinatorMongod::_startIndexBuild(OperationContext* opCtx, // 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.toStringWithTenantId())); + uassertStatusOK(tenant_migration_access_blocker::checkIfCanBuildIndex(opCtx, dbName)); uassertStatusOK(writeBlockState->checkIfIndexBuildAllowedToStart(opCtx, nss)); stdx::unique_lock<Latch> lk(_throttlingMutex); @@ -272,8 +271,8 @@ IndexBuildsCoordinatorMongod::_startIndexBuild(OperationContext* opCtx, } if (opCtx->getClient()->isFromUserConnection()) { - auto migrationStatus = tenant_migration_access_blocker::checkIfCanBuildIndex( - opCtx, dbName.toStringWithTenantId()); + auto migrationStatus = + tenant_migration_access_blocker::checkIfCanBuildIndex(opCtx, dbName); if (!migrationStatus.isOK()) { LOGV2(4886200, "Aborted index build before start due to tenant migration", diff --git a/src/mongo/db/op_observer/op_observer_impl.cpp b/src/mongo/db/op_observer/op_observer_impl.cpp index 2ea66354d30..e77718ab2fd 100644 --- a/src/mongo/db/op_observer/op_observer_impl.cpp +++ b/src/mongo/db/op_observer/op_observer_impl.cpp @@ -1912,7 +1912,7 @@ void OpObserverImpl::onUnpreparedTransactionCommit(OperationContext* opCtx, // migrated. We only need check the namespace of the first statement since a transaction's // statements must all be for the same tenant. tenant_migration_access_blocker::checkIfCanWriteOrThrow( - opCtx, statements->begin()->getNss().db(), oplogSlots.back().getTimestamp()); + opCtx, statements->begin()->getNss().dbName(), oplogSlots.back().getTimestamp()); if (MONGO_unlikely(hangAndFailUnpreparedCommitAfterReservingOplogSlot.shouldFail())) { hangAndFailUnpreparedCommitAfterReservingOplogSlot.pauseWhileSet(opCtx); @@ -1982,7 +1982,7 @@ void OpObserverImpl::onBatchedWriteCommit(OperationContext* opCtx) { // statements must all be for the same tenant. const auto& firstOpNss = batchedOps->getMutableOperationsForOpObserver()->begin()->getNss(); tenant_migration_access_blocker::checkIfCanWriteOrThrow( - opCtx, firstOpNss.db(), oplogSlots.back().getTimestamp()); + opCtx, firstOpNss.dbName(), oplogSlots.back().getTimestamp()); boost::optional<repl::ReplOperation::ImageBundle> noPrePostImage; diff --git a/src/mongo/db/read_concern.cpp b/src/mongo/db/read_concern.cpp index 85f33dd149e..30a7f9c502b 100644 --- a/src/mongo/db/read_concern.cpp +++ b/src/mongo/db/read_concern.cpp @@ -42,7 +42,7 @@ void setPrepareConflictBehaviorForReadConcern(OperationContext* opCtx, Status waitForReadConcern(OperationContext* opCtx, const repl::ReadConcernArgs& readConcernArgs, - StringData dbName, + const DatabaseName& dbName, bool allowAfterClusterTime) { static auto w = MONGO_WEAK_FUNCTION_DEFINITION(waitForReadConcern); return w(opCtx, readConcernArgs, dbName, allowAfterClusterTime); diff --git a/src/mongo/db/read_concern.h b/src/mongo/db/read_concern.h index 5767631864e..c1acc6f5d06 100644 --- a/src/mongo/db/read_concern.h +++ b/src/mongo/db/read_concern.h @@ -29,6 +29,7 @@ #pragma once +#include "mongo/db/database_name.h" #include "mongo/util/duration.h" namespace mongo { @@ -67,7 +68,7 @@ void setPrepareConflictBehaviorForReadConcern(OperationContext* opCtx, */ Status waitForReadConcern(OperationContext* opCtx, const repl::ReadConcernArgs& readConcernArgs, - StringData dbName, + const DatabaseName& dbName, bool allowAfterClusterTime); /* diff --git a/src/mongo/db/read_concern_mongod.cpp b/src/mongo/db/read_concern_mongod.cpp index 536dbec1741..3a286140ca6 100644 --- a/src/mongo/db/read_concern_mongod.cpp +++ b/src/mongo/db/read_concern_mongod.cpp @@ -110,7 +110,9 @@ private: /** * Schedule a write via appendOplogNote command to the primary of this replica set. */ -Status makeNoopWriteIfNeeded(OperationContext* opCtx, LogicalTime clusterTime, StringData dbName) { +Status makeNoopWriteIfNeeded(OperationContext* opCtx, + LogicalTime clusterTime, + const DatabaseName& dbName) { repl::ReplicationCoordinator* const replCoord = repl::ReplicationCoordinator::get(opCtx); invariant(replCoord->isReplEnabled()); @@ -281,7 +283,7 @@ void setPrepareConflictBehaviorForReadConcernImpl(OperationContext* opCtx, Status waitForReadConcernImpl(OperationContext* opCtx, const repl::ReadConcernArgs& readConcernArgs, - StringData dbName, + const DatabaseName& dbName, bool allowAfterClusterTime) { // If we are in a direct client within a transaction, then we may be holding locks, so it is // illegal to wait for read concern. This is fine, since the outer operation should have handled diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index e9a8704792d..ea7de687dac 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -383,7 +383,8 @@ void _logOpsInner(OperationContext* opCtx, // index build on the donor after the blockTimestamp, plus if an index build fails to commit due // to TenantMigrationConflict, we need to be able to abort the index build and clean up. if (!isAbortIndexBuild) { - tenant_migration_access_blocker::checkIfCanWriteOrThrow(opCtx, nss.db(), timestamps.back()); + tenant_migration_access_blocker::checkIfCanWriteOrThrow( + opCtx, nss.dbName(), timestamps.back()); } Status result = insertDocumentsForOplog(opCtx, oplogCollection, records, timestamps); diff --git a/src/mongo/db/repl/tenant_file_importer_service.cpp b/src/mongo/db/repl/tenant_file_importer_service.cpp index b200ec7df68..060baba872a 100644 --- a/src/mongo/db/repl/tenant_file_importer_service.cpp +++ b/src/mongo/db/repl/tenant_file_importer_service.cpp @@ -96,7 +96,7 @@ void importCopiedFiles(OperationContext* opCtx, const UUID& migrationId) { auto metadatas = wiredTigerRollbackToStableAndGetMetadata(opCtx, tempWTDirectory.string()); for (auto&& m : metadatas) { - auto tenantId = parseTenantIdFromDB(m.ns.db()); + const auto tenantId = parseTenantIdFromDB(m.ns.toStringWithTenantId()); if (tenantId == boost::none) { continue; } diff --git a/src/mongo/db/repl/tenant_migration_access_blocker_registry.cpp b/src/mongo/db/repl/tenant_migration_access_blocker_registry.cpp index 4f685c814a4..4ffafc7e440 100644 --- a/src/mongo/db/repl/tenant_migration_access_blocker_registry.cpp +++ b/src/mongo/db/repl/tenant_migration_access_blocker_registry.cpp @@ -210,10 +210,11 @@ void TenantMigrationAccessBlockerRegistry::removeAll(MtabType type) { } boost::optional<MtabPair> TenantMigrationAccessBlockerRegistry::getAccessBlockersForDbName( - StringData dbName) { + const DatabaseName& dbName) { stdx::lock_guard<Latch> lg(_mutex); auto donorAccessBlocker = _getAllTenantDonorAccessBlocker(lg, dbName); - auto tenantId = tenant_migration_access_blocker::parseTenantIdFromDB(dbName); + const auto tenantId = + tenant_migration_access_blocker::parseTenantIdFromDB(dbName.toStringWithTenantId()); if (!tenantId && donorAccessBlocker) { return MtabPair{donorAccessBlocker}; @@ -243,8 +244,8 @@ boost::optional<MtabPair> TenantMigrationAccessBlockerRegistry::getAccessBlocker } std::shared_ptr<TenantMigrationAccessBlocker> -TenantMigrationAccessBlockerRegistry::getTenantMigrationAccessBlockerForDbName(StringData dbName, - MtabType type) { +TenantMigrationAccessBlockerRegistry::getTenantMigrationAccessBlockerForDbName( + const DatabaseName& dbName, MtabType type) { auto mtabPair = getAccessBlockersForDbName(dbName); if (!mtabPair) { return nullptr; @@ -283,10 +284,10 @@ TenantMigrationAccessBlockerRegistry::getAccessBlockerForMigration( } std::shared_ptr<TenantMigrationDonorAccessBlocker> -TenantMigrationAccessBlockerRegistry::_getAllTenantDonorAccessBlocker(WithLock lk, - StringData dbName) const { +TenantMigrationAccessBlockerRegistry::_getAllTenantDonorAccessBlocker( + WithLock lk, const DatabaseName& dbName) const { // No-op oplog entries, e.g. for linearizable reads, use namespace "". - bool isInternal = (dbName == "" || NamespaceString(dbName).isOnInternalDb()); + bool isInternal = (dbName.db() == "" || NamespaceString(dbName).isOnInternalDb()); if (isInternal) { return nullptr; } diff --git a/src/mongo/db/repl/tenant_migration_access_blocker_registry.h b/src/mongo/db/repl/tenant_migration_access_blocker_registry.h index f08f506098b..982ebb199dc 100644 --- a/src/mongo/db/repl/tenant_migration_access_blocker_registry.h +++ b/src/mongo/db/repl/tenant_migration_access_blocker_registry.h @@ -146,7 +146,8 @@ public: * Returns the first 'DonorRecipientAccessBlockerPair' it finds whose 'tenantId' is a prefix for * 'dbName'. */ - boost::optional<DonorRecipientAccessBlockerPair> getAccessBlockersForDbName(StringData dbName); + boost::optional<DonorRecipientAccessBlockerPair> getAccessBlockersForDbName( + const DatabaseName& dbName); /** @@ -161,7 +162,7 @@ public: * 'dbName' and is of the requested type. */ std::shared_ptr<TenantMigrationAccessBlocker> getTenantMigrationAccessBlockerForDbName( - StringData dbName, TenantMigrationAccessBlocker::BlockerType type); + const DatabaseName& dbName, TenantMigrationAccessBlocker::BlockerType type); /** * Searches through TenantMigrationAccessBlockers and @@ -221,7 +222,7 @@ private: WithLock) const; std::shared_ptr<TenantMigrationDonorAccessBlocker> _getAllTenantDonorAccessBlocker( - WithLock, StringData dbName) const; + WithLock, const DatabaseName& dbName) const; mutable Mutex _mutex = MONGO_MAKE_LATCH("TenantMigrationAccessBlockerRegistry::_mutex"); diff --git a/src/mongo/db/repl/tenant_migration_access_blocker_util.cpp b/src/mongo/db/repl/tenant_migration_access_blocker_util.cpp index 27c59a092c4..fc5e62197cf 100644 --- a/src/mongo/db/repl/tenant_migration_access_blocker_util.cpp +++ b/src/mongo/db/repl/tenant_migration_access_blocker_util.cpp @@ -172,11 +172,12 @@ TenantMigrationDonorDocument parseDonorStateDocument(const BSONObj& doc) { return donorStateDoc; } -SemiFuture<void> checkIfCanReadOrBlock(OperationContext* opCtx, const OpMsgRequest& request) { +SemiFuture<void> checkIfCanReadOrBlock(OperationContext* opCtx, + const DatabaseName& dbName, + const OpMsgRequest& request) { // We need to check both donor and recipient access blockers in the case where two // migrations happen back-to-back before the old recipient state (from the first // migration) is garbage collected. - auto dbName = request.getDatabase(); auto& blockerRegistry = TenantMigrationAccessBlockerRegistry::get(opCtx->getServiceContext()); auto mtabPair = blockerRegistry.getAccessBlockersForDbName(dbName); @@ -278,7 +279,7 @@ SemiFuture<void> checkIfCanReadOrBlock(OperationContext* opCtx, const OpMsgReque .semi(); // To require continuation in the user executor. } -void checkIfLinearizableReadWasAllowedOrThrow(OperationContext* opCtx, StringData dbName) { +void checkIfLinearizableReadWasAllowedOrThrow(OperationContext* opCtx, const DatabaseName& dbName) { if (repl::ReadConcernArgs::get(opCtx).getLevel() == repl::ReadConcernLevel::kLinearizableReadConcern) { // Only the donor access blocker will block linearizable reads. @@ -291,7 +292,9 @@ void checkIfLinearizableReadWasAllowedOrThrow(OperationContext* opCtx, StringDat } } -void checkIfCanWriteOrThrow(OperationContext* opCtx, StringData dbName, Timestamp writeTs) { +void checkIfCanWriteOrThrow(OperationContext* opCtx, + const DatabaseName& dbName, + Timestamp writeTs) { // The migration protocol guarantees the recipient will not get writes until the migration // is committed. auto mtab = TenantMigrationAccessBlockerRegistry::get(opCtx->getServiceContext()) @@ -304,7 +307,7 @@ void checkIfCanWriteOrThrow(OperationContext* opCtx, StringData dbName, Timestam } } -Status checkIfCanBuildIndex(OperationContext* opCtx, StringData dbName) { +Status checkIfCanBuildIndex(OperationContext* opCtx, const DatabaseName& dbName) { // We only block index builds on the donor. auto mtab = TenantMigrationAccessBlockerRegistry::get(opCtx->getServiceContext()) .getTenantMigrationAccessBlockerForDbName(dbName, MtabType::kDonor); @@ -326,8 +329,8 @@ Status checkIfCanBuildIndex(OperationContext* opCtx, StringData dbName) { return Status::OK(); } -bool hasActiveTenantMigration(OperationContext* opCtx, StringData dbName) { - if (dbName.empty()) { +bool hasActiveTenantMigration(OperationContext* opCtx, const DatabaseName& dbName) { + if (dbName.db().empty()) { return false; } diff --git a/src/mongo/db/repl/tenant_migration_access_blocker_util.h b/src/mongo/db/repl/tenant_migration_access_blocker_util.h index 17c73cf5667..33459f4beb9 100644 --- a/src/mongo/db/repl/tenant_migration_access_blocker_util.h +++ b/src/mongo/db/repl/tenant_migration_access_blocker_util.h @@ -80,30 +80,32 @@ TenantMigrationDonorDocument parseDonorStateDocument(const BSONObj& doc); * will be set for the returned future when the migration is committed or aborted. Note: for better * performance, check if the future is immediately ready. */ -SemiFuture<void> checkIfCanReadOrBlock(OperationContext* opCtx, const OpMsgRequest& request); +SemiFuture<void> checkIfCanReadOrBlock(OperationContext* opCtx, + const DatabaseName& dbName, + const OpMsgRequest& request); /** * If the operation has read concern "linearizable", throws TenantMigrationCommitted error if the * database has been migrated to a different replica set. */ -void checkIfLinearizableReadWasAllowedOrThrow(OperationContext* opCtx, StringData dbName); +void checkIfLinearizableReadWasAllowedOrThrow(OperationContext* opCtx, const DatabaseName& dbName); /** * Throws TenantMigrationConflict if the database is being migrated and the migration is in the * blocking state. Throws TenantMigrationCommitted if it is in committed. */ -void checkIfCanWriteOrThrow(OperationContext* opCtx, StringData dbName, Timestamp writeTs); +void checkIfCanWriteOrThrow(OperationContext* opCtx, const DatabaseName& dbName, Timestamp writeTs); /** * Returns TenantMigrationConflict if the database is being migrated (even if migration is not yet * in the blocking state). Returns TenantMigrationCommitted if it is in committed. */ -Status checkIfCanBuildIndex(OperationContext* opCtx, StringData dbName); +Status checkIfCanBuildIndex(OperationContext* opCtx, const DatabaseName& dbName); /** * Returns true if there is either a donor or recipient access blocker for the given dbName. */ -bool hasActiveTenantMigration(OperationContext* opCtx, StringData dbName); +bool hasActiveTenantMigration(OperationContext* opCtx, const DatabaseName& dbName); /** * Scan config.tenantMigrationDonors and creates the necessary TenantMigrationAccessBlockers for diff --git a/src/mongo/db/repl/tenant_migration_access_blocker_util_test.cpp b/src/mongo/db/repl/tenant_migration_access_blocker_util_test.cpp index 1da0c3736da..df29e1f4046 100644 --- a/src/mongo/db/repl/tenant_migration_access_blocker_util_test.cpp +++ b/src/mongo/db/repl/tenant_migration_access_blocker_util_test.cpp @@ -38,8 +38,8 @@ namespace mongo { class TenantMigrationAccessBlockerUtilTest : public ServiceContextTest { public: - const std::string kTenantId = "tenantId"; - const std::string kTenantDB = "tenantId_db"; + const TenantId kTenantId = TenantId(OID::gen()); + const DatabaseName kTenantDB = DatabaseName(kTenantId, "db"); void setUp() { _opCtx = makeOperationContext(); @@ -66,7 +66,8 @@ TEST_F(TenantMigrationAccessBlockerUtilTest, HasActiveTenantMigrationInitiallyFa TEST_F(TenantMigrationAccessBlockerUtilTest, HasActiveTenantMigrationTrueWithDonor) { auto donorMtab = std::make_shared<TenantMigrationDonorAccessBlocker>(getServiceContext(), UUID::gen()); - TenantMigrationAccessBlockerRegistry::get(getServiceContext()).add(kTenantId, donorMtab); + TenantMigrationAccessBlockerRegistry::get(getServiceContext()) + .add(kTenantId.toString(), donorMtab); ASSERT(tenant_migration_access_blocker::hasActiveTenantMigration(opCtx(), kTenantDB)); } @@ -76,13 +77,14 @@ TEST_F(TenantMigrationAccessBlockerUtilTest, HasActiveShardMergeTrueWithDonor) { std::make_shared<TenantMigrationDonorAccessBlocker>(getServiceContext(), UUID::gen()); TenantMigrationAccessBlockerRegistry::get(getServiceContext()).add(donorMtab); ASSERT(tenant_migration_access_blocker::hasActiveTenantMigration(opCtx(), "anyDb"_sd)); - ASSERT(tenant_migration_access_blocker::hasActiveTenantMigration(opCtx(), kTenantId)); + ASSERT(tenant_migration_access_blocker::hasActiveTenantMigration(opCtx(), kTenantDB)); } TEST_F(TenantMigrationAccessBlockerUtilTest, HasActiveTenantMigrationTrueWithRecipient) { auto recipientMtab = std::make_shared<TenantMigrationRecipientAccessBlocker>(getServiceContext(), UUID::gen()); - TenantMigrationAccessBlockerRegistry::get(getServiceContext()).add(kTenantId, recipientMtab); + TenantMigrationAccessBlockerRegistry::get(getServiceContext()) + .add(kTenantId.toString(), recipientMtab); ASSERT(tenant_migration_access_blocker::hasActiveTenantMigration(opCtx(), kTenantDB)); } @@ -90,11 +92,13 @@ TEST_F(TenantMigrationAccessBlockerUtilTest, HasActiveTenantMigrationTrueWithRec TEST_F(TenantMigrationAccessBlockerUtilTest, HasActiveTenantMigrationTrueWithBoth) { auto recipientMtab = std::make_shared<TenantMigrationRecipientAccessBlocker>(getServiceContext(), UUID::gen()); - TenantMigrationAccessBlockerRegistry::get(getServiceContext()).add(kTenantId, recipientMtab); + TenantMigrationAccessBlockerRegistry::get(getServiceContext()) + .add(kTenantId.toString(), recipientMtab); auto donorMtab = std::make_shared<TenantMigrationDonorAccessBlocker>(getServiceContext(), UUID::gen()); - TenantMigrationAccessBlockerRegistry::get(getServiceContext()).add(kTenantId, donorMtab); + TenantMigrationAccessBlockerRegistry::get(getServiceContext()) + .add(kTenantId.toString(), donorMtab); ASSERT(tenant_migration_access_blocker::hasActiveTenantMigration(opCtx(), kTenantDB)); } @@ -103,18 +107,20 @@ TEST_F(TenantMigrationAccessBlockerUtilTest, HasActiveShardMergeTrueWithBoth) { auto uuid = UUID::gen(); auto recipientMtab = std::make_shared<TenantMigrationRecipientAccessBlocker>(getServiceContext(), uuid); - TenantMigrationAccessBlockerRegistry::get(getServiceContext()).add(kTenantId, recipientMtab); + TenantMigrationAccessBlockerRegistry::get(getServiceContext()) + .add(kTenantId.toString(), recipientMtab); auto donorMtab = std::make_shared<TenantMigrationDonorAccessBlocker>(getServiceContext(), uuid); TenantMigrationAccessBlockerRegistry::get(getServiceContext()).add(donorMtab); ASSERT(tenant_migration_access_blocker::hasActiveTenantMigration(opCtx(), "anyDb"_sd)); - ASSERT(tenant_migration_access_blocker::hasActiveTenantMigration(opCtx(), kTenantId)); + ASSERT(tenant_migration_access_blocker::hasActiveTenantMigration(opCtx(), kTenantDB)); } TEST_F(TenantMigrationAccessBlockerUtilTest, HasActiveTenantMigrationDonorFalseForNoDbName) { auto donorMtab = std::make_shared<TenantMigrationDonorAccessBlocker>(getServiceContext(), UUID::gen()); - TenantMigrationAccessBlockerRegistry::get(getServiceContext()).add(kTenantId, donorMtab); + TenantMigrationAccessBlockerRegistry::get(getServiceContext()) + .add(kTenantId.toString(), donorMtab); ASSERT_FALSE(tenant_migration_access_blocker::hasActiveTenantMigration(opCtx(), StringData())); } @@ -129,18 +135,21 @@ TEST_F(TenantMigrationAccessBlockerUtilTest, HasActiveShardMergeDonorFalseForNoD TEST_F(TenantMigrationAccessBlockerUtilTest, HasActiveShardMergeRecipientFalseForNoDbName) { auto recipientMtab = std::make_shared<TenantMigrationRecipientAccessBlocker>(getServiceContext(), UUID::gen()); - TenantMigrationAccessBlockerRegistry::get(getServiceContext()).add(kTenantId, recipientMtab); + TenantMigrationAccessBlockerRegistry::get(getServiceContext()) + .add(kTenantId.toString(), recipientMtab); ASSERT_FALSE(tenant_migration_access_blocker::hasActiveTenantMigration(opCtx(), StringData())); } TEST_F(TenantMigrationAccessBlockerUtilTest, HasActiveTenantMigrationFalseForUnrelatedDb) { auto recipientMtab = std::make_shared<TenantMigrationRecipientAccessBlocker>(getServiceContext(), UUID::gen()); - TenantMigrationAccessBlockerRegistry::get(getServiceContext()).add(kTenantId, recipientMtab); + TenantMigrationAccessBlockerRegistry::get(getServiceContext()) + .add(kTenantId.toString(), recipientMtab); auto donorMtab = std::make_shared<TenantMigrationDonorAccessBlocker>(getServiceContext(), UUID::gen()); - TenantMigrationAccessBlockerRegistry::get(getServiceContext()).add(kTenantId, donorMtab); + TenantMigrationAccessBlockerRegistry::get(getServiceContext()) + .add(kTenantId.toString(), donorMtab); ASSERT_FALSE(tenant_migration_access_blocker::hasActiveTenantMigration(opCtx(), "otherDb"_sd)); } @@ -148,22 +157,24 @@ TEST_F(TenantMigrationAccessBlockerUtilTest, HasActiveTenantMigrationFalseForUnr TEST_F(TenantMigrationAccessBlockerUtilTest, HasActiveTenantMigrationFalseAfterRemoveWithBoth) { auto recipientMtab = std::make_shared<TenantMigrationRecipientAccessBlocker>(getServiceContext(), UUID::gen()); - TenantMigrationAccessBlockerRegistry::get(getServiceContext()).add(kTenantId, recipientMtab); + TenantMigrationAccessBlockerRegistry::get(getServiceContext()) + .add(kTenantId.toString(), recipientMtab); auto donorMtab = std::make_shared<TenantMigrationDonorAccessBlocker>(getServiceContext(), UUID::gen()); - TenantMigrationAccessBlockerRegistry::get(getServiceContext()).add(kTenantId, donorMtab); + TenantMigrationAccessBlockerRegistry::get(getServiceContext()) + .add(kTenantId.toString(), donorMtab); ASSERT(tenant_migration_access_blocker::hasActiveTenantMigration(opCtx(), kTenantDB)); // Remove donor, should still be a migration. TenantMigrationAccessBlockerRegistry::get(getServiceContext()) - .remove(kTenantId, TenantMigrationAccessBlocker::BlockerType::kDonor); + .remove(kTenantId.toString(), TenantMigrationAccessBlocker::BlockerType::kDonor); ASSERT(tenant_migration_access_blocker::hasActiveTenantMigration(opCtx(), kTenantDB)); // Remove recipient, there should be no migration. TenantMigrationAccessBlockerRegistry::get(getServiceContext()) - .remove(kTenantId, TenantMigrationAccessBlocker::BlockerType::kRecipient); + .remove(kTenantId.toString(), TenantMigrationAccessBlocker::BlockerType::kRecipient); ASSERT_FALSE(tenant_migration_access_blocker::hasActiveTenantMigration(opCtx(), kTenantDB)); } @@ -171,7 +182,8 @@ TEST_F(TenantMigrationAccessBlockerUtilTest, HasActiveShardMergeFalseAfterRemove auto migrationId = UUID::gen(); auto recipientMtab = std::make_shared<TenantMigrationRecipientAccessBlocker>(getServiceContext(), migrationId); - TenantMigrationAccessBlockerRegistry::get(getServiceContext()).add(kTenantId, recipientMtab); + TenantMigrationAccessBlockerRegistry::get(getServiceContext()) + .add(kTenantId.toString(), recipientMtab); auto donorMtab = std::make_shared<TenantMigrationDonorAccessBlocker>(getServiceContext(), migrationId); @@ -189,7 +201,7 @@ TEST_F(TenantMigrationAccessBlockerUtilTest, HasActiveShardMergeFalseAfterRemove // Remove recipient, there should be no migration. TenantMigrationAccessBlockerRegistry::get(getServiceContext()) - .remove(kTenantId, TenantMigrationAccessBlocker::BlockerType::kRecipient); + .remove(kTenantId.toString(), TenantMigrationAccessBlocker::BlockerType::kRecipient); ASSERT_FALSE(tenant_migration_access_blocker::hasActiveTenantMigration(opCtx(), kTenantDB)); ASSERT_FALSE(tenant_migration_access_blocker::hasActiveTenantMigration(opCtx(), "anyDb"_sd)); } diff --git a/src/mongo/db/repl/tenant_migration_recipient_op_observer.cpp b/src/mongo/db/repl/tenant_migration_recipient_op_observer.cpp index 1ec471f259f..2c46e0ef34a 100644 --- a/src/mongo/db/repl/tenant_migration_recipient_op_observer.cpp +++ b/src/mongo/db/repl/tenant_migration_recipient_op_observer.cpp @@ -162,7 +162,8 @@ void TenantMigrationRecipientOpObserver::onCreateCollection(OperationContext* op if (!recipientInfo) return; - auto tenantId = tenant_migration_access_blocker::parseTenantIdFromDB(collectionName.db()); + const auto tenantId = tenant_migration_access_blocker::parseTenantIdFromDB( + collectionName.dbName().toStringWithTenantId()); tassert( 6461602, diff --git a/src/mongo/db/repl_index_build_state.cpp b/src/mongo/db/repl_index_build_state.cpp index 45470d2f6aa..2c0c02c40a5 100644 --- a/src/mongo/db/repl_index_build_state.cpp +++ b/src/mongo/db/repl_index_build_state.cpp @@ -358,8 +358,7 @@ ReplIndexBuildState::TryAbortResult ReplIndexBuildState::tryAbort(OperationConte opCtx->recoveryUnit()->getCommitTimestamp()); auto skipCheck = _shouldSkipIndexBuildStateTransitionCheck(opCtx); Status abortStatus = signalAction == IndexBuildAction::kTenantMigrationAbort - ? tenant_migration_access_blocker::checkIfCanBuildIndex(opCtx, - dbName.toStringWithTenantId()) + ? tenant_migration_access_blocker::checkIfCanBuildIndex(opCtx, dbName) : Status(ErrorCodes::IndexBuildAborted, reason); invariant(!abortStatus.isOK()); _indexBuildState.setState(IndexBuildState::kAborted, skipCheck, abortTimestamp, abortStatus); diff --git a/src/mongo/db/s/migration_source_manager.cpp b/src/mongo/db/s/migration_source_manager.cpp index 53578adff62..ea865509159 100644 --- a/src/mongo/db/s/migration_source_manager.cpp +++ b/src/mongo/db/s/migration_source_manager.cpp @@ -306,7 +306,7 @@ void MigrationSourceManager::startClone() { if (replEnabled) { auto const readConcernArgs = repl::ReadConcernArgs( replCoord->getMyLastAppliedOpTime(), repl::ReadConcernLevel::kLocalReadConcern); - uassertStatusOK(waitForReadConcern(_opCtx, readConcernArgs, StringData(), false)); + uassertStatusOK(waitForReadConcern(_opCtx, readConcernArgs, DatabaseName(), false)); setPrepareConflictBehaviorForReadConcern( _opCtx, readConcernArgs, PrepareConflictBehavior::kEnforce); diff --git a/src/mongo/db/serverless/shard_split_donor_service_test.cpp b/src/mongo/db/serverless/shard_split_donor_service_test.cpp index 99aa8dd3327..9d4f21b98e9 100644 --- a/src/mongo/db/serverless/shard_split_donor_service_test.cpp +++ b/src/mongo/db/serverless/shard_split_donor_service_test.cpp @@ -232,7 +232,7 @@ void fastForwardCommittedSnapshotOpTime( bool hasActiveSplitForTenants(OperationContext* opCtx, const std::vector<TenantId>& tenantIds) { return std::all_of(tenantIds.begin(), tenantIds.end(), [&](const auto& tenantId) { return tenant_migration_access_blocker::hasActiveTenantMigration( - opCtx, StringData(tenantId.toString() + "_db")); + opCtx, DatabaseName(tenantId, "db")); }); } diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp index 84444a22f43..6f77b62ffb3 100644 --- a/src/mongo/db/service_entry_point_common.cpp +++ b/src/mongo/db/service_entry_point_common.cpp @@ -863,10 +863,11 @@ private: Future<void> InvokeCommand::run() { return makeReadyFutureWith([&] { auto execContext = _ecd->getExecutionContext(); + const auto dbName = _ecd->getInvocation()->ns().dbName(); // TODO SERVER-53761: find out if we can do this more asynchronously. The client // Strand is locked to current thread in SessionWorkflow::Impl::startNewLoop(). - tenant_migration_access_blocker::checkIfCanReadOrBlock(execContext->getOpCtx(), - execContext->getRequest()) + tenant_migration_access_blocker::checkIfCanReadOrBlock( + execContext->getOpCtx(), dbName, execContext->getRequest()) .get(execContext->getOpCtx()); return runCommandInvocation(_ecd->getExecutionContext(), _ecd->getInvocation()); }) @@ -882,9 +883,10 @@ Future<void> CheckoutSessionAndInvokeCommand::run() { _checkOutSession(); auto execContext = _ecd->getExecutionContext(); + const auto dbName = _ecd->getInvocation()->ns().dbName(); // TODO SERVER-53761: find out if we can do this more asynchronously. - tenant_migration_access_blocker::checkIfCanReadOrBlock(execContext->getOpCtx(), - execContext->getRequest()) + tenant_migration_access_blocker::checkIfCanReadOrBlock( + execContext->getOpCtx(), dbName, execContext->getRequest()) .get(execContext->getOpCtx()); return runCommandInvocation(_ecd->getExecutionContext(), _ecd->getInvocation()); }) diff --git a/src/mongo/db/service_entry_point_mongod.cpp b/src/mongo/db/service_entry_point_mongod.cpp index e42e353a477..138b7818d9e 100644 --- a/src/mongo/db/service_entry_point_mongod.cpp +++ b/src/mongo/db/service_entry_point_mongod.cpp @@ -81,7 +81,7 @@ public: const OpMsgRequest& request) const override { Status rcStatus = mongo::waitForReadConcern(opCtx, repl::ReadConcernArgs::get(opCtx), - request.getDatabase(), + invocation->ns().dbName(), invocation->allowsAfterClusterTime()); if (!rcStatus.isOK()) { diff --git a/src/mongo/db/ttl.cpp b/src/mongo/db/ttl.cpp index f56b3985261..d300d79878c 100644 --- a/src/mongo/db/ttl.cpp +++ b/src/mongo/db/ttl.cpp @@ -438,8 +438,8 @@ bool TTLMonitor::_doTTLIndexDelete(OperationContext* opCtx, if (coll.getDb() && nullptr != (mtab = TenantMigrationAccessBlockerRegistry::get(opCtx->getServiceContext()) - .getTenantMigrationAccessBlockerForDbName( - coll.getDb()->name().toString(), MtabType::kRecipient)) && + .getTenantMigrationAccessBlockerForDbName(coll.getDb()->name(), + MtabType::kRecipient)) && mtab->checkIfShouldBlockTTL()) { LOGV2_DEBUG(53768, 1, diff --git a/src/mongo/embedded/read_concern_embedded.cpp b/src/mongo/embedded/read_concern_embedded.cpp index 52bdf708c23..f96171219a7 100644 --- a/src/mongo/embedded/read_concern_embedded.cpp +++ b/src/mongo/embedded/read_concern_embedded.cpp @@ -42,7 +42,7 @@ void setPrepareConflictBehaviorForReadConcernImpl( Status waitForReadConcernImpl(OperationContext* opCtx, const repl::ReadConcernArgs& readConcernArgs, - StringData dbName, + const DatabaseName& dbName, bool allowAfterClusterTime) { if (readConcernArgs.getLevel() == repl::ReadConcernLevel::kLinearizableReadConcern) { return {ErrorCodes::NotImplemented, "linearizable read concern not supported on embedded"}; diff --git a/src/mongo/embedded/service_entry_point_embedded.cpp b/src/mongo/embedded/service_entry_point_embedded.cpp index 2dfb0ba9f2a..e6a40bfd512 100644 --- a/src/mongo/embedded/service_entry_point_embedded.cpp +++ b/src/mongo/embedded/service_entry_point_embedded.cpp @@ -86,7 +86,7 @@ public: const OpMsgRequest& request) const override { auto rcStatus = mongo::waitForReadConcern(opCtx, repl::ReadConcernArgs::get(opCtx), - request.getDatabase(), + invocation->ns().dbName(), invocation->allowsAfterClusterTime()); uassertStatusOK(rcStatus); } |