From 3b1bf38d16e8791a59d7ab64b3eaac8e1b5f7e7a Mon Sep 17 00:00:00 2001 From: Adityavardhan Agrawal Date: Thu, 29 Sep 2022 20:57:43 +0000 Subject: SERVER-68357: Have CollectionUUIDMismatchInfo use DatabaseName --- src/mongo/db/catalog/collection_uuid_mismatch.cpp | 2 +- src/mongo/db/catalog/collection_uuid_mismatch_info.cpp | 4 ++-- src/mongo/db/catalog/collection_uuid_mismatch_info.h | 12 ++++++------ src/mongo/db/catalog/drop_collection.cpp | 2 +- src/mongo/s/collection_uuid_mismatch.cpp | 10 +++++----- src/mongo/s/commands/cluster_collection_mod_cmd.cpp | 11 +++++------ src/mongo/s/commands/cluster_drop_collection_cmd.cpp | 2 +- src/mongo/s/commands/cluster_rename_collection_cmd.cpp | 2 +- src/mongo/s/query/cluster_aggregate.cpp | 2 +- src/mongo/s/query/cluster_find.cpp | 2 +- src/mongo/s/write_ops/batch_write_op.cpp | 2 +- 11 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/mongo/db/catalog/collection_uuid_mismatch.cpp b/src/mongo/db/catalog/collection_uuid_mismatch.cpp index 57a6551dc9b..ef5062be962 100644 --- a/src/mongo/db/catalog/collection_uuid_mismatch.cpp +++ b/src/mongo/db/catalog/collection_uuid_mismatch.cpp @@ -44,7 +44,7 @@ void checkCollectionUUIDMismatch(OperationContext* opCtx, auto actualNamespace = CollectionCatalog::get(opCtx)->lookupNSSByUUID(opCtx, *uuid); uassert( - (CollectionUUIDMismatchInfo{ns.db().toString(), + (CollectionUUIDMismatchInfo{ns.dbName(), *uuid, ns.coll().toString(), actualNamespace && actualNamespace->db() == ns.db() diff --git a/src/mongo/db/catalog/collection_uuid_mismatch_info.cpp b/src/mongo/db/catalog/collection_uuid_mismatch_info.cpp index 7cb40347e92..86a5cf5ab66 100644 --- a/src/mongo/db/catalog/collection_uuid_mismatch_info.cpp +++ b/src/mongo/db/catalog/collection_uuid_mismatch_info.cpp @@ -45,14 +45,14 @@ constexpr StringData kActualCollectionFieldName = "actualCollection"_sd; std::shared_ptr CollectionUUIDMismatchInfo::parse(const BSONObj& obj) { auto actualNamespace = obj[kActualCollectionFieldName]; return std::make_shared( - obj[kDbFieldName].str(), + DatabaseName(obj[kDbFieldName].str()), UUID::parse(obj[kCollectionUUIDFieldName]).getValue(), obj[kExpectedCollectionFieldName].str(), actualNamespace.isNull() ? boost::none : boost::make_optional(actualNamespace.str())); } void CollectionUUIDMismatchInfo::serialize(BSONObjBuilder* builder) const { - builder->append(kDbFieldName, _db); + builder->append(kDbFieldName, _dbName.db()); _collectionUUID.appendToBuilder(builder, kCollectionUUIDFieldName); builder->append(kExpectedCollectionFieldName, _expectedCollection); if (_actualCollection) { diff --git a/src/mongo/db/catalog/collection_uuid_mismatch_info.h b/src/mongo/db/catalog/collection_uuid_mismatch_info.h index 2a627f75e7e..01147676076 100644 --- a/src/mongo/db/catalog/collection_uuid_mismatch_info.h +++ b/src/mongo/db/catalog/collection_uuid_mismatch_info.h @@ -30,7 +30,7 @@ #pragma once #include "mongo/base/error_extra_info.h" - +#include "mongo/db/database_name.h" #include "mongo/util/uuid.h" namespace mongo { @@ -38,11 +38,11 @@ class CollectionUUIDMismatchInfo final : public ErrorExtraInfo { public: static constexpr auto code = ErrorCodes::CollectionUUIDMismatch; - explicit CollectionUUIDMismatchInfo(std::string db, + explicit CollectionUUIDMismatchInfo(DatabaseName dbName, UUID collectionUUID, std::string expectedCollection, boost::optional actualCollection) - : _db(std::move(db)), + : _dbName(std::move(dbName)), _collectionUUID(std::move(collectionUUID)), _expectedCollection(std::move(expectedCollection)), _actualCollection(std::move(actualCollection)) {} @@ -51,8 +51,8 @@ public: void serialize(BSONObjBuilder* builder) const override; - const auto& db() const { - return _db; + const auto& dbName() const { + return _dbName; } const auto& collectionUUID() const { @@ -68,7 +68,7 @@ public: } private: - std::string _db; + DatabaseName _dbName; UUID _collectionUUID; std::string _expectedCollection; boost::optional _actualCollection; diff --git a/src/mongo/db/catalog/drop_collection.cpp b/src/mongo/db/catalog/drop_collection.cpp index 645362a327d..da4bcfd6d09 100644 --- a/src/mongo/db/catalog/drop_collection.cpp +++ b/src/mongo/db/catalog/drop_collection.cpp @@ -362,7 +362,7 @@ Status _dropCollection(OperationContext* opCtx, auto db = autoDb.getDb(); if (!db) { return expectedUUID - ? Status{CollectionUUIDMismatchInfo(collectionName.db().toString(), + ? Status{CollectionUUIDMismatchInfo(collectionName.dbName(), *expectedUUID, collectionName.coll().toString(), boost::none), diff --git a/src/mongo/s/collection_uuid_mismatch.cpp b/src/mongo/s/collection_uuid_mismatch.cpp index da2d8dc6229..4df6f92067e 100644 --- a/src/mongo/s/collection_uuid_mismatch.cpp +++ b/src/mongo/s/collection_uuid_mismatch.cpp @@ -54,20 +54,20 @@ Status populateCollectionUUIDMismatch(OperationContext* opCtx, opCtx = alternativeOpCtx.get(); AlternativeClientRegion acr{client}; - auto swDbInfo = Grid::get(opCtx)->catalogCache()->getDatabase(opCtx, info->db()); + auto swDbInfo = + Grid::get(opCtx)->catalogCache()->getDatabase(opCtx, info->dbName().toStringWithTenantId()); if (!swDbInfo.isOK()) { return swDbInfo.getStatus(); } ListCollections listCollections; // Empty tenant id is acceptable here as command's tenant id will not be serialized to BSON. - // TODO SERVER-68357: Use database name of CollectionUUIDMismatchInfo. - listCollections.setDbName(DatabaseName(boost::none, info->db())); + listCollections.setDbName(info->dbName()); listCollections.setFilter(BSON("info.uuid" << info->collectionUUID())); auto response = executeCommandAgainstDatabasePrimary(opCtx, - info->db(), + info->dbName().db(), swDbInfo.getValue(), listCollections.toBSON({}), ReadPreferenceSetting{ReadPreference::PrimaryOnly}, @@ -83,7 +83,7 @@ Status populateCollectionUUIDMismatch(OperationContext* opCtx, if (auto actualCollectionElem = dotted_path_support::extractElementAtPath( response.swResponse.getValue().data, "cursor.firstBatch.0.name")) { - return {CollectionUUIDMismatchInfo{info->db(), + return {CollectionUUIDMismatchInfo{info->dbName(), info->collectionUUID(), info->expectedCollection(), actualCollectionElem.str()}, diff --git a/src/mongo/s/commands/cluster_collection_mod_cmd.cpp b/src/mongo/s/commands/cluster_collection_mod_cmd.cpp index 8b73ac91430..146778efdc0 100644 --- a/src/mongo/s/commands/cluster_collection_mod_cmd.cpp +++ b/src/mongo/s/commands/cluster_collection_mod_cmd.cpp @@ -101,12 +101,11 @@ public: auto swDbInfo = Grid::get(opCtx)->catalogCache()->getDatabase( opCtx, cmd.getDbName().toStringWithTenantId()); if (swDbInfo == ErrorCodes::NamespaceNotFound) { - uassert(CollectionUUIDMismatchInfo(cmd.getDbName().toString(), - *cmd.getCollectionUUID(), - nss.coll().toString(), - boost::none), - "Database does not exist", - !cmd.getCollectionUUID()); + uassert( + CollectionUUIDMismatchInfo( + cmd.getDbName(), *cmd.getCollectionUUID(), nss.coll().toString(), boost::none), + "Database does not exist", + !cmd.getCollectionUUID()); } const auto dbInfo = uassertStatusOK(swDbInfo); diff --git a/src/mongo/s/commands/cluster_drop_collection_cmd.cpp b/src/mongo/s/commands/cluster_drop_collection_cmd.cpp index ef1bfe63c7b..3651dcb1253 100644 --- a/src/mongo/s/commands/cluster_drop_collection_cmd.cpp +++ b/src/mongo/s/commands/cluster_drop_collection_cmd.cpp @@ -119,7 +119,7 @@ public: // Ensure our reply conforms to the IDL-defined reply structure. return DropReply::parse(IDLParserContext{"drop"}, resultObj); } catch (const ExceptionFor&) { - uassert(CollectionUUIDMismatchInfo(request().getDbName().toString(), + uassert(CollectionUUIDMismatchInfo(request().getDbName(), *request().getCollectionUUID(), request().getNamespace().coll().toString(), boost::none), diff --git a/src/mongo/s/commands/cluster_rename_collection_cmd.cpp b/src/mongo/s/commands/cluster_rename_collection_cmd.cpp index b109fdcc556..8920eb793be 100644 --- a/src/mongo/s/commands/cluster_rename_collection_cmd.cpp +++ b/src/mongo/s/commands/cluster_rename_collection_cmd.cpp @@ -101,7 +101,7 @@ public: auto catalogCache = Grid::get(opCtx)->catalogCache(); auto swDbInfo = Grid::get(opCtx)->catalogCache()->getDatabase(opCtx, fromNss.db()); if (swDbInfo == ErrorCodes::NamespaceNotFound) { - uassert(CollectionUUIDMismatchInfo(fromNss.db().toString(), + uassert(CollectionUUIDMismatchInfo(fromNss.dbName(), *request().getCollectionUUID(), fromNss.coll().toString(), boost::none), diff --git a/src/mongo/s/query/cluster_aggregate.cpp b/src/mongo/s/query/cluster_aggregate.cpp index 99dff9da625..807745b6caa 100644 --- a/src/mongo/s/query/cluster_aggregate.cpp +++ b/src/mongo/s/query/cluster_aggregate.cpp @@ -329,7 +329,7 @@ Status ClusterAggregate::runAggregate(OperationContext* opCtx, sharded_agg_helpers::getExecutionNsRoutingInfo(opCtx, namespaces.executionNss); if (!executionNsRoutingInfoStatus.isOK()) { - uassert(CollectionUUIDMismatchInfo(request.getDbName().toString(), + uassert(CollectionUUIDMismatchInfo(request.getDbName(), *request.getCollectionUUID(), request.getNamespace().coll().toString(), boost::none), diff --git a/src/mongo/s/query/cluster_find.cpp b/src/mongo/s/query/cluster_find.cpp index 6ccadf2e927..1e007eed33a 100644 --- a/src/mongo/s/query/cluster_find.cpp +++ b/src/mongo/s/query/cluster_find.cpp @@ -517,7 +517,7 @@ CursorId ClusterFind::runQuery(OperationContext* opCtx, for (size_t retries = 1; retries <= kMaxRetries; ++retries) { auto swCM = getCollectionRoutingInfoForTxnCmd(opCtx, query.nss()); if (swCM == ErrorCodes::NamespaceNotFound) { - uassert(CollectionUUIDMismatchInfo(query.nss().db().toString(), + uassert(CollectionUUIDMismatchInfo(query.nss().dbName(), *findCommand.getCollectionUUID(), query.nss().coll().toString(), boost::none), diff --git a/src/mongo/s/write_ops/batch_write_op.cpp b/src/mongo/s/write_ops/batch_write_op.cpp index 26f9a4d3488..21c8491135d 100644 --- a/src/mongo/s/write_ops/batch_write_op.cpp +++ b/src/mongo/s/write_ops/batch_write_op.cpp @@ -232,7 +232,7 @@ void populateCollectionUUIDMismatch(OperationContext* opCtx, } if (*actualCollection) { - error->setStatus({CollectionUUIDMismatchInfo{info->db(), + error->setStatus({CollectionUUIDMismatchInfo{info->dbName(), info->collectionUUID(), info->expectedCollection(), **actualCollection}, -- cgit v1.2.1