diff options
Diffstat (limited to 'src/mongo/db')
62 files changed, 445 insertions, 413 deletions
diff --git a/src/mongo/db/auth/auth_op_observer.h b/src/mongo/db/auth/auth_op_observer.h index f8d0a86c3be..49690cd0333 100644 --- a/src/mongo/db/auth/auth_op_observer.h +++ b/src/mongo/db/auth/auth_op_observer.h @@ -45,10 +45,10 @@ public: AuthOpObserver(); ~AuthOpObserver(); - void onModifyShardedCollectionGlobalIndexCatalogEntry(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - BSONObj indexDoc) final {} + void onModifyCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + BSONObj indexDoc) final {} void onCreateGlobalIndex(OperationContext* opCtx, const NamespaceString& globalIndexNss, diff --git a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp index 50ef0d1a537..d411e77d50b 100644 --- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp +++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp @@ -67,7 +67,6 @@ #include "mongo/db/repl/tenant_migration_donor_service.h" #include "mongo/db/repl/tenant_migration_recipient_service.h" #include "mongo/db/s/config/sharding_catalog_manager.h" -#include "mongo/db/s/global_index_ddl_util.h" #include "mongo/db/s/migration_coordinator_document_gen.h" #include "mongo/db/s/range_deletion_util.h" #include "mongo/db/s/resharding/coordinator_document_gen.h" @@ -75,6 +74,7 @@ #include "mongo/db/s/resharding/resharding_donor_recipient_common.h" #include "mongo/db/s/shard_authoritative_catalog_gen.h" #include "mongo/db/s/sharding_ddl_coordinator_service.h" +#include "mongo/db/s/sharding_index_catalog_ddl_util.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/s/sharding_util.h" #include "mongo/db/s/transaction_coordinator_service.h" @@ -537,7 +537,7 @@ private: } if (requestedVersion > actualVersion) { - _createGlobalIndexesIndexes(opCtx, requestedVersion); + _createShardingIndexCatalogIndexes(opCtx, requestedVersion); } } @@ -656,11 +656,11 @@ private: } } - void _createGlobalIndexesIndexes( + void _createShardingIndexCatalogIndexes( OperationContext* opCtx, const multiversion::FeatureCompatibilityVersion requestedVersion) { - // TODO SERVER-67392: Remove once FCV 7.0 becomes last-lts. + // TODO SERVER-67392: Remove once gGlobalIndexesShardingCatalog is enabled. if (feature_flags::gGlobalIndexesShardingCatalog.isEnabledOnVersion(requestedVersion)) { - uassertStatusOK(sharding_util::createGlobalIndexesIndexes(opCtx)); + uassertStatusOK(sharding_util::createShardingIndexCatalogIndexes(opCtx)); if (serverGlobalParams.clusterRole == ClusterRole::ShardServer) { uassertStatusOK(sharding_util::createShardCollectionCatalogIndexes(opCtx)); } @@ -772,7 +772,7 @@ private: // TODO SERVER-68551: Remove once 7.0 becomes last-lts dropDistLockCollections(opCtx); - _createGlobalIndexesIndexes(opCtx, requestedVersion); + _createShardingIndexCatalogIndexes(opCtx, requestedVersion); // Tell the shards to enter phase-2 of setFCV (fully upgraded) _sendSetFCVRequestToShards(opCtx, request, changeTimestamp, SetFCVPhaseEnum::kComplete); @@ -833,15 +833,15 @@ private: if (!feature_flags::gGlobalIndexesShardingCatalog.isEnabledOnVersion( requestedVersion)) { - bool hasGlobalIndexes; + bool hasShardingIndexCatalogEntries; BSONObj indexDoc, collDoc; { AutoGetCollection indexesColl( opCtx, NamespaceString::kConfigsvrIndexCatalogNamespace, MODE_IS); - hasGlobalIndexes = + hasShardingIndexCatalogEntries = Helpers::findOne(opCtx, indexesColl.getCollection(), BSONObj(), indexDoc); } - if (hasGlobalIndexes) { + if (hasShardingIndexCatalogEntries) { auto uuid = uassertStatusOK( UUID::parse(indexDoc[IndexCatalogType::kCollectionUUIDFieldName])); AutoGetCollection collsColl( @@ -860,7 +860,7 @@ private: << "' on collection '" << NamespaceString(collDoc[CollectionType::kNssFieldName].String()) << "'", - !hasGlobalIndexes); + !hasShardingIndexCatalogEntries); } return; } else if (serverGlobalParams.clusterRole == ClusterRole::ShardServer || @@ -1014,7 +1014,7 @@ private: OperationContext* opCtx, const multiversion::FeatureCompatibilityVersion requestedVersion) { _cleanUpClusterParameters(opCtx, requestedVersion); if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) { - _dropInternalGlobalIndexesCollection(opCtx, requestedVersion); + _dropInternalShardingIndexCatalogCollection(opCtx, requestedVersion); _removeSchemaOnConfigSettings(opCtx, requestedVersion); // Always abort the reshardCollection regardless of version to ensure that it will // run on a consistent version from start to finish. This will ensure that it will @@ -1030,13 +1030,13 @@ private: ShardingDDLCoordinatorService::getService(opCtx) ->waitForOngoingCoordinatorsToFinish(opCtx); } - _dropInternalGlobalIndexesCollection(opCtx, requestedVersion); + _dropInternalShardingIndexCatalogCollection(opCtx, requestedVersion); } else { return; } } - void _dropInternalGlobalIndexesCollection( + void _dropInternalShardingIndexCatalogCollection( OperationContext* opCtx, const multiversion::FeatureCompatibilityVersion requestedVersion) { // TODO SERVER-67392: Remove when 7.0 branches-out. // Coordinators that commits indexes to the csrs must be drained before this point. Older @@ -1045,7 +1045,7 @@ private: if (!feature_flags::gGlobalIndexesShardingCatalog.isEnabledOnVersion(requestedVersion)) { if (serverGlobalParams.clusterRole == ClusterRole::ShardServer) { // There cannot be any global indexes at this point, but calling - // clearCollectionGlobalIndexes removes the index version from + // clearCollectionShardingIndexCatalog removes the index version from // config.shard.collections and the csr transactionally. LOGV2(7013200, "Clearing global indexes for all collections"); DBDirectClient client(opCtx); @@ -1056,8 +1056,9 @@ private: while (cursor->more()) { const auto collectionDoc = cursor->next(); auto collection = ShardAuthoritativeCollectionType::parse( - IDLParserContext("FCVDropIndexCatalog"), collectionDoc); - clearCollectionGlobalIndexes(opCtx, collection.getNss(), collection.getUuid()); + IDLParserContext("FCVDropIndexCatalogCtx"), collectionDoc); + clearCollectionShardingIndexCatalog( + opCtx, collection.getNss(), collection.getUuid()); } LOGV2(6711905, diff --git a/src/mongo/db/free_mon/free_mon_op_observer.h b/src/mongo/db/free_mon/free_mon_op_observer.h index ab2fce7d034..50a2bf8eb0a 100644 --- a/src/mongo/db/free_mon/free_mon_op_observer.h +++ b/src/mongo/db/free_mon/free_mon_op_observer.h @@ -45,10 +45,10 @@ public: FreeMonOpObserver(); ~FreeMonOpObserver(); - void onModifyShardedCollectionGlobalIndexCatalogEntry(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - BSONObj indexDoc) final {} + void onModifyCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + BSONObj indexDoc) final {} void onCreateGlobalIndex(OperationContext* opCtx, const NamespaceString& globalIndexNss, diff --git a/src/mongo/db/op_observer/fcv_op_observer.h b/src/mongo/db/op_observer/fcv_op_observer.h index 31523b4f370..fcf199ad866 100644 --- a/src/mongo/db/op_observer/fcv_op_observer.h +++ b/src/mongo/db/op_observer/fcv_op_observer.h @@ -79,10 +79,10 @@ public: const NamespaceString& globalIndexNss, const UUID& globalIndexUUID) final{}; - void onModifyShardedCollectionGlobalIndexCatalogEntry(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - BSONObj indexDoc) final {} + void onModifyCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + BSONObj indexDoc) final {} void onDropGlobalIndex(OperationContext* opCtx, const NamespaceString& globalIndexNss, const UUID& globalIndexUUID, diff --git a/src/mongo/db/op_observer/op_observer.h b/src/mongo/db/op_observer/op_observer.h index 61019324a76..5ca52fa1256 100644 --- a/src/mongo/db/op_observer/op_observer.h +++ b/src/mongo/db/op_observer/op_observer.h @@ -124,10 +124,10 @@ public: virtual ~OpObserver() = default; - virtual void onModifyShardedCollectionGlobalIndexCatalogEntry(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - BSONObj indexDoc) = 0; + virtual void onModifyCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + BSONObj indexDoc) = 0; virtual void onCreateGlobalIndex(OperationContext* opCtx, const NamespaceString& globalIndexNss, diff --git a/src/mongo/db/op_observer/op_observer_impl.cpp b/src/mongo/db/op_observer/op_observer_impl.cpp index 4437bf827c7..94f6db8fd13 100644 --- a/src/mongo/db/op_observer/op_observer_impl.cpp +++ b/src/mongo/db/op_observer/op_observer_impl.cpp @@ -2154,12 +2154,12 @@ void OpObserverImpl::onTransactionAbort(OperationContext* opCtx, opCtx, &oplogEntry, DurableTxnStateEnum::kAborted, _oplogWriter.get()); } -void OpObserverImpl::onModifyShardedCollectionGlobalIndexCatalogEntry(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - BSONObj opDoc) { +void OpObserverImpl::onModifyCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + BSONObj opDoc) { repl::MutableOplogEntry oplogEntry; - auto obj = BSON("modifyShardedCollectionGlobalIndexCatalog" << nss.toString()).addFields(opDoc); + auto obj = BSON(kShardingIndexCatalogOplogEntryName << nss.toString()).addFields(opDoc); oplogEntry.setOpType(repl::OpTypeEnum::kCommand); oplogEntry.setNss(nss); oplogEntry.setUuid(uuid); diff --git a/src/mongo/db/op_observer/op_observer_impl.h b/src/mongo/db/op_observer/op_observer_impl.h index f685e2069aa..c058de1d872 100644 --- a/src/mongo/db/op_observer/op_observer_impl.h +++ b/src/mongo/db/op_observer/op_observer_impl.h @@ -53,10 +53,10 @@ public: OpObserverImpl(std::unique_ptr<OplogWriter> oplogWriter); virtual ~OpObserverImpl() = default; - void onModifyShardedCollectionGlobalIndexCatalogEntry(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - BSONObj indexDoc) final; + void onModifyCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + BSONObj indexDoc) final; void onCreateGlobalIndex(OperationContext* opCtx, const NamespaceString& globalIndexNss, diff --git a/src/mongo/db/op_observer/op_observer_noop.h b/src/mongo/db/op_observer/op_observer_noop.h index 79b643d19ed..8a5f5052089 100644 --- a/src/mongo/db/op_observer/op_observer_noop.h +++ b/src/mongo/db/op_observer/op_observer_noop.h @@ -35,10 +35,10 @@ namespace mongo { class OpObserverNoop : public OpObserver { public: - void onModifyShardedCollectionGlobalIndexCatalogEntry(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - BSONObj indexDoc) override {} + void onModifyCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + BSONObj indexDoc) override {} void onCreateGlobalIndex(OperationContext* opCtx, const NamespaceString& globalIndexNss, diff --git a/src/mongo/db/op_observer/op_observer_registry.h b/src/mongo/db/op_observer/op_observer_registry.h index b4f11588189..ba785c6c8d1 100644 --- a/src/mongo/db/op_observer/op_observer_registry.h +++ b/src/mongo/db/op_observer/op_observer_registry.h @@ -58,13 +58,13 @@ public: _observers.push_back(std::move(observer)); } - void onModifyShardedCollectionGlobalIndexCatalogEntry(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - BSONObj indexDoc) override { + void onModifyCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + BSONObj indexDoc) override { ReservedTimes times{opCtx}; for (auto& o : _observers) - o->onModifyShardedCollectionGlobalIndexCatalogEntry(opCtx, nss, uuid, indexDoc); + o->onModifyCollectionShardingIndexCatalog(opCtx, nss, uuid, indexDoc); } void onCreateGlobalIndex(OperationContext* opCtx, diff --git a/src/mongo/db/op_observer/user_write_block_mode_op_observer.h b/src/mongo/db/op_observer/user_write_block_mode_op_observer.h index edde7357f67..81daaf64241 100644 --- a/src/mongo/db/op_observer/user_write_block_mode_op_observer.h +++ b/src/mongo/db/op_observer/user_write_block_mode_op_observer.h @@ -158,11 +158,11 @@ public: // Noop operations (don't perform any check). - // Unchecked because sharded collection global indexes are modified from internal commands. - void onModifyShardedCollectionGlobalIndexCatalogEntry(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - BSONObj indexDoc) final {} + // Unchecked because sharded collection indexes catalog are modified from internal commands. + void onModifyCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + BSONObj indexDoc) final {} // Unchecked because global indexes are created from internal commands. void onCreateGlobalIndex(OperationContext* opCtx, diff --git a/src/mongo/db/pipeline/process_interface/shardsvr_process_interface.cpp b/src/mongo/db/pipeline/process_interface/shardsvr_process_interface.cpp index f18bda978f7..ccf0c1b6ed9 100644 --- a/src/mongo/db/pipeline/process_interface/shardsvr_process_interface.cpp +++ b/src/mongo/db/pipeline/process_interface/shardsvr_process_interface.cpp @@ -75,15 +75,15 @@ void ShardServerProcessInterface::checkRoutingInfoEpochOrThrow( auto* catalogCache = Grid::get(expCtx->opCtx)->catalogCache(); // Since we are only checking the epoch, don't advance the time in store of the index cache - auto currentGlobalIndexesInfo = - uassertStatusOK(catalogCache->getCollectionRoutingInfo(expCtx->opCtx, nss)).gii; + auto currentShardingIndexCatalogInfo = + uassertStatusOK(catalogCache->getCollectionRoutingInfo(expCtx->opCtx, nss)).sii; // Mark the cache entry routingInfo for the 'nss' and 'shardId' if the entry is staler than // 'targetCollectionPlacementVersion'. const ShardVersion ignoreIndexVersion = ShardVersionFactory::make( targetCollectionPlacementVersion, - currentGlobalIndexesInfo - ? boost::make_optional(currentGlobalIndexesInfo->getCollectionIndexes()) + currentShardingIndexCatalogInfo + ? boost::make_optional(currentShardingIndexCatalogInfo->getCollectionIndexes()) : boost::none); catalogCache->invalidateShardOrEntireCollectionEntryForShardedCollection( nss, ignoreIndexVersion, shardId); diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index d300ebaa4d6..c2f9d3f17e1 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -91,8 +91,8 @@ #include "mongo/db/repl/tenant_migration_decoration.h" #include "mongo/db/repl/timestamp_block.h" #include "mongo/db/repl/transaction_oplog_application.h" -#include "mongo/db/s/global_index_ddl_util.h" #include "mongo/db/s/operation_sharding_state.h" +#include "mongo/db/s/sharding_index_catalog_ddl_util.h" #include "mongo/db/service_context.h" #include "mongo/db/stats/counters.h" #include "mongo/db/stats/server_write_concern_metrics.h" @@ -1220,18 +1220,19 @@ const StringMap<ApplyOpMetadata> kOpsMap = { -> Status { return applyAbortTransaction(opCtx, op, mode); }}}, - {"modifyShardedCollectionGlobalIndexCatalog", + {kShardingIndexCatalogOplogEntryName, {[](OperationContext* opCtx, const ApplierOperation& op, OplogApplication::Mode mode) -> Status { const auto& entry = *op; auto indexCatalogOplog = ShardingIndexCatalogOplogEntry::parse( - IDLParserContext("OplogModifyCatalogEntryContext"), entry.getObject()); + IDLParserContext("OplogModifyCollectionShardingIndexCatalogCtx"), entry.getObject()); try { switch (indexCatalogOplog.getOp()) { - case ShardingIndexCatalogOpEnumEnum::insert: { + case ShardingIndexCatalogOpEnum::insert: { auto indexEntry = ShardingIndexCatalogInsertEntry::parse( - IDLParserContext("OplogModifyCatalogEntryContext"), entry.getObject()); - addGlobalIndexCatalogEntryToCollection( + IDLParserContext("OplogModifyCollectionShardingIndexCatalogCtx"), + entry.getObject()); + addShardingIndexCatalogEntryToCollection( opCtx, entry.getNss(), indexEntry.getI().getName().toString(), @@ -1242,42 +1243,43 @@ const StringMap<ApplyOpMetadata> kOpsMap = { indexEntry.getI().getIndexCollectionUUID()); break; } - case ShardingIndexCatalogOpEnumEnum::remove: { + case ShardingIndexCatalogOpEnum::remove: { auto removeEntry = ShardingIndexCatalogRemoveEntry::parse( IDLParserContext("OplogModifyCatalogEntryContext"), entry.getObject()); - removeGlobalIndexCatalogEntryFromCollection(opCtx, - entry.getNss(), - removeEntry.getUuid(), - removeEntry.getName(), - removeEntry.getLastmod()); + removeShardingIndexCatalogEntryFromCollection(opCtx, + entry.getNss(), + removeEntry.getUuid(), + removeEntry.getName(), + removeEntry.getLastmod()); break; } - case ShardingIndexCatalogOpEnumEnum::replace: { + case ShardingIndexCatalogOpEnum::replace: { auto replaceEntry = ShardingIndexCatalogReplaceEntry::parse( IDLParserContext("OplogModifyCatalogEntryContext"), entry.getObject()); - replaceCollectionGlobalIndexes(opCtx, - entry.getNss(), - replaceEntry.getUuid(), - replaceEntry.getLastmod(), - replaceEntry.getI()); + replaceCollectionShardingIndexCatalog(opCtx, + entry.getNss(), + replaceEntry.getUuid(), + replaceEntry.getLastmod(), + replaceEntry.getI()); break; } - case ShardingIndexCatalogOpEnumEnum::clear: { + case ShardingIndexCatalogOpEnum::clear: { auto clearEntry = ShardingIndexCatalogClearEntry::parse( IDLParserContext("OplogModifyCatalogEntryContext"), entry.getObject()); - clearCollectionGlobalIndexes(opCtx, entry.getNss(), clearEntry.getUuid()); + clearCollectionShardingIndexCatalog( + opCtx, entry.getNss(), clearEntry.getUuid()); break; } - case ShardingIndexCatalogOpEnumEnum::drop: - dropCollectionGlobalIndexesMetadata(opCtx, entry.getNss()); + case ShardingIndexCatalogOpEnum::drop: + dropCollectionShardingIndexCatalog(opCtx, entry.getNss()); break; - case ShardingIndexCatalogOpEnumEnum::rename: { + case ShardingIndexCatalogOpEnum::rename: { auto renameEntry = ShardingIndexCatalogRenameEntry::parse( IDLParserContext("OplogModifyCatalogEntryContext"), entry.getObject()); - renameGlobalIndexesMetadata(opCtx, - renameEntry.getFromNss(), - renameEntry.getToNss(), - renameEntry.getLastmod()); + renameCollectionShardingIndexCatalog(opCtx, + renameEntry.getFromNss(), + renameEntry.getToNss(), + renameEntry.getLastmod()); break; } default: @@ -1285,7 +1287,7 @@ const StringMap<ApplyOpMetadata> kOpsMap = { } } catch (const DBException& ex) { LOGV2_ERROR(6712302, - "Failed to apply modifyShardedCollectionGlobalIndexCatalog with entry obj", + "Failed to apply modifyCollectionShardingIndexCatalog with entry obj", "entry"_attr = redact(entry.getObject()), "error"_attr = redact(ex)); return ex.toStatus(); diff --git a/src/mongo/db/repl/oplog_entry.cpp b/src/mongo/db/repl/oplog_entry.cpp index 86532c8149c..408a91a750e 100644 --- a/src/mongo/db/repl/oplog_entry.cpp +++ b/src/mongo/db/repl/oplog_entry.cpp @@ -38,6 +38,7 @@ #include "mongo/db/namespace_string.h" #include "mongo/db/server_feature_flags_gen.h" #include "mongo/logv2/redaction.h" +#include "mongo/s/catalog/type_index_catalog.h" #include "mongo/util/namespace_string_util.h" #include "mongo/util/time_support.h" @@ -167,8 +168,8 @@ DurableOplogEntry::CommandType parseCommandType(const BSONObj& objectField) { return DurableOplogEntry::CommandType::kAbortTransaction; } else if (commandString == "importCollection") { return DurableOplogEntry::CommandType::kImportCollection; - } else if (commandString == "modifyShardedCollectionGlobalIndexCatalog") { - return DurableOplogEntry::CommandType::kModifyShardedCollectionGlobalIndexCatalog; + } else if (commandString == kShardingIndexCatalogOplogEntryName) { + return DurableOplogEntry::CommandType::kModifyCollectionShardingIndexCatalog; } else if (commandString == "createGlobalIndex") { return DurableOplogEntry::CommandType::kCreateGlobalIndex; } else if (commandString == "dropGlobalIndex") { diff --git a/src/mongo/db/repl/oplog_entry.h b/src/mongo/db/repl/oplog_entry.h index 64b40477283..7804f2d99d9 100644 --- a/src/mongo/db/repl/oplog_entry.h +++ b/src/mongo/db/repl/oplog_entry.h @@ -508,7 +508,7 @@ public: kCommitTransaction, kAbortTransaction, kImportCollection, - kModifyShardedCollectionGlobalIndexCatalog, + kModifyCollectionShardingIndexCatalog, kCreateGlobalIndex, kDropGlobalIndex, }; diff --git a/src/mongo/db/repl/primary_only_service_op_observer.h b/src/mongo/db/repl/primary_only_service_op_observer.h index 5064719949d..722bff53730 100644 --- a/src/mongo/db/repl/primary_only_service_op_observer.h +++ b/src/mongo/db/repl/primary_only_service_op_observer.h @@ -47,10 +47,10 @@ public: explicit PrimaryOnlyServiceOpObserver(ServiceContext* serviceContext); ~PrimaryOnlyServiceOpObserver(); - void onModifyShardedCollectionGlobalIndexCatalogEntry(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - BSONObj indexDoc) final {} + void onModifyCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + BSONObj indexDoc) final {} void onCreateGlobalIndex(OperationContext* opCtx, const NamespaceString& globalIndexNss, diff --git a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp index c092a77fe96..981f060b10c 100644 --- a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp @@ -1015,7 +1015,7 @@ void ReplicationCoordinatorExternalStateImpl::_shardingOnTransitionToPrimaryHook if (mongo::feature_flags::gGlobalIndexesShardingCatalog.isEnabledAndIgnoreFCV()) { // Create indexes in config.shard.indexes if needed. - indexStatus = sharding_util::createGlobalIndexesIndexes(opCtx); + indexStatus = sharding_util::createShardingIndexCatalogIndexes(opCtx); if (!indexStatus.isOK()) { // If the node is shutting down or it lost quorum just as it was becoming primary, // don't run the sharding onStepUp machinery. The onStepDown counterpart to these diff --git a/src/mongo/db/repl/rollback_impl.cpp b/src/mongo/db/repl/rollback_impl.cpp index 0968e7f464a..c94780f077f 100644 --- a/src/mongo/db/repl/rollback_impl.cpp +++ b/src/mongo/db/repl/rollback_impl.cpp @@ -438,7 +438,7 @@ StatusWith<std::set<NamespaceString>> RollbackImpl::_namespacesForOp(const Oplog << "' during rollback."; return Status(ErrorCodes::UnrecoverableRollbackError, message); } - case OplogEntry::CommandType::kModifyShardedCollectionGlobalIndexCatalog: + case OplogEntry::CommandType::kModifyCollectionShardingIndexCatalog: case OplogEntry::CommandType::kCreateGlobalIndex: case OplogEntry::CommandType::kDropGlobalIndex: case OplogEntry::CommandType::kCreate: diff --git a/src/mongo/db/repl/tenant_migration_donor_op_observer.h b/src/mongo/db/repl/tenant_migration_donor_op_observer.h index 9bcd876485a..97e83130ad2 100644 --- a/src/mongo/db/repl/tenant_migration_donor_op_observer.h +++ b/src/mongo/db/repl/tenant_migration_donor_op_observer.h @@ -45,10 +45,10 @@ public: TenantMigrationDonorOpObserver() = default; ~TenantMigrationDonorOpObserver() = default; - void onModifyShardedCollectionGlobalIndexCatalogEntry(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - BSONObj indexDoc) final {} + void onModifyCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + BSONObj indexDoc) final {} void onCreateGlobalIndex(OperationContext* opCtx, const NamespaceString& globalIndexNss, diff --git a/src/mongo/db/repl/tenant_migration_recipient_op_observer.h b/src/mongo/db/repl/tenant_migration_recipient_op_observer.h index a395173ef58..0eff8068a4a 100644 --- a/src/mongo/db/repl/tenant_migration_recipient_op_observer.h +++ b/src/mongo/db/repl/tenant_migration_recipient_op_observer.h @@ -46,10 +46,10 @@ public: TenantMigrationRecipientOpObserver() = default; ~TenantMigrationRecipientOpObserver() = default; - void onModifyShardedCollectionGlobalIndexCatalogEntry(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - BSONObj indexDoc) final {} + void onModifyCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + BSONObj indexDoc) final {} void onCreateGlobalIndex(OperationContext* opCtx, const NamespaceString& globalIndexNss, diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript index 73884611a91..5c52f982c45 100644 --- a/src/mongo/db/s/SConscript +++ b/src/mongo/db/s/SConscript @@ -101,8 +101,8 @@ env.Library( env.Library( target='sharding_catalog', source=[ - 'global_index_ddl_util.cpp', 'shard_authoritative_catalog.idl', + 'sharding_index_catalog_ddl_util.cpp', ], LIBDEPS_PRIVATE=[ '$BUILD_DIR/mongo/base', diff --git a/src/mongo/db/s/analyze_shard_key_read_write_distribution_test.cpp b/src/mongo/db/s/analyze_shard_key_read_write_distribution_test.cpp index c082ddcaa37..8af7634343e 100644 --- a/src/mongo/db/s/analyze_shard_key_read_write_distribution_test.cpp +++ b/src/mongo/db/s/analyze_shard_key_read_write_distribution_test.cpp @@ -128,8 +128,8 @@ protected: RoutingTableHistoryValueHandle(std::make_shared<RoutingTableHistory>( std::move(routingTableHistory))), boost::none); - return CollectionRoutingInfoTargeter( - CollectionRoutingInfo{std::move(cm), boost::optional<GlobalIndexesCache>(boost::none)}); + return CollectionRoutingInfoTargeter(CollectionRoutingInfo{ + std::move(cm), boost::optional<ShardingIndexesCatalogCache>(boost::none)}); } int32_t getRandomInt(int32_t limit) const { diff --git a/src/mongo/db/s/chunk_operation_precondition_checks.cpp b/src/mongo/db/s/chunk_operation_precondition_checks.cpp index 7759e719569..7b95ee9335e 100644 --- a/src/mongo/db/s/chunk_operation_precondition_checks.cpp +++ b/src/mongo/db/s/chunk_operation_precondition_checks.cpp @@ -46,7 +46,7 @@ CollectionPlacementAndIndexInfo checkCollectionIdentity( const auto scopedCsr = CollectionShardingRuntime::assertCollectionLockedAndAcquireShared(opCtx, nss); auto optMetadata = scopedCsr->getCurrentMetadataIfKnown(); - auto optGlobalIndexInfo = scopedCsr->getIndexes(opCtx); + auto optShardingIndexCatalogInfo = scopedCsr->getIndexes(opCtx); uassert(StaleConfigInfo(nss, ShardVersion::IGNORED() /* receivedVersion */, @@ -89,20 +89,20 @@ CollectionPlacementAndIndexInfo checkCollectionIdentity( str::stream() << "Shard does not contain any chunks for collection.", placementVersion.majorVersion() > 0); - return std::make_pair(metadata, optGlobalIndexInfo); + return std::make_pair(metadata, optShardingIndexCatalogInfo); } void checkShardKeyPattern(OperationContext* opCtx, const NamespaceString& nss, const CollectionMetadata& metadata, - const boost::optional<GlobalIndexesCache>& globalIndexInfo, + const boost::optional<ShardingIndexesCatalogCache>& shardingIndexesInfo, const ChunkRange& chunkRange) { const auto shardId = ShardingState::get(opCtx)->shardId(); const auto& keyPattern = metadata.getKeyPattern(); const auto shardVersion = ShardVersionFactory::make( metadata, - globalIndexInfo ? boost::make_optional(globalIndexInfo->getCollectionIndexes()) - : boost::none); + shardingIndexesInfo ? boost::make_optional(shardingIndexesInfo->getCollectionIndexes()) + : boost::none); uassert(StaleConfigInfo(nss, ShardVersion::IGNORED() /* receivedVersion */, @@ -117,13 +117,13 @@ void checkShardKeyPattern(OperationContext* opCtx, void checkChunkMatchesRange(OperationContext* opCtx, const NamespaceString& nss, const CollectionMetadata& metadata, - const boost::optional<GlobalIndexesCache>& globalIndexInfo, + const boost::optional<ShardingIndexesCatalogCache>& shardingIndexesInfo, const ChunkRange& chunkRange) { const auto shardId = ShardingState::get(opCtx)->shardId(); const auto shardVersion = ShardVersionFactory::make( metadata, - globalIndexInfo ? boost::make_optional(globalIndexInfo->getCollectionIndexes()) - : boost::none); + shardingIndexesInfo ? boost::make_optional(shardingIndexesInfo->getCollectionIndexes()) + : boost::none); ChunkType existingChunk; uassert(StaleConfigInfo(nss, @@ -146,13 +146,13 @@ void checkChunkMatchesRange(OperationContext* opCtx, void checkRangeWithinChunk(OperationContext* opCtx, const NamespaceString& nss, const CollectionMetadata& metadata, - const boost::optional<GlobalIndexesCache>& globalIndexInfo, + const boost::optional<ShardingIndexesCatalogCache>& shardingIndexesInfo, const ChunkRange& chunkRange) { const auto shardId = ShardingState::get(opCtx)->shardId(); const auto shardVersion = ShardVersionFactory::make( metadata, - globalIndexInfo ? boost::make_optional(globalIndexInfo->getCollectionIndexes()) - : boost::none); + shardingIndexesInfo ? boost::make_optional(shardingIndexesInfo->getCollectionIndexes()) + : boost::none); ChunkType existingChunk; uassert(StaleConfigInfo(nss, @@ -168,13 +168,13 @@ void checkRangeWithinChunk(OperationContext* opCtx, void checkRangeOwnership(OperationContext* opCtx, const NamespaceString& nss, const CollectionMetadata& metadata, - const boost::optional<GlobalIndexesCache>& globalIndexInfo, + const boost::optional<ShardingIndexesCatalogCache>& shardingIndexesInfo, const ChunkRange& chunkRange) { const auto shardId = ShardingState::get(opCtx)->shardId(); const auto shardVersion = ShardVersionFactory::make( metadata, - globalIndexInfo ? boost::make_optional(globalIndexInfo->getCollectionIndexes()) - : boost::none); + shardingIndexesInfo ? boost::make_optional(shardingIndexesInfo->getCollectionIndexes()) + : boost::none); ChunkType existingChunk; BSONObj minKey = chunkRange.getMin(); diff --git a/src/mongo/db/s/chunk_operation_precondition_checks.h b/src/mongo/db/s/chunk_operation_precondition_checks.h index ae17fac61dc..d6fc96ff1a9 100644 --- a/src/mongo/db/s/chunk_operation_precondition_checks.h +++ b/src/mongo/db/s/chunk_operation_precondition_checks.h @@ -31,7 +31,7 @@ #include "mongo/db/s/collection_metadata.h" #include "mongo/db/s/collection_sharding_runtime.h" #include "mongo/s/catalog/type_chunk.h" -#include "mongo/s/global_index_cache.h" +#include "mongo/s/sharding_index_catalog_cache.h" namespace mongo { /** @@ -60,7 +60,7 @@ CollectionPlacementAndIndexInfo checkCollectionIdentity( void checkShardKeyPattern(OperationContext* opCtx, const NamespaceString& nss, const CollectionMetadata& metadata, - const boost::optional<GlobalIndexesCache>& indexInfo, + const boost::optional<ShardingIndexesCatalogCache>& indexInfo, const ChunkRange& chunkRange); /** @@ -71,7 +71,7 @@ void checkShardKeyPattern(OperationContext* opCtx, void checkChunkMatchesRange(OperationContext* opCtx, const NamespaceString& nss, const CollectionMetadata& metadata, - const boost::optional<GlobalIndexesCache>& indexInfo, + const boost::optional<ShardingIndexesCatalogCache>& indexInfo, const ChunkRange& chunkRange); /** @@ -83,7 +83,7 @@ void checkChunkMatchesRange(OperationContext* opCtx, void checkRangeWithinChunk(OperationContext* opCtx, const NamespaceString& nss, const CollectionMetadata& metadata, - const boost::optional<GlobalIndexesCache>& indexInfo, + const boost::optional<ShardingIndexesCatalogCache>& indexInfo, const ChunkRange& chunkRange); /** @@ -94,7 +94,7 @@ void checkRangeWithinChunk(OperationContext* opCtx, void checkRangeOwnership(OperationContext* opCtx, const NamespaceString& nss, const CollectionMetadata& metadata, - const boost::optional<GlobalIndexesCache>& indexInfo, + const boost::optional<ShardingIndexesCatalogCache>& indexInfo, const ChunkRange& chunkRange); } // namespace mongo diff --git a/src/mongo/db/s/collection_sharding_runtime.cpp b/src/mongo/db/s/collection_sharding_runtime.cpp index a1484a50924..84fc203c095 100644 --- a/src/mongo/db/s/collection_sharding_runtime.cpp +++ b/src/mongo/db/s/collection_sharding_runtime.cpp @@ -190,6 +190,11 @@ ScopedCollectionDescription CollectionShardingRuntime::getCollectionDescription( return {std::move(optMetadata)}; } +boost::optional<ShardingIndexesCatalogCache> CollectionShardingRuntime::getIndexesInCritSec( + OperationContext* opCtx) const { + return _shardingIndexesCatalogInfo; +} + boost::optional<CollectionMetadata> CollectionShardingRuntime::getCurrentMetadataIfKnown() const { auto optMetadata = _getCurrentMetadataIfKnown(boost::none); if (!optMetadata) @@ -572,53 +577,53 @@ boost::optional<CollectionIndexes> CollectionShardingRuntime::getCollectionIndex OperationContext* opCtx) const { _checkCritSecForIndexMetadata(opCtx); - return _globalIndexesInfo ? boost::make_optional(_globalIndexesInfo->getCollectionIndexes()) - : boost::none; + return _shardingIndexesCatalogInfo + ? boost::make_optional(_shardingIndexesCatalogInfo->getCollectionIndexes()) + : boost::none; } -boost::optional<GlobalIndexesCache> CollectionShardingRuntime::getIndexes(OperationContext* opCtx, - bool withCritSec) const { - if (!withCritSec) - _checkCritSecForIndexMetadata(opCtx); - - return _globalIndexesInfo; +boost::optional<ShardingIndexesCatalogCache> CollectionShardingRuntime::getIndexes( + OperationContext* opCtx) const { + _checkCritSecForIndexMetadata(opCtx); + return _shardingIndexesCatalogInfo; } void CollectionShardingRuntime::addIndex(OperationContext* opCtx, const IndexCatalogType& index, const CollectionIndexes& collectionIndexes) { - if (_globalIndexesInfo) { - _globalIndexesInfo->add(index, collectionIndexes); + if (_shardingIndexesCatalogInfo) { + _shardingIndexesCatalogInfo->add(index, collectionIndexes); } else { IndexCatalogTypeMap indexMap; indexMap.emplace(index.getName(), index); - _globalIndexesInfo.emplace(collectionIndexes, std::move(indexMap)); + _shardingIndexesCatalogInfo.emplace(collectionIndexes, std::move(indexMap)); } } void CollectionShardingRuntime::removeIndex(OperationContext* opCtx, const std::string& name, const CollectionIndexes& collectionIndexes) { - tassert( - 7019500, "Index information does not exist on CSR", _globalIndexesInfo.is_initialized()); - _globalIndexesInfo->remove(name, collectionIndexes); + tassert(7019500, + "Index information does not exist on CSR", + _shardingIndexesCatalogInfo.is_initialized()); + _shardingIndexesCatalogInfo->remove(name, collectionIndexes); } void CollectionShardingRuntime::clearIndexes(OperationContext* opCtx) { - _globalIndexesInfo = boost::none; + _shardingIndexesCatalogInfo = boost::none; } void CollectionShardingRuntime::replaceIndexes(OperationContext* opCtx, const std::vector<IndexCatalogType>& indexes, const CollectionIndexes& collectionIndexes) { - if (_globalIndexesInfo) { - _globalIndexesInfo = boost::none; + if (_shardingIndexesCatalogInfo) { + _shardingIndexesCatalogInfo = boost::none; } IndexCatalogTypeMap indexMap; for (const auto& index : indexes) { indexMap.emplace(index.getName(), index); } - _globalIndexesInfo.emplace(collectionIndexes, std::move(indexMap)); + _shardingIndexesCatalogInfo.emplace(collectionIndexes, std::move(indexMap)); } CollectionCriticalSection::CollectionCriticalSection(OperationContext* opCtx, diff --git a/src/mongo/db/s/collection_sharding_runtime.h b/src/mongo/db/s/collection_sharding_runtime.h index 3272e0ed0a8..6da67980fa3 100644 --- a/src/mongo/db/s/collection_sharding_runtime.h +++ b/src/mongo/db/s/collection_sharding_runtime.h @@ -33,13 +33,12 @@ #include "mongo/db/s/collection_sharding_state.h" #include "mongo/db/s/metadata_manager.h" #include "mongo/db/s/sharding_migration_critical_section.h" -#include "mongo/s/global_index_cache.h" #include "mongo/util/cancellation.h" #include "mongo/util/decorable.h" namespace mongo { -typedef std::pair<CollectionMetadata, boost::optional<GlobalIndexesCache>> +typedef std::pair<CollectionMetadata, boost::optional<ShardingIndexesCatalogCache>> CollectionPlacementAndIndexInfo; /** @@ -133,6 +132,10 @@ public: OrphanCleanupPolicy orphanCleanupPolicy, const ShardVersion& receivedShardVersion) const override; + boost::optional<CollectionIndexes> getCollectionIndexes(OperationContext* opCtx) const override; + + boost::optional<ShardingIndexesCatalogCache> getIndexes(OperationContext* opCtx) const override; + void checkShardVersionOrThrow(OperationContext* opCtx) const override; void checkShardVersionOrThrow(OperationContext* opCtx, @@ -142,6 +145,8 @@ public: size_t numberOfRangesScheduledForDeletion() const override; + boost::optional<ShardingIndexesCatalogCache> getIndexesInCritSec(OperationContext* opCtx) const; + /** * Returns boost::none if the description for the collection is not known yet. Otherwise * returns the most recently refreshed from the config server metadata. @@ -269,19 +274,6 @@ public: void resetPlacementVersionRecoverRefreshFuture(); /** - * Gets the shard's index version. - */ - boost::optional<CollectionIndexes> getCollectionIndexes(OperationContext* opCtx) const; - - /** - * Gets the shard's index cache. - * - * If withCritSec is true, then this function is being called under a critical section. - */ - boost::optional<GlobalIndexesCache> getIndexes(OperationContext* opCtx, - bool withCritSec = false) const; - - /** * Add a new index to the shard-role index info under a lock. */ void addIndex(OperationContext* opCtx, @@ -405,7 +397,7 @@ private: // Contains the global indexes for the collection. This will be boost::none if no global indexes // have ever been created for the collection. - boost::optional<GlobalIndexesCache> _globalIndexesInfo; + boost::optional<ShardingIndexesCatalogCache> _shardingIndexesCatalogInfo; }; /** diff --git a/src/mongo/db/s/collection_sharding_runtime_test.cpp b/src/mongo/db/s/collection_sharding_runtime_test.cpp index 6d1931188f3..8b0a06703a3 100644 --- a/src/mongo/db/s/collection_sharding_runtime_test.cpp +++ b/src/mongo/db/s/collection_sharding_runtime_test.cpp @@ -36,12 +36,12 @@ #include "mongo/db/persistent_task_store.h" #include "mongo/db/repl/wait_for_majority_service.h" #include "mongo/db/s/collection_sharding_runtime.h" -#include "mongo/db/s/global_index_ddl_util.h" #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/s/range_deleter_service_test.h" #include "mongo/db/s/range_deletion_task_gen.h" #include "mongo/db/s/shard_filtering_metadata_refresh.h" #include "mongo/db/s/shard_server_test_fixture.h" +#include "mongo/db/s/sharding_index_catalog_ddl_util.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/vector_clock.h" #include "mongo/s/catalog/sharding_catalog_client_mock.h" @@ -573,13 +573,13 @@ public: } }; -TEST_F(CollectionShardingRuntimeWithCatalogTest, TestGlobalIndexesCache) { +TEST_F(CollectionShardingRuntimeWithCatalogTest, TestShardingIndexesCatalogCache) { OperationContext* opCtx = operationContext(); ASSERT_EQ(false, csr()->getIndexes(opCtx).is_initialized()); Timestamp indexVersion(1, 0); - addGlobalIndexCatalogEntryToCollection( + addShardingIndexCatalogEntryToCollection( opCtx, kTestNss, "x_1", BSON("x" << 1), BSONObj(), uuid(), indexVersion, boost::none); ASSERT_EQ(true, csr()->getIndexes(opCtx).is_initialized()); diff --git a/src/mongo/db/s/collection_sharding_state.h b/src/mongo/db/s/collection_sharding_state.h index cf69a4dd369..81e5d593ab9 100644 --- a/src/mongo/db/s/collection_sharding_state.h +++ b/src/mongo/db/s/collection_sharding_state.h @@ -33,6 +33,7 @@ #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/s/scoped_collection_metadata.h" +#include "mongo/s/sharding_index_catalog_cache.h" namespace mongo { @@ -172,6 +173,19 @@ public: const ShardVersion& receivedShardVersion) const = 0; /** + * Gets the shard's index version. + */ + virtual boost::optional<CollectionIndexes> getCollectionIndexes( + OperationContext* opCtx) const = 0; + + /** + * Gets the shard's index cache. + * + */ + virtual boost::optional<ShardingIndexesCatalogCache> getIndexes( + OperationContext* opCtx) const = 0; + + /** * Checks whether the shard version in the operation context is compatible with the shard * version of the collection and if not, throws StaleConfigException populated with the received * and wanted versions. diff --git a/src/mongo/db/s/collection_sharding_state_factory_standalone.cpp b/src/mongo/db/s/collection_sharding_state_factory_standalone.cpp index 794dae98eb0..48fed34a989 100644 --- a/src/mongo/db/s/collection_sharding_state_factory_standalone.cpp +++ b/src/mongo/db/s/collection_sharding_state_factory_standalone.cpp @@ -69,6 +69,16 @@ public: return {kUnshardedCollection}; } + boost::optional<CollectionIndexes> getCollectionIndexes( + OperationContext* opCtx) const override { + return boost::none; + } + + boost::optional<ShardingIndexesCatalogCache> getIndexes( + OperationContext* opCtx) const override { + return boost::none; + } + ScopedCollectionFilter getOwnershipFilter( OperationContext*, OrphanCleanupPolicy orphanCleanupPolicy, diff --git a/src/mongo/db/s/config/sharding_catalog_manager.cpp b/src/mongo/db/s/config/sharding_catalog_manager.cpp index b8f0c0bbc3b..73978ff57bd 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager.cpp @@ -657,7 +657,7 @@ Status ShardingCatalogManager::_initConfigIndexes(OperationContext* opCtx) { if (feature_flags::gGlobalIndexesShardingCatalog.isEnabled( serverGlobalParams.featureCompatibility)) { - result = sharding_util::createGlobalIndexesIndexes(opCtx); + result = sharding_util::createShardingIndexCatalogIndexes(opCtx); if (!result.isOK()) { return result; } diff --git a/src/mongo/db/s/config_server_op_observer.h b/src/mongo/db/s/config_server_op_observer.h index f4cc1f41345..e221592d29c 100644 --- a/src/mongo/db/s/config_server_op_observer.h +++ b/src/mongo/db/s/config_server_op_observer.h @@ -46,10 +46,10 @@ public: ConfigServerOpObserver(); ~ConfigServerOpObserver(); - void onModifyShardedCollectionGlobalIndexCatalogEntry(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - BSONObj indexDoc) override {} + void onModifyCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + BSONObj indexDoc) override {} void onCreateGlobalIndex(OperationContext* opCtx, const NamespaceString& globalIndexNss, diff --git a/src/mongo/db/s/create_collection_coordinator.cpp b/src/mongo/db/s/create_collection_coordinator.cpp index 2db474536ec..774ea2289c0 100644 --- a/src/mongo/db/s/create_collection_coordinator.cpp +++ b/src/mongo/db/s/create_collection_coordinator.cpp @@ -707,7 +707,7 @@ CreateCollectionCoordinator::_checkIfCollectionAlreadyShardedWithSameOptions( uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfoWithRefresh( opCtx, originalNss())); auto& cm = cri.cm; - auto& gii = cri.gii; + auto& sii = cri.sii; if (cm.isSharded()) { auto requestMatchesExistingCollection = [&] { // No timeseries fields in request @@ -751,7 +751,7 @@ CreateCollectionCoordinator::_checkIfCollectionAlreadyShardedWithSameOptions( cri = uassertStatusOK( Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfoWithRefresh(opCtx, bucketsNss)); cm = cri.cm; - gii = cri.gii; + sii = cri.sii; if (!cm.isSharded()) { return boost::none; } diff --git a/src/mongo/db/s/document_source_analyze_shard_key_read_write_distribution.cpp b/src/mongo/db/s/document_source_analyze_shard_key_read_write_distribution.cpp index 503b288c745..ce227852abc 100644 --- a/src/mongo/db/s/document_source_analyze_shard_key_read_write_distribution.cpp +++ b/src/mongo/db/s/document_source_analyze_shard_key_read_write_distribution.cpp @@ -146,8 +146,8 @@ CollectionRoutingInfoTargeter makeCollectionRoutingInfoTargeter( std::move(routingTableHistory))), boost::none); - return CollectionRoutingInfoTargeter( - CollectionRoutingInfo{std::move(cm), boost::optional<GlobalIndexesCache>(boost::none)}); + return CollectionRoutingInfoTargeter(CollectionRoutingInfo{ + std::move(cm), boost::optional<ShardingIndexesCatalogCache>(boost::none)}); } /** diff --git a/src/mongo/db/s/drop_collection_coordinator.cpp b/src/mongo/db/s/drop_collection_coordinator.cpp index f49a6af55bf..72a2612734a 100644 --- a/src/mongo/db/s/drop_collection_coordinator.cpp +++ b/src/mongo/db/s/drop_collection_coordinator.cpp @@ -34,11 +34,11 @@ #include "mongo/db/concurrency/exception_util.h" #include "mongo/db/db_raii.h" #include "mongo/db/s/collection_sharding_runtime.h" -#include "mongo/db/s/global_index_ddl_util.h" #include "mongo/db/s/participant_block_gen.h" #include "mongo/db/s/range_deletion_util.h" #include "mongo/db/s/sharded_index_catalog_commands_gen.h" #include "mongo/db/s/sharding_ddl_util.h" +#include "mongo/db/s/sharding_index_catalog_ddl_util.h" #include "mongo/db/s/sharding_logging.h" #include "mongo/db/s/sharding_state.h" #include "mongo/logv2/log.h" @@ -76,7 +76,7 @@ void DropCollectionCoordinator::dropCollectionLocally(OperationContext* opCtx, ->clearFilteringMetadataForDroppedCollection(opCtx); } - dropCollectionGlobalIndexesMetadata(opCtx, nss); + dropCollectionShardingIndexCatalog(opCtx, nss); // Remove all range deletion task documents present on disk for the collection to drop. This is // a best-effort tentative considering that migrations are not blocked, hence some new document diff --git a/src/mongo/db/s/migration_destination_manager.cpp b/src/mongo/db/s/migration_destination_manager.cpp index 6462bdb5661..e5608787dd6 100644 --- a/src/mongo/db/s/migration_destination_manager.cpp +++ b/src/mongo/db/s/migration_destination_manager.cpp @@ -55,13 +55,13 @@ #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/s/collection_sharding_runtime.h" #include "mongo/db/s/collection_sharding_state.h" -#include "mongo/db/s/global_index_ddl_util.h" #include "mongo/db/s/migration_util.h" #include "mongo/db/s/move_timing_helper.h" #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/s/range_deletion_task_gen.h" #include "mongo/db/s/range_deletion_util.h" #include "mongo/db/s/shard_filtering_metadata_refresh.h" +#include "mongo/db/s/sharding_index_catalog_ddl_util.h" #include "mongo/db/s/sharding_recovery_service.h" #include "mongo/db/s/sharding_runtime_d_params_gen.h" #include "mongo/db/s/sharding_statistics.h" @@ -295,9 +295,9 @@ bool migrationRecipientRecoveryDocumentExists(OperationContext* opCtx, << sessionId.toString())) > 0; } -void replaceGlobalIndexesInShardIfNeeded(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid) { +void replaceShardingIndexCatalogInShardIfNeeded(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid) { auto currentShardHasAnyChunks = [&]() -> bool { AutoGetCollection autoColl(opCtx, nss, MODE_IS); const auto scsr = @@ -311,19 +311,19 @@ void replaceGlobalIndexesInShardIfNeeded(OperationContext* opCtx, return; } - auto [_, optGii] = uassertStatusOK( + auto [_, optSii] = uassertStatusOK( Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfoWithIndexRefresh(opCtx, nss)); - if (optGii) { + if (optSii) { std::vector<IndexCatalogType> indexes; - optGii->forEachIndex([&](const auto& index) { + optSii->forEachIndex([&](const auto& index) { indexes.push_back(index); return true; }); - replaceCollectionGlobalIndexes( - opCtx, nss, uuid, optGii->getCollectionIndexes().indexVersion(), indexes); + replaceCollectionShardingIndexCatalog( + opCtx, nss, uuid, optSii->getCollectionIndexes().indexVersion(), indexes); } else { - clearCollectionGlobalIndexes(opCtx, nss, uuid); + clearCollectionShardingIndexCatalog(opCtx, nss, uuid); } } @@ -1316,7 +1316,7 @@ void MigrationDestinationManager::_migrateDriver(OperationContext* outerOpCtx, // Get the global indexes and install them. if (feature_flags::gGlobalIndexesShardingCatalog.isEnabled( serverGlobalParams.featureCompatibility)) { - replaceGlobalIndexesInShardIfNeeded( + replaceShardingIndexCatalogInShardIfNeeded( altOpCtx.get(), _nss, donorCollectionOptionsAndIndexes.uuid); } diff --git a/src/mongo/db/s/migration_util_test.cpp b/src/mongo/db/s/migration_util_test.cpp index f21ba9b7aff..029a7ff39fc 100644 --- a/src/mongo/db/s/migration_util_test.cpp +++ b/src/mongo/db/s/migration_util_test.cpp @@ -438,7 +438,8 @@ public: return _colls; } - std::pair<CollectionType, std::vector<IndexCatalogType>> getCollectionAndGlobalIndexes( + std::pair<CollectionType, std::vector<IndexCatalogType>> + getCollectionAndShardingIndexCatalogEntries( OperationContext* opCtx, const NamespaceString& nss, const repl::ReadConcernArgs& readConcern) override { diff --git a/src/mongo/db/s/query_analysis_op_observer.h b/src/mongo/db/s/query_analysis_op_observer.h index af6c1b18f81..06c5e11b290 100644 --- a/src/mongo/db/s/query_analysis_op_observer.h +++ b/src/mongo/db/s/query_analysis_op_observer.h @@ -45,10 +45,10 @@ public: QueryAnalysisOpObserver() = default; ~QueryAnalysisOpObserver() = default; - void onModifyShardedCollectionGlobalIndexCatalogEntry(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - BSONObj indexDoc) final {} + void onModifyCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + BSONObj indexDoc) final {} void onCreateGlobalIndex(OperationContext* opCtx, const NamespaceString& globalIndexNss, diff --git a/src/mongo/db/s/range_deleter_service_op_observer.h b/src/mongo/db/s/range_deleter_service_op_observer.h index 34c288efcd8..18fd7ba7c1c 100644 --- a/src/mongo/db/s/range_deleter_service_op_observer.h +++ b/src/mongo/db/s/range_deleter_service_op_observer.h @@ -75,10 +75,10 @@ public: const OplogDeleteEntryArgs& args) override; private: - void onModifyShardedCollectionGlobalIndexCatalogEntry(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - BSONObj indexDoc) override {} + void onModifyCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + BSONObj indexDoc) override {} void onCreateGlobalIndex(OperationContext* opCtx, const NamespaceString& globalIndexNss, diff --git a/src/mongo/db/s/rename_collection_coordinator.cpp b/src/mongo/db/s/rename_collection_coordinator.cpp index a4be65a6485..5519dbf47bc 100644 --- a/src/mongo/db/s/rename_collection_coordinator.cpp +++ b/src/mongo/db/s/rename_collection_coordinator.cpp @@ -39,9 +39,9 @@ #include "mongo/db/ops/insert.h" #include "mongo/db/persistent_task_store.h" #include "mongo/db/s/collection_sharding_runtime.h" -#include "mongo/db/s/global_index_ddl_util.h" #include "mongo/db/s/sharded_index_catalog_commands_gen.h" #include "mongo/db/s/sharding_ddl_util.h" +#include "mongo/db/s/sharding_index_catalog_ddl_util.h" #include "mongo/db/s/sharding_logging.h" #include "mongo/db/s/sharding_recovery_service.h" #include "mongo/db/s/sharding_state.h" diff --git a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp index 0c862e7fe2b..170930aa2ec 100644 --- a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp +++ b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp @@ -574,12 +574,12 @@ void writeToConfigIndexesForTempNss(OperationContext* opCtx, switch (nextState) { case CoordinatorStateEnum::kPreparingToDonate: { - auto [_, optGii] = + auto [_, optSii] = uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo( opCtx, coordinatorDoc.getSourceNss())); - if (optGii) { + if (optSii) { std::vector<BSONObj> indexes; - optGii->forEachIndex([&](const auto index) { + optSii->forEachIndex([&](const auto index) { IndexCatalogType copyIdx(index); copyIdx.setCollectionUUID(coordinatorDoc.getReshardingUUID()); // TODO SERVER-73304: add the new index collection UUID here if neccessary. @@ -998,9 +998,9 @@ ChunkVersion ReshardingCoordinatorExternalState::calculateChunkVersionForInitial boost::optional<CollectionIndexes> ReshardingCoordinatorExternalState::getCatalogIndexVersion( OperationContext* opCtx, const NamespaceString& nss, const UUID& uuid) { - auto [_, optGii] = + auto [_, optSii] = uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); - if (optGii) { + if (optSii) { VectorClock::VectorTime vt = VectorClock::get(opCtx)->getTime(); auto time = vt.clusterTime().asTimestamp(); return CollectionIndexes{uuid, time}; @@ -1011,10 +1011,10 @@ boost::optional<CollectionIndexes> ReshardingCoordinatorExternalState::getCatalo boost::optional<CollectionIndexes> ReshardingCoordinatorExternalState::getCatalogIndexVersionForCommit(OperationContext* opCtx, const NamespaceString& nss) { - auto [_, optGii] = + auto [_, optSii] = uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); - if (optGii) { - return optGii->getCollectionIndexes(); + if (optSii) { + return optSii->getCollectionIndexes(); } return boost::none; } diff --git a/src/mongo/db/s/resharding/resharding_data_copy_util.cpp b/src/mongo/db/s/resharding/resharding_data_copy_util.cpp index 912677b3854..d79b4d1a496 100644 --- a/src/mongo/db/s/resharding/resharding_data_copy_util.cpp +++ b/src/mongo/db/s/resharding/resharding_data_copy_util.cpp @@ -40,11 +40,11 @@ #include "mongo/db/persistent_task_store.h" #include "mongo/db/pipeline/pipeline.h" #include "mongo/db/s/collection_sharding_runtime.h" -#include "mongo/db/s/global_index_ddl_util.h" #include "mongo/db/s/resharding/resharding_oplog_applier_progress_gen.h" #include "mongo/db/s/resharding/resharding_txn_cloner_progress_gen.h" #include "mongo/db/s/resharding/resharding_util.h" #include "mongo/db/s/session_catalog_migration.h" +#include "mongo/db/s/sharding_index_catalog_ddl_util.h" #include "mongo/db/session/session_catalog_mongod.h" #include "mongo/db/session/session_txn_record_gen.h" #include "mongo/db/storage/write_unit_of_work.h" @@ -144,11 +144,11 @@ void ensureTemporaryReshardingCollectionRenamed(OperationContext* opCtx, "Temporary resharding collection exists but doesn't have a UUID matching the" " resharding operation", !tempReshardingColl || tempReshardingColl->uuid() == metadata.getReshardingUUID()); - auto gii = CollectionShardingRuntime::assertCollectionLockedAndAcquireShared( + auto sii = CollectionShardingRuntime::assertCollectionLockedAndAcquireShared( opCtx, metadata.getTempReshardingNss()) - ->getIndexes(opCtx, true); - indexVersion = gii - ? boost::make_optional<Timestamp>(gii->getCollectionIndexes().indexVersion()) + ->getIndexesInCritSec(opCtx); + indexVersion = sii + ? boost::make_optional<Timestamp>(sii->getCollectionIndexes().indexVersion()) : boost::none; return bool(tempReshardingColl); }(); @@ -164,7 +164,7 @@ void ensureTemporaryReshardingCollectionRenamed(OperationContext* opCtx, } if (indexVersion) { - renameGlobalIndexesMetadata( + renameCollectionShardingIndexCatalog( opCtx, metadata.getTempReshardingNss(), metadata.getSourceNss(), *indexVersion); } diff --git a/src/mongo/db/s/resharding/resharding_destined_recipient_test.cpp b/src/mongo/db/s/resharding/resharding_destined_recipient_test.cpp index b4b3732d6ca..c7458a1bf50 100644 --- a/src/mongo/db/s/resharding/resharding_destined_recipient_test.cpp +++ b/src/mongo/db/s/resharding/resharding_destined_recipient_test.cpp @@ -147,7 +147,8 @@ public: _colls = std::move(colls); } - std::pair<CollectionType, std::vector<IndexCatalogType>> getCollectionAndGlobalIndexes( + std::pair<CollectionType, std::vector<IndexCatalogType>> + getCollectionAndShardingIndexCatalogEntries( OperationContext* opCtx, const NamespaceString& nss, const repl::ReadConcernArgs& readConcern) override { diff --git a/src/mongo/db/s/resharding/resharding_donor_service.cpp b/src/mongo/db/s/resharding/resharding_donor_service.cpp index a6198b4a45c..a0886e63a35 100644 --- a/src/mongo/db/s/resharding/resharding_donor_service.cpp +++ b/src/mongo/db/s/resharding/resharding_donor_service.cpp @@ -46,13 +46,13 @@ #include "mongo/db/persistent_task_store.h" #include "mongo/db/repl/repl_client_info.h" #include "mongo/db/repl/wait_for_majority_service.h" -#include "mongo/db/s/global_index_ddl_util.h" #include "mongo/db/s/resharding/resharding_change_event_o2_field_gen.h" #include "mongo/db/s/resharding/resharding_data_copy_util.h" #include "mongo/db/s/resharding/resharding_donor_recipient_common.h" #include "mongo/db/s/resharding/resharding_future_util.h" #include "mongo/db/s/resharding/resharding_server_parameters_gen.h" #include "mongo/db/s/resharding/resharding_util.h" +#include "mongo/db/s/sharding_index_catalog_ddl_util.h" #include "mongo/db/s/sharding_recovery_service.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/write_block_bypass.h" @@ -829,7 +829,7 @@ void ReshardingDonorService::DonorStateMachine::_dropOriginalCollectionThenTrans if (feature_flags::gGlobalIndexesShardingCatalog.isEnabled( serverGlobalParams.featureCompatibility)) { - dropCollectionGlobalIndexesMetadata(opCtx.get(), _metadata.getSourceNss()); + dropCollectionShardingIndexCatalog(opCtx.get(), _metadata.getSourceNss()); } resharding::data_copy::ensureCollectionDropped( opCtx.get(), _metadata.getSourceNss(), _metadata.getSourceUUID()); diff --git a/src/mongo/db/s/resharding/resharding_op_observer.h b/src/mongo/db/s/resharding/resharding_op_observer.h index ffb91be78de..d400d523179 100644 --- a/src/mongo/db/s/resharding/resharding_op_observer.h +++ b/src/mongo/db/s/resharding/resharding_op_observer.h @@ -61,10 +61,10 @@ public: ReshardingOpObserver(); ~ReshardingOpObserver() override; - void onModifyShardedCollectionGlobalIndexCatalogEntry(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - BSONObj indexDoc) override {} + void onModifyCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + BSONObj indexDoc) override {} void onCreateGlobalIndex(OperationContext* opCtx, const NamespaceString& globalIndexNss, diff --git a/src/mongo/db/s/resharding/resharding_recipient_service.cpp b/src/mongo/db/s/resharding/resharding_recipient_service.cpp index 9d2543dbd9c..17f2b800a0d 100644 --- a/src/mongo/db/s/resharding/resharding_recipient_service.cpp +++ b/src/mongo/db/s/resharding/resharding_recipient_service.cpp @@ -43,7 +43,6 @@ #include "mongo/db/repl/oplog_applier.h" #include "mongo/db/repl/read_concern_args.h" #include "mongo/db/repl/wait_for_majority_service.h" -#include "mongo/db/s/global_index_ddl_util.h" #include "mongo/db/s/migration_destination_manager.h" #include "mongo/db/s/resharding/resharding_change_event_o2_field_gen.h" #include "mongo/db/s/resharding/resharding_data_copy_util.h" @@ -54,6 +53,7 @@ #include "mongo/db/s/resharding/resharding_server_parameters_gen.h" #include "mongo/db/s/shard_key_util.h" #include "mongo/db/s/sharding_ddl_util.h" +#include "mongo/db/s/sharding_index_catalog_ddl_util.h" #include "mongo/db/s/sharding_recovery_service.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/write_block_bypass.h" @@ -856,7 +856,7 @@ void ReshardingRecipientService::RecipientStateMachine::_cleanupReshardingCollec if (aborted) { if (feature_flags::gGlobalIndexesShardingCatalog.isEnabled( serverGlobalParams.featureCompatibility)) { - dropCollectionGlobalIndexesMetadata(opCtx.get(), _metadata.getTempReshardingNss()); + dropCollectionShardingIndexCatalog(opCtx.get(), _metadata.getTempReshardingNss()); } resharding::data_copy::ensureCollectionDropped( diff --git a/src/mongo/db/s/resharding/resharding_recipient_service_external_state.cpp b/src/mongo/db/s/resharding/resharding_recipient_service_external_state.cpp index fb458dbfb33..644c5688dd6 100644 --- a/src/mongo/db/s/resharding/resharding_recipient_service_external_state.cpp +++ b/src/mongo/db/s/resharding/resharding_recipient_service_external_state.cpp @@ -30,8 +30,8 @@ #include "mongo/db/s/resharding/resharding_recipient_service_external_state.h" #include "mongo/db/s/collection_sharding_runtime.h" -#include "mongo/db/s/global_index_ddl_util.h" #include "mongo/db/s/resharding/resharding_donor_recipient_common.h" +#include "mongo/db/s/sharding_index_catalog_ddl_util.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/write_concern_options.h" #include "mongo/logv2/log.h" @@ -92,19 +92,19 @@ void ReshardingRecipientService::RecipientStateMachineExternalState:: if (feature_flags::gGlobalIndexesShardingCatalog.isEnabled( serverGlobalParams.featureCompatibility)) { - auto optGii = getCollectionIndexInfoWithRefresh(opCtx, metadata.getTempReshardingNss()); + auto optSii = getCollectionIndexInfoWithRefresh(opCtx, metadata.getTempReshardingNss()); - if (optGii) { + if (optSii) { std::vector<IndexCatalogType> indexes; - optGii->forEachIndex([&](const auto& index) { + optSii->forEachIndex([&](const auto& index) { indexes.push_back(index); return true; }); - replaceCollectionGlobalIndexes(opCtx, - metadata.getTempReshardingNss(), - metadata.getReshardingUUID(), - optGii->getCollectionIndexes().indexVersion(), - indexes); + replaceCollectionShardingIndexCatalog(opCtx, + metadata.getTempReshardingNss(), + metadata.getReshardingUUID(), + optSii->getCollectionIndexes().indexVersion(), + indexes); } } @@ -175,11 +175,11 @@ RecipientStateMachineExternalStateImpl::getCollectionIndexes(OperationContext* o }); } -boost::optional<GlobalIndexesCache> +boost::optional<ShardingIndexesCatalogCache> RecipientStateMachineExternalStateImpl::getCollectionIndexInfoWithRefresh( OperationContext* opCtx, const NamespaceString& nss) { auto catalogCache = Grid::get(opCtx)->catalogCache(); - return uassertStatusOK(catalogCache->getCollectionRoutingInfoWithIndexRefresh(opCtx, nss)).gii; + return uassertStatusOK(catalogCache->getCollectionRoutingInfoWithIndexRefresh(opCtx, nss)).sii; } void RecipientStateMachineExternalStateImpl::withShardVersionRetry( diff --git a/src/mongo/db/s/resharding/resharding_recipient_service_external_state.h b/src/mongo/db/s/resharding/resharding_recipient_service_external_state.h index 2b587590d59..dbba30a6d68 100644 --- a/src/mongo/db/s/resharding/resharding_recipient_service_external_state.h +++ b/src/mongo/db/s/resharding/resharding_recipient_service_external_state.h @@ -81,7 +81,7 @@ public: Timestamp afterClusterTime, StringData reason) = 0; - virtual boost::optional<GlobalIndexesCache> getCollectionIndexInfoWithRefresh( + virtual boost::optional<ShardingIndexesCatalogCache> getCollectionIndexInfoWithRefresh( OperationContext* opCtx, const NamespaceString& nss) = 0; virtual void withShardVersionRetry(OperationContext* opCtx, @@ -134,7 +134,7 @@ public: StringData reason) override; - boost::optional<GlobalIndexesCache> getCollectionIndexInfoWithRefresh( + boost::optional<ShardingIndexesCatalogCache> getCollectionIndexInfoWithRefresh( OperationContext* opCtx, const NamespaceString& nss) override; void withShardVersionRetry(OperationContext* opCtx, diff --git a/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp b/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp index 59a76e3da98..814040381d4 100644 --- a/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp +++ b/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp @@ -98,8 +98,8 @@ public: boost::none /* chunkSizeBytes */, true /* allowMigrations */, chunks); - IndexCatalogTypeMap globalIndexesMap; - globalIndexesMap.emplace( + IndexCatalogTypeMap shardingIndexesCatalogMap; + shardingIndexesCatalogMap.emplace( "randomKey_1", IndexCatalogType( "randomKey_1", BSON("randomKey" << 1), BSONObj(), Timestamp(1, 0), _sourceUUID)); @@ -109,8 +109,8 @@ public: DatabaseVersion(UUID::gen(), Timestamp(1, 1)), _makeStandaloneRoutingTableHistory(std::move(rt)), boost::none /* clusterTime */), - GlobalIndexesCache(CollectionIndexes(_sourceUUID, Timestamp(1, 0)), - std::move(globalIndexesMap))}; + ShardingIndexesCatalogCache(CollectionIndexes(_sourceUUID, Timestamp(1, 0)), + std::move(shardingIndexesCatalogMap))}; } MigrationDestinationManager::CollectionOptionsAndUUID getCollectionOptions( @@ -133,7 +133,7 @@ public: return {std::vector<BSONObj>{}, BSONObj()}; } - boost::optional<GlobalIndexesCache> getCollectionIndexInfoWithRefresh( + boost::optional<ShardingIndexesCatalogCache> getCollectionIndexInfoWithRefresh( OperationContext* opCtx, const NamespaceString& nss) { return boost::none; } diff --git a/src/mongo/db/s/resharding/resharding_txn_cloner_test.cpp b/src/mongo/db/s/resharding/resharding_txn_cloner_test.cpp index f9819bbe375..5240e118bff 100644 --- a/src/mongo/db/s/resharding/resharding_txn_cloner_test.cpp +++ b/src/mongo/db/s/resharding/resharding_txn_cloner_test.cpp @@ -148,7 +148,8 @@ class ReshardingTxnClonerTest : public ShardServerTestFixture { return repl::OpTimeWith<std::vector<ShardType>>(shardTypes); } - std::pair<CollectionType, std::vector<IndexCatalogType>> getCollectionAndGlobalIndexes( + std::pair<CollectionType, std::vector<IndexCatalogType>> + getCollectionAndShardingIndexCatalogEntries( OperationContext* opCtx, const NamespaceString& nss, const repl::ReadConcernArgs& readConcern) override { diff --git a/src/mongo/db/s/sessions_collection_config_server.cpp b/src/mongo/db/s/sessions_collection_config_server.cpp index 882103b902a..fc6c489fb5d 100644 --- a/src/mongo/db/s/sessions_collection_config_server.cpp +++ b/src/mongo/db/s/sessions_collection_config_server.cpp @@ -80,12 +80,12 @@ void SessionsCollectionConfigServer::_generateIndexesIfNeeded(OperationContext* // (SERVER-61214) wait for the catalog cache to acknowledge that the sessions // collection is sharded in order to be sure to get a valid routing table while (true) { - auto [cm, gii] = uassertStatusOK( + auto [cm, sii] = uassertStatusOK( Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfoWithRefresh(opCtx, nss)); if (cm.isSharded()) { - return CollectionRoutingInfo(std::move(cm), std::move(gii)); + return CollectionRoutingInfo(std::move(cm), std::move(sii)); } } }(); diff --git a/src/mongo/db/s/shard_server_op_observer.cpp b/src/mongo/db/s/shard_server_op_observer.cpp index a141a1f7ebb..75eb77062b6 100644 --- a/src/mongo/db/s/shard_server_op_observer.cpp +++ b/src/mongo/db/s/shard_server_op_observer.cpp @@ -38,12 +38,12 @@ #include "mongo/db/s/collection_critical_section_document_gen.h" #include "mongo/db/s/collection_sharding_runtime.h" #include "mongo/db/s/database_sharding_state.h" -#include "mongo/db/s/global_index_ddl_util.h" #include "mongo/db/s/migration_source_manager.h" #include "mongo/db/s/migration_util.h" #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/s/range_deletion_task_gen.h" #include "mongo/db/s/shard_identity_rollback_notifier.h" +#include "mongo/db/s/sharding_index_catalog_ddl_util.h" #include "mongo/db/s/sharding_initialization_mongod.h" #include "mongo/db/s/sharding_recovery_service.h" #include "mongo/db/s/sharding_state.h" @@ -532,22 +532,23 @@ void ShardServerOpObserver::aboutToDelete(OperationContext* opCtx, } } -void ShardServerOpObserver::onModifyShardedCollectionGlobalIndexCatalogEntry( - OperationContext* opCtx, const NamespaceString& nss, const UUID& uuid, BSONObj indexDoc) { +void ShardServerOpObserver::onModifyCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + BSONObj indexDoc) { // If we are in recovery mode (STARTUP or ROLLBACK) let the sharding recovery service to take // care of the in-memory state. if (sharding_recovery_util::inRecoveryMode(opCtx)) { return; } - LOGV2_DEBUG( - 6712303, - 1, - "Updating sharding in-memory state onModifyShardedCollectionGlobalIndexCatalogEntry", - "indexDoc"_attr = indexDoc); + LOGV2_DEBUG(6712303, + 1, + "Updating sharding in-memory state onModifyCollectionShardingIndexCatalog", + "indexDoc"_attr = indexDoc); auto indexCatalogOplog = ShardingIndexCatalogOplogEntry::parse( - IDLParserContext("onModifyShardedCollectionGlobalIndexCatalogEntry"), indexDoc); + IDLParserContext("onModifyCollectionShardingIndexCatalogCtx"), indexDoc); switch (indexCatalogOplog.getOp()) { - case ShardingIndexCatalogOpEnumEnum::insert: { + case ShardingIndexCatalogOpEnum::insert: { auto indexEntry = ShardingIndexCatalogInsertEntry::parse( IDLParserContext("OplogModifyCatalogEntryContext"), indexDoc); opCtx->recoveryUnit()->onCommit([nss, indexEntry](OperationContext* opCtx, @@ -561,7 +562,7 @@ void ShardServerOpObserver::onModifyShardedCollectionGlobalIndexCatalogEntry( }); break; } - case ShardingIndexCatalogOpEnumEnum::remove: { + case ShardingIndexCatalogOpEnum::remove: { auto removeEntry = ShardingIndexCatalogRemoveEntry::parse( IDLParserContext("OplogModifyCatalogEntryContext"), indexDoc); opCtx->recoveryUnit()->onCommit([nss, removeEntry](OperationContext* opCtx, @@ -574,7 +575,7 @@ void ShardServerOpObserver::onModifyShardedCollectionGlobalIndexCatalogEntry( }); break; } - case ShardingIndexCatalogOpEnumEnum::replace: { + case ShardingIndexCatalogOpEnum::replace: { auto replaceEntry = ShardingIndexCatalogReplaceEntry::parse( IDLParserContext("OplogModifyCatalogEntryContext"), indexDoc); opCtx->recoveryUnit()->onCommit([nss, replaceEntry](OperationContext* opCtx, @@ -587,7 +588,7 @@ void ShardServerOpObserver::onModifyShardedCollectionGlobalIndexCatalogEntry( }); break; } - case ShardingIndexCatalogOpEnumEnum::clear: + case ShardingIndexCatalogOpEnum::clear: opCtx->recoveryUnit()->onCommit([nss](OperationContext* opCtx, boost::optional<Timestamp>) { auto scsr = CollectionShardingRuntime::assertCollectionLockedAndAcquireExclusive( @@ -596,7 +597,7 @@ void ShardServerOpObserver::onModifyShardedCollectionGlobalIndexCatalogEntry( }); break; - case ShardingIndexCatalogOpEnumEnum::drop: { + case ShardingIndexCatalogOpEnum::drop: { opCtx->recoveryUnit()->onCommit([nss](OperationContext* opCtx, boost::optional<Timestamp>) { auto scsr = CollectionShardingRuntime::assertCollectionLockedAndAcquireExclusive( @@ -606,7 +607,7 @@ void ShardServerOpObserver::onModifyShardedCollectionGlobalIndexCatalogEntry( break; } - case ShardingIndexCatalogOpEnumEnum::rename: { + case ShardingIndexCatalogOpEnum::rename: { auto renameEntry = ShardingIndexCatalogRenameEntry::parse( IDLParserContext("OplogModifyCatalogEntryContext"), indexDoc); opCtx->recoveryUnit()->onCommit([renameEntry](OperationContext* opCtx, @@ -617,7 +618,7 @@ void ShardServerOpObserver::onModifyShardedCollectionGlobalIndexCatalogEntry( auto fromCSR = CollectionShardingRuntime::assertCollectionLockedAndAcquireExclusive( opCtx, renameEntry.getFromNss()); - auto indexCache = fromCSR->getIndexes(opCtx, true); + auto indexCache = fromCSR->getIndexesInCritSec(opCtx); indexCache->forEachGlobalIndex([&](const auto& index) { fromIndexes.push_back(index); return true; diff --git a/src/mongo/db/s/shard_server_op_observer.h b/src/mongo/db/s/shard_server_op_observer.h index a6b0d66a32e..396f736c2dd 100644 --- a/src/mongo/db/s/shard_server_op_observer.h +++ b/src/mongo/db/s/shard_server_op_observer.h @@ -45,10 +45,10 @@ public: ShardServerOpObserver(); ~ShardServerOpObserver(); - void onModifyShardedCollectionGlobalIndexCatalogEntry(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - BSONObj indexDoc) override; + void onModifyCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + BSONObj indexDoc) override; void onCreateGlobalIndex(OperationContext* opCtx, const NamespaceString& globalIndexNss, diff --git a/src/mongo/db/s/sharding_catalog_client_aggregations_test.cpp b/src/mongo/db/s/sharding_catalog_client_aggregations_test.cpp index abd0a8d9c60..7bd924b8749 100644 --- a/src/mongo/db/s/sharding_catalog_client_aggregations_test.cpp +++ b/src/mongo/db/s/sharding_catalog_client_aggregations_test.cpp @@ -1079,7 +1079,7 @@ TEST_F(CatalogClientAggregationsTest, TestCollectionAndIndexesAggregationWithNoI BSONObjBuilder().appendMaxKey("_id").obj()), placementVersion, ShardId("shard01"))}); - auto [collection, indexes] = catalogClient()->getCollectionAndGlobalIndexes( + auto [collection, indexes] = catalogClient()->getCollectionAndShardingIndexCatalogEntries( operationContext(), nss, {repl::ReadConcernLevel::kSnapshotReadConcern}); ASSERT_EQ(indexes.size(), 0); @@ -1109,7 +1109,7 @@ TEST_F(CatalogClientAggregationsTest, TestCollectionAndIndexesWithIndexes) { uassertStatusOK(insertToConfigCollection( operationContext(), NamespaceString::kConfigsvrIndexCatalogNamespace, index2.toBSON())); - auto [collection, indexes] = catalogClient()->getCollectionAndGlobalIndexes( + auto [collection, indexes] = catalogClient()->getCollectionAndShardingIndexCatalogEntries( operationContext(), nss, {repl::ReadConcernLevel::kSnapshotReadConcern}); ASSERT_EQ(indexes.size(), 2); @@ -1150,7 +1150,7 @@ TEST_F(CatalogClientAggregationsTest, TestCollectionAndIndexesWithMultipleCollec uassertStatusOK(insertToConfigCollection( operationContext(), NamespaceString::kConfigsvrIndexCatalogNamespace, index2.toBSON())); - auto [collection, indexes] = catalogClient()->getCollectionAndGlobalIndexes( + auto [collection, indexes] = catalogClient()->getCollectionAndShardingIndexCatalogEntries( operationContext(), nssColl1, {repl::ReadConcernLevel::kSnapshotReadConcern}); ASSERT_EQ(indexes.size(), 1); diff --git a/src/mongo/db/s/sharding_ddl_util.cpp b/src/mongo/db/s/sharding_ddl_util.cpp index d28acbc411a..deca970d22b 100644 --- a/src/mongo/db/s/sharding_ddl_util.cpp +++ b/src/mongo/db/s/sharding_ddl_util.cpp @@ -219,9 +219,9 @@ void deleteCollection(OperationContext* opCtx, runTransactionOnShardingCatalog(opCtx, std::move(transactionChain), writeConcern); } -void deleteGlobalIndexesMetadata(OperationContext* opCtx, - const UUID& uuid, - const WriteConcernOptions& writeConcern) { +void deleteShardingIndexCatalogMetadata(OperationContext* opCtx, + const UUID& uuid, + const WriteConcernOptions& writeConcern) { BatchedCommandRequest request([&] { write_ops::DeleteCommandRequest deleteOp(NamespaceString::kConfigsvrIndexCatalogNamespace); deleteOp.setDeletes({[&] { @@ -506,7 +506,7 @@ void removeCollAndChunksMetadataFromConfig(OperationContext* opCtx, deleteChunks(opCtx, uuid, writeConcern); - deleteGlobalIndexesMetadata(opCtx, uuid, writeConcern); + deleteShardingIndexCatalogMetadata(opCtx, uuid, writeConcern); } bool removeCollAndChunksMetadataFromConfig_notIdempotent(OperationContext* opCtx, diff --git a/src/mongo/db/s/global_index_ddl_util.cpp b/src/mongo/db/s/sharding_index_catalog_ddl_util.cpp index 0d1f38c66e7..99102399ecb 100644 --- a/src/mongo/db/s/global_index_ddl_util.cpp +++ b/src/mongo/db/s/sharding_index_catalog_ddl_util.cpp @@ -27,7 +27,7 @@ * it in the license file. */ -#include "mongo/db/s/global_index_ddl_util.h" +#include "mongo/db/s/sharding_index_catalog_ddl_util.h" #include "mongo/db/catalog/collection_write_path.h" #include "mongo/db/concurrency/exception_util.h" @@ -48,9 +48,9 @@ namespace { /** * Remove all indexes by uuid. */ -void deleteGlobalIndexes(OperationContext* opCtx, - const CollectionPtr& collection, - const UUID& uuid) { +void deleteShardingIndexCatalogEntries(OperationContext* opCtx, + const CollectionPtr& collection, + const UUID& uuid) { mongo::deleteObjects(opCtx, collection, NamespaceString::kShardIndexCatalogNamespace, @@ -59,13 +59,13 @@ void deleteGlobalIndexes(OperationContext* opCtx, } } // namespace -void renameGlobalIndexesMetadata(OperationContext* opCtx, - const NamespaceString& fromNss, - const NamespaceString& toNss, - const Timestamp& indexVersion) { +void renameCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& fromNss, + const NamespaceString& toNss, + const Timestamp& indexVersion) { writeConflictRetry( opCtx, - "RenameGlobalIndexesMetadata", + "RenameCollectionShardingIndexCatalog", NamespaceString::kShardIndexCatalogNamespace.ns(), [&]() { boost::optional<UUID> toUuid; @@ -86,14 +86,15 @@ void renameGlobalIndexesMetadata(OperationContext* opCtx, Helpers::findOne(opCtx, collsColl.getCollection(), queryTo, collectionToDoc); if (docExists) { auto collectionTo = ShardAuthoritativeCollectionType::parse( - IDLParserContext("renameGlobalIndexesMetadata"), collectionToDoc); + IDLParserContext("RenameCollectionShardingIndexCatalogCtx"), + collectionToDoc); auto toIndexVersion = collectionTo.getIndexVersion().get_value_or(Timestamp(0, 0)); if (indexVersion <= toIndexVersion) { LOGV2_DEBUG(7079500, 1, - "renameGlobalIndexesMetadata has index version older than " - "current collection index version", + "renameCollectionShardingIndexCatalog has index version older " + "than current collection index version", "collectionIndexVersion"_attr = toIndexVersion, "expectedIndexVersion"_attr = indexVersion, "fromNss"_attr = redact(fromNss.toString()), @@ -120,7 +121,7 @@ void renameGlobalIndexesMetadata(OperationContext* opCtx, Helpers::findOne( opCtx, collsColl.getCollection(), queryFrom, collectionFromDoc)); auto collectionFrom = ShardAuthoritativeCollectionType::parse( - IDLParserContext("renameGlobalIndexesMetadata"), collectionFromDoc); + IDLParserContext("RenameCollectionShardingIndexCatalogCtx"), collectionFromDoc); collectionFrom.setNss(toNss); mongo::deleteObjects(opCtx, @@ -147,25 +148,23 @@ void renameGlobalIndexesMetadata(OperationContext* opCtx, false); } - opCtx->getServiceContext() - ->getOpObserver() - ->onModifyShardedCollectionGlobalIndexCatalogEntry( - opCtx, - fromNss, - idxColl->uuid(), - ShardingIndexCatalogRenameEntry(fromNss, toNss, indexVersion).toBSON()); + opCtx->getServiceContext()->getOpObserver()->onModifyCollectionShardingIndexCatalog( + opCtx, + fromNss, + idxColl->uuid(), + ShardingIndexCatalogRenameEntry(fromNss, toNss, indexVersion).toBSON()); wunit.commit(); }); } -void addGlobalIndexCatalogEntryToCollection(OperationContext* opCtx, - const NamespaceString& userCollectionNss, - const std::string& name, - const BSONObj& keyPattern, - const BSONObj& options, - const UUID& collectionUUID, - const Timestamp& lastmod, - const boost::optional<UUID>& indexCollectionUUID) { +void addShardingIndexCatalogEntryToCollection(OperationContext* opCtx, + const NamespaceString& userCollectionNss, + const std::string& name, + const BSONObj& keyPattern, + const BSONObj& options, + const UUID& collectionUUID, + const Timestamp& lastmod, + const boost::optional<UUID>& indexCollectionUUID) { IndexCatalogType indexCatalogEntry(name, keyPattern, options, lastmod, collectionUUID); indexCatalogEntry.setIndexCollectionUUID(indexCollectionUUID); @@ -194,7 +193,7 @@ void addGlobalIndexCatalogEntryToCollection(OperationContext* opCtx, if (collection.getIndexVersion() && lastmod <= *collection.getIndexVersion()) { LOGV2_DEBUG(6712300, 1, - "addGlobalIndexCatalogEntryToCollection has index version " + "addShardingIndexCatalogEntryToCollection has index version " "older than current collection index version", "collectionIndexVersion"_attr = *collection.getIndexVersion(), "expectedIndexVersion"_attr = lastmod, @@ -231,24 +230,25 @@ void addGlobalIndexCatalogEntryToCollection(OperationContext* opCtx, false)); } - opCtx->getServiceContext() - ->getOpObserver() - ->onModifyShardedCollectionGlobalIndexCatalogEntry( - opCtx, - userCollectionNss, - idxColl->uuid(), - ShardingIndexCatalogInsertEntry(indexCatalogEntry).toBSON()); + opCtx->getServiceContext()->getOpObserver()->onModifyCollectionShardingIndexCatalog( + opCtx, + userCollectionNss, + idxColl->uuid(), + ShardingIndexCatalogInsertEntry(indexCatalogEntry).toBSON()); wunit.commit(); }); } -void removeGlobalIndexCatalogEntryFromCollection(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - const StringData& indexName, - const Timestamp& lastmod) { +void removeShardingIndexCatalogEntryFromCollection(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + const StringData& indexName, + const Timestamp& lastmod) { writeConflictRetry( - opCtx, "RemoveIndexCatalogEntry", NamespaceString::kShardIndexCatalogNamespace.ns(), [&]() { + opCtx, + "RemoveShardingIndexCatalogEntryFromCollection", + NamespaceString::kShardIndexCatalogNamespace.ns(), + [&]() { WriteUnitOfWork wunit(opCtx); AutoGetCollection userColl(opCtx, nss, MODE_IX); AutoGetCollection collsColl(opCtx, @@ -270,8 +270,8 @@ void removeGlobalIndexCatalogEntryFromCollection(OperationContext* opCtx, if (collection.getIndexVersion() && lastmod <= *collection.getIndexVersion()) { LOGV2_DEBUG(6712301, 1, - "removeGlobalIndexCatalogEntryFromCollection has index version " - "older than current collection index version", + "removeShardingIndexCatalogEntryFromCollection has index " + "version older than current collection index version", "collectionIndexVersion"_attr = *collection.getIndexVersion(), "expectedIndexVersion"_attr = lastmod, "nss"_attr = redact(nss.toString())); @@ -304,24 +304,25 @@ void removeGlobalIndexCatalogEntryFromCollection(OperationContext* opCtx, true); } - opCtx->getServiceContext() - ->getOpObserver() - ->onModifyShardedCollectionGlobalIndexCatalogEntry( - opCtx, - nss, - idxColl->uuid(), - ShardingIndexCatalogRemoveEntry(indexName.toString(), uuid, lastmod).toBSON()); + opCtx->getServiceContext()->getOpObserver()->onModifyCollectionShardingIndexCatalog( + opCtx, + nss, + idxColl->uuid(), + ShardingIndexCatalogRemoveEntry(indexName.toString(), uuid, lastmod).toBSON()); wunit.commit(); }); } -void replaceCollectionGlobalIndexes(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - const Timestamp& indexVersion, - const std::vector<IndexCatalogType>& indexes) { +void replaceCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + const Timestamp& indexVersion, + const std::vector<IndexCatalogType>& indexes) { writeConflictRetry( - opCtx, "ReplaceIndexCatalog", NamespaceString::kShardIndexCatalogNamespace.ns(), [&]() { + opCtx, + "ReplaceCollectionShardingIndexCatalog", + NamespaceString::kShardIndexCatalogNamespace.ns(), + [&]() { WriteUnitOfWork wunit(opCtx); AutoGetCollection userColl(opCtx, nss, MODE_IX); AutoGetCollection collsColl(opCtx, @@ -371,7 +372,7 @@ void replaceCollectionGlobalIndexes(OperationContext* opCtx, { // Clear old indexes. repl::UnreplicatedWritesBlock unreplicatedWritesBlock(opCtx); - deleteGlobalIndexes(opCtx, idxColl.getCollection(), uuid); + deleteShardingIndexCatalogEntries(opCtx, idxColl.getCollection(), uuid); // Add new indexes. for (const auto& i : indexes) { @@ -390,20 +391,21 @@ void replaceCollectionGlobalIndexes(OperationContext* opCtx, } } - opCtx->getServiceContext() - ->getOpObserver() - ->onModifyShardedCollectionGlobalIndexCatalogEntry( - opCtx, - nss, - idxColl->uuid(), - ShardingIndexCatalogReplaceEntry(uuid, indexVersion, indexes).toBSON()); + opCtx->getServiceContext()->getOpObserver()->onModifyCollectionShardingIndexCatalog( + opCtx, + nss, + idxColl->uuid(), + ShardingIndexCatalogReplaceEntry(uuid, indexVersion, indexes).toBSON()); wunit.commit(); }); } -void dropCollectionGlobalIndexesMetadata(OperationContext* opCtx, const NamespaceString& nss) { +void dropCollectionShardingIndexCatalog(OperationContext* opCtx, const NamespaceString& nss) { writeConflictRetry( - opCtx, "DropIndexCatalogEntry", NamespaceString::kShardIndexCatalogNamespace.ns(), [&]() { + opCtx, + "DropCollectionShardingIndexCatalog", + NamespaceString::kShardIndexCatalogNamespace.ns(), + [&]() { boost::optional<UUID> collectionUUID; WriteUnitOfWork wunit(opCtx); Lock::DBLock dbLock(opCtx, nss.dbName(), MODE_IX); @@ -427,7 +429,7 @@ void dropCollectionGlobalIndexesMetadata(OperationContext* opCtx, const Namespac return; } auto collection = ShardAuthoritativeCollectionType::parse( - IDLParserContext("DropIndexCatalogEntry"), collectionDoc); + IDLParserContext("dropCollectionShardingIndexCatalog"), collectionDoc); collectionUUID.emplace(collection.getUuid()); repl::UnreplicatedWritesBlock unreplicatedWritesBlock(opCtx); mongo::deleteObjects(opCtx, @@ -441,25 +443,26 @@ void dropCollectionGlobalIndexesMetadata(OperationContext* opCtx, const Namespac { repl::UnreplicatedWritesBlock unreplicatedWritesBlock(opCtx); - deleteGlobalIndexes(opCtx, idxColl.getCollection(), *collectionUUID); + deleteShardingIndexCatalogEntries(opCtx, idxColl.getCollection(), *collectionUUID); } - opCtx->getServiceContext() - ->getOpObserver() - ->onModifyShardedCollectionGlobalIndexCatalogEntry( - opCtx, - nss, - idxColl->uuid(), - ShardingIndexCatalogDropEntry(*collectionUUID).toBSON()); + opCtx->getServiceContext()->getOpObserver()->onModifyCollectionShardingIndexCatalog( + opCtx, + nss, + idxColl->uuid(), + ShardingIndexCatalogDropEntry(*collectionUUID).toBSON()); wunit.commit(); }); } -void clearCollectionGlobalIndexes(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid) { +void clearCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid) { writeConflictRetry( - opCtx, "ClearIndexCatalogEntry", NamespaceString::kShardIndexCatalogNamespace.ns(), [&]() { + opCtx, + "ClearCollectionShardingIndexCatalog", + NamespaceString::kShardIndexCatalogNamespace.ns(), + [&]() { WriteUnitOfWork wunit(opCtx); AutoGetCollection userColl(opCtx, nss, MODE_IX); AutoGetCollection collsColl(opCtx, @@ -482,7 +485,7 @@ void clearCollectionGlobalIndexes(OperationContext* opCtx, } auto collection = ShardAuthoritativeCollectionType::parse( - IDLParserContext("ClearIndexCatalogEntry"), collectionDoc); + IDLParserContext("clearCollectionShardingIndexCatalogCtx"), collectionDoc); if (!collection.getIndexVersion()) { return; @@ -506,13 +509,11 @@ void clearCollectionGlobalIndexes(OperationContext* opCtx, { repl::UnreplicatedWritesBlock unreplicatedWritesBlock(opCtx); - deleteGlobalIndexes(opCtx, idxColl.getCollection(), uuid); + deleteShardingIndexCatalogEntries(opCtx, idxColl.getCollection(), uuid); } - opCtx->getServiceContext() - ->getOpObserver() - ->onModifyShardedCollectionGlobalIndexCatalogEntry( - opCtx, nss, idxColl->uuid(), ShardingIndexCatalogClearEntry(uuid).toBSON()); + opCtx->getServiceContext()->getOpObserver()->onModifyCollectionShardingIndexCatalog( + opCtx, nss, idxColl->uuid(), ShardingIndexCatalogClearEntry(uuid).toBSON()); wunit.commit(); }); } diff --git a/src/mongo/db/s/global_index_ddl_util.h b/src/mongo/db/s/sharding_index_catalog_ddl_util.h index 9874c1b6d75..bcef36eb837 100644 --- a/src/mongo/db/s/global_index_ddl_util.h +++ b/src/mongo/db/s/sharding_index_catalog_ddl_util.h @@ -39,10 +39,10 @@ namespace mongo { * migrations and holding the critical section in all shards with data for userCollectionNss. This * function is not currently compatible with transactions. */ -void renameGlobalIndexesMetadata(OperationContext* opCtx, - const NamespaceString& fromNss, - const NamespaceString& toNss, - const Timestamp& indexVersion); +void renameCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& fromNss, + const NamespaceString& toNss, + const Timestamp& indexVersion); /** * Adds a new index entry into the in-memory catalog and persist it to disk. It effectively executes @@ -50,14 +50,14 @@ void renameGlobalIndexesMetadata(OperationContext* opCtx, * section in all shards with data for userCollectionNss. This function is not currently compatible * with transactions. */ -void addGlobalIndexCatalogEntryToCollection(OperationContext* opCtx, - const NamespaceString& userCollectionNss, - const std::string& name, - const BSONObj& keyPattern, - const BSONObj& options, - const UUID& collectionUUID, - const Timestamp& lastmod, - const boost::optional<UUID>& indexCollectionUUID); +void addShardingIndexCatalogEntryToCollection(OperationContext* opCtx, + const NamespaceString& userCollectionNss, + const std::string& name, + const BSONObj& keyPattern, + const BSONObj& options, + const UUID& collectionUUID, + const Timestamp& lastmod, + const boost::optional<UUID>& indexCollectionUUID); /** * Removes the index identified by indexName from the catalog. This function updates the in-memory @@ -65,11 +65,11 @@ void addGlobalIndexCatalogEntryToCollection(OperationContext* opCtx, * the critical section in all shards with data for nss. This function is not * currently compatible with transactions. */ -void removeGlobalIndexCatalogEntryFromCollection(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - const StringData& indexName, - const Timestamp& lastmod); +void removeShardingIndexCatalogEntryFromCollection(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + const StringData& indexName, + const Timestamp& lastmod); /** * Removes all the indexes and the current index version, and replace them for the specified indexes @@ -77,26 +77,26 @@ void removeGlobalIndexCatalogEntryFromCollection(OperationContext* opCtx, * critical section in all shards with data for userCollectionNss. This function is not currently * compatible with transactions. */ -void replaceCollectionGlobalIndexes(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - const Timestamp& indexVersion, - const std::vector<IndexCatalogType>& indexes); +void replaceCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + const Timestamp& indexVersion, + const std::vector<IndexCatalogType>& indexes); /** * Drops all indexes and the collection entry. This function should only be called after stopping * migrations and holding the critical section in all shards with data for userCollectionNss. This * function is not currently compatible with transactions. */ -void dropCollectionGlobalIndexesMetadata(OperationContext* opCtx, const NamespaceString& nss); +void dropCollectionShardingIndexCatalog(OperationContext* opCtx, const NamespaceString& nss); /** * Removes all the indexes and unset the current index version. This function should only be called * after stopping migrations and holding the critical section in all shards with data for * userCollectionNss. This function is not currently compatible with transactions. */ -void clearCollectionGlobalIndexes(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid); +void clearCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid); } // namespace mongo diff --git a/src/mongo/db/s/sharding_recovery_service.cpp b/src/mongo/db/s/sharding_recovery_service.cpp index dc24d5be0d3..828a092a048 100644 --- a/src/mongo/db/s/sharding_recovery_service.cpp +++ b/src/mongo/db/s/sharding_recovery_service.cpp @@ -69,7 +69,7 @@ bool inRecoveryMode(OperationContext* opCtx) { } // namespace sharding_recovery_util namespace { -const StringData kGlobalIndexesFieldName = "globalIndexes"_sd; +const StringData kShardingIndexCatalogEntriesFieldName = "indexes"_sd; const auto serviceDecorator = ServiceContext::declareDecoration<ShardingRecoveryService>(); AggregateCommandRequest makeCollectionsAndIndexesAggregation(OperationContext* opCtx) { @@ -104,18 +104,18 @@ AggregateCommandRequest makeCollectionsAndIndexesAggregation(OperationContext* o // config.shard.collections document. // // The $lookup stage gets the config.shard.indexes documents and puts them in a field called - // "globalIndexes" in the document produced during stage 1. + // "indexes" in the document produced during stage 1. // // { // $lookup: { // from: "shard.indexes", - // as: "globalIndexes", + // as: "indexes", // localField: "uuid", // foreignField: "collectionUUID" // } // } const Doc lookupPipeline{{"from", NamespaceString::kShardIndexCatalogNamespace.coll()}, - {"as", kGlobalIndexesFieldName}, + {"as", kShardingIndexCatalogEntriesFieldName}, {"localField", ShardAuthoritativeCollectionType::kUuidFieldName}, {"foreignField", IndexCatalogType::kCollectionUUIDFieldName}}; @@ -618,7 +618,7 @@ void ShardingRecoveryService::recoverIndexesCatalog(OperationContext* opCtx) { auto doc = cursor->nextSafe(); auto nss = NamespaceString(doc[CollectionType::kNssFieldName].String()); auto indexVersion = doc[CollectionType::kIndexVersionFieldName].timestamp(); - for (const auto& idx : doc[kGlobalIndexesFieldName].Array()) { + for (const auto& idx : doc[kShardingIndexCatalogEntriesFieldName].Array()) { auto indexEntry = IndexCatalogType::parse( IDLParserContext("recoverIndexesCatalogContext"), idx.Obj()); AutoGetCollection collLock(opCtx, nss, MODE_X); diff --git a/src/mongo/db/s/sharding_util.cpp b/src/mongo/db/s/sharding_util.cpp index 47d86cad7a7..483193445f6 100644 --- a/src/mongo/db/s/sharding_util.cpp +++ b/src/mongo/db/s/sharding_util.cpp @@ -212,7 +212,7 @@ Status createIndexOnCollection(OperationContext* opCtx, return Status::OK(); } -Status createGlobalIndexesIndexes(OperationContext* opCtx) { +Status createShardingIndexCatalogIndexes(OperationContext* opCtx) { bool unique = true; NamespaceString indexCatalogNamespace; if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) { diff --git a/src/mongo/db/s/sharding_util.h b/src/mongo/db/s/sharding_util.h index f58d88d93c8..afab57904a7 100644 --- a/src/mongo/db/s/sharding_util.h +++ b/src/mongo/db/s/sharding_util.h @@ -88,9 +88,9 @@ std::vector<AsyncRequestsSender::Response> sendCommandToShardsWithVersion( bool throwOnError = true); /** - * Creates the necessary indexes for the globalIndexes collections. + * Creates the necessary indexes for the sharding index catalog collections. */ -Status createGlobalIndexesIndexes(OperationContext* opCtx); +Status createShardingIndexCatalogIndexes(OperationContext* opCtx); /** * Creates the necessary indexes for the collections collection. diff --git a/src/mongo/db/s/shardsvr_commit_index_participant_command.cpp b/src/mongo/db/s/shardsvr_commit_index_participant_command.cpp index bab4b483342..72c3cb33d71 100644 --- a/src/mongo/db/s/shardsvr_commit_index_participant_command.cpp +++ b/src/mongo/db/s/shardsvr_commit_index_participant_command.cpp @@ -32,8 +32,8 @@ #include "mongo/db/commands.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/s/collection_sharding_runtime.h" -#include "mongo/db/s/global_index_ddl_util.h" #include "mongo/db/s/sharded_index_catalog_commands_gen.h" +#include "mongo/db/s/sharding_index_catalog_ddl_util.h" #include "mongo/db/s/sharding_index_catalog_util.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/transaction/transaction_participant.h" @@ -105,14 +105,14 @@ public: } opCtx->setAlwaysInterruptAtStepDownOrUp_UNSAFE(); - addGlobalIndexCatalogEntryToCollection(opCtx, - ns(), - request().getName().toString(), - request().getKeyPattern(), - request().getOptions(), - request().getCollectionUUID(), - request().getLastmod(), - request().getIndexCollectionUUID()); + addShardingIndexCatalogEntryToCollection(opCtx, + ns(), + request().getName().toString(), + request().getKeyPattern(), + request().getOptions(), + request().getCollectionUUID(), + request().getLastmod(), + request().getIndexCollectionUUID()); } private: diff --git a/src/mongo/db/s/shardsvr_drop_index_catalog_entry_participant_command.cpp b/src/mongo/db/s/shardsvr_drop_index_catalog_entry_participant_command.cpp index 38c11cfe5f3..9d65051ec8c 100644 --- a/src/mongo/db/s/shardsvr_drop_index_catalog_entry_participant_command.cpp +++ b/src/mongo/db/s/shardsvr_drop_index_catalog_entry_participant_command.cpp @@ -32,8 +32,8 @@ #include "mongo/db/commands.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/s/collection_sharding_runtime.h" -#include "mongo/db/s/global_index_ddl_util.h" #include "mongo/db/s/sharded_index_catalog_commands_gen.h" +#include "mongo/db/s/sharding_index_catalog_ddl_util.h" #include "mongo/db/s/sharding_index_catalog_util.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/transaction/transaction_participant.h" @@ -104,11 +104,11 @@ public: } opCtx->setAlwaysInterruptAtStepDownOrUp_UNSAFE(); - removeGlobalIndexCatalogEntryFromCollection(opCtx, - ns(), - request().getCollectionUUID(), - request().getName(), - request().getLastmod()); + removeShardingIndexCatalogEntryFromCollection(opCtx, + ns(), + request().getCollectionUUID(), + request().getName(), + request().getLastmod()); } private: diff --git a/src/mongo/db/s/shardsvr_rename_index_metadata_command.cpp b/src/mongo/db/s/shardsvr_rename_index_metadata_command.cpp index 2a9a5b9591b..769baf15c2c 100644 --- a/src/mongo/db/s/shardsvr_rename_index_metadata_command.cpp +++ b/src/mongo/db/s/shardsvr_rename_index_metadata_command.cpp @@ -31,8 +31,8 @@ #include "mongo/db/commands.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/s/collection_sharding_runtime.h" -#include "mongo/db/s/global_index_ddl_util.h" #include "mongo/db/s/sharded_index_catalog_commands_gen.h" +#include "mongo/db/s/sharding_index_catalog_ddl_util.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/transaction/transaction_participant.h" #include "mongo/logv2/log.h" @@ -108,7 +108,7 @@ public: ns().toString()), scopedCsr->getCriticalSectionSignal( opCtx, ShardingMigrationCriticalSection::kWrite)); - if (scopedCsr->getIndexes(opCtx, true)) { + if (scopedCsr->getIndexesInCritSec(opCtx)) { renameOp = RenameIndexCatalogOperationEnum::kRename; } } @@ -125,7 +125,7 @@ public: ns().toString()), scopedToCsr->getCriticalSectionSignal( opCtx, ShardingMigrationCriticalSection::kWrite)); - const auto& indexMetadata = scopedToCsr->getIndexes(opCtx, true); + const auto& indexMetadata = scopedToCsr->getIndexesInCritSec(opCtx); if (indexMetadata && indexMetadata->getCollectionIndexes().uuid() == request().getIndexVersion().uuid()) { @@ -139,13 +139,15 @@ public: switch (renameOp) { case RenameIndexCatalogOperationEnum::kRename: - renameGlobalIndexesMetadata(opCtx, - ns(), - request().getToNss(), - request().getIndexVersion().indexVersion()); + renameCollectionShardingIndexCatalog( + opCtx, + ns(), + request().getToNss(), + request().getIndexVersion().indexVersion()); break; case RenameIndexCatalogOperationEnum::kClearTo: - clearCollectionGlobalIndexes(opCtx, request().getToNss(), toUuid.value()); + clearCollectionShardingIndexCatalog( + opCtx, request().getToNss(), toUuid.value()); break; case RenameIndexCatalogOperationEnum::kNoop: { // Since no write happened on this txnNumber, we need to make a dummy write diff --git a/src/mongo/db/serverless/shard_split_donor_op_observer.h b/src/mongo/db/serverless/shard_split_donor_op_observer.h index f8f14328802..1e17c232cf6 100644 --- a/src/mongo/db/serverless/shard_split_donor_op_observer.h +++ b/src/mongo/db/serverless/shard_split_donor_op_observer.h @@ -44,10 +44,10 @@ public: ShardSplitDonorOpObserver() = default; ~ShardSplitDonorOpObserver() = default; - void onModifyShardedCollectionGlobalIndexCatalogEntry(OperationContext* opCtx, - const NamespaceString& nss, - const UUID& uuid, - BSONObj indexDoc) final {} + void onModifyCollectionShardingIndexCatalog(OperationContext* opCtx, + const NamespaceString& nss, + const UUID& uuid, + BSONObj indexDoc) final {} void onCreateGlobalIndex(OperationContext* opCtx, const NamespaceString& globalIndexNss, |