diff options
author | Marcos José Grillo Ramirez <marcos.grillo@mongodb.com> | 2023-03-03 18:00:25 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-03-04 00:24:45 +0000 |
commit | dce4b62e25f4d62b2990e4faff54a6702eeb24c0 (patch) | |
tree | 71fd9f1d095aa3c15bfd6cbcca86aff872242a74 | |
parent | 23a26b5dad45d12187b61a1e5e49c60c5be26632 (diff) | |
download | mongo-dce4b62e25f4d62b2990e4faff54a6702eeb24c0.tar.gz |
SERVER-70789 Rename sharding global indexes utilities to reflect globalness of the API
86 files changed, 564 insertions, 529 deletions
diff --git a/jstests/sharding/global_index_sharding_catalog_API.js b/jstests/sharding/sharding_index_catalog_API.js index 40cb0de806b..40cb0de806b 100644 --- a/jstests/sharding/global_index_sharding_catalog_API.js +++ b/jstests/sharding/sharding_index_catalog_API.js diff --git a/jstests/sharding/global_index_sharding_catalog_collection_upgrade_downgrade.js b/jstests/sharding/sharding_index_catalog_upgrade_downgrade.js index 75782689a39..75782689a39 100644 --- a/jstests/sharding/global_index_sharding_catalog_collection_upgrade_downgrade.js +++ b/jstests/sharding/sharding_index_catalog_upgrade_downgrade.js 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, diff --git a/src/mongo/idl/cluster_server_parameter_op_observer.h b/src/mongo/idl/cluster_server_parameter_op_observer.h index 0a961e99719..ac93383461c 100644 --- a/src/mongo/idl/cluster_server_parameter_op_observer.h +++ b/src/mongo/idl/cluster_server_parameter_op_observer.h @@ -100,10 +100,11 @@ 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/s/SConscript b/src/mongo/s/SConscript index 3b104f8ab1a..08895150fbe 100644 --- a/src/mongo/s/SConscript +++ b/src/mongo/s/SConscript @@ -319,7 +319,7 @@ env.Library( 'catalog_cache.cpp', 'client/shard_factory.cpp', 'client/shard_registry.cpp', - 'global_index_cache.cpp', + 'sharding_index_catalog_cache.cpp', 'grid.cpp', ], LIBDEPS=[ @@ -667,7 +667,7 @@ env.CppUnitTest( 'comparable_chunk_version_test.cpp', 'comparable_database_version_test.cpp', 'comparable_index_version_test.cpp', - 'global_index_cache_test.cpp', + 'sharding_index_catalog_cache_test.cpp', 'load_balancer_support_test.cpp', 'mock_ns_targeter.cpp', 'mongos_core_options_stub.cpp', diff --git a/src/mongo/s/catalog/sharding_catalog_client.h b/src/mongo/s/catalog/sharding_catalog_client.h index 36fa1290999..366ad9cfb36 100644 --- a/src/mongo/s/catalog/sharding_catalog_client.h +++ b/src/mongo/s/catalog/sharding_catalog_client.h @@ -202,10 +202,10 @@ public: * Retrieves the collection metadata and its global index metadata. This function will return * all of the global idexes for a collection. */ - virtual std::pair<CollectionType, std::vector<IndexCatalogType>> getCollectionAndGlobalIndexes( - OperationContext* opCtx, - const NamespaceString& nss, - const repl::ReadConcernArgs& readConcern) = 0; + virtual std::pair<CollectionType, std::vector<IndexCatalogType>> + getCollectionAndShardingIndexCatalogEntries(OperationContext* opCtx, + const NamespaceString& nss, + const repl::ReadConcernArgs& readConcern) = 0; /** * Retrieves all zones defined for the specified collection. The returned vector is sorted based diff --git a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp index 4f8f4a15713..7bb4579f0a4 100644 --- a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp +++ b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp @@ -788,9 +788,8 @@ std::pair<CollectionType, std::vector<ChunkType>> ShardingCatalogClientImpl::get }; std::pair<CollectionType, std::vector<IndexCatalogType>> -ShardingCatalogClientImpl::getCollectionAndGlobalIndexes(OperationContext* opCtx, - const NamespaceString& nss, - const repl::ReadConcernArgs& readConcern) { +ShardingCatalogClientImpl::getCollectionAndShardingIndexCatalogEntries( + OperationContext* opCtx, const NamespaceString& nss, const repl::ReadConcernArgs& readConcern) { auto aggRequest = makeCollectionAndIndexesAggregation(opCtx, nss); std::vector<BSONObj> aggResult = runCatalogAggregation(opCtx, diff --git a/src/mongo/s/catalog/sharding_catalog_client_impl.h b/src/mongo/s/catalog/sharding_catalog_client_impl.h index 34b535000f0..980d5c6b0fb 100644 --- a/src/mongo/s/catalog/sharding_catalog_client_impl.h +++ b/src/mongo/s/catalog/sharding_catalog_client_impl.h @@ -108,10 +108,10 @@ public: const ChunkVersion& sinceVersion, const repl::ReadConcernArgs& readConcern) override; - std::pair<CollectionType, std::vector<IndexCatalogType>> getCollectionAndGlobalIndexes( - OperationContext* opCtx, - const NamespaceString& nss, - const repl::ReadConcernArgs& readConcern) override; + std::pair<CollectionType, std::vector<IndexCatalogType>> + getCollectionAndShardingIndexCatalogEntries(OperationContext* opCtx, + const NamespaceString& nss, + const repl::ReadConcernArgs& readConcern) override; StatusWith<std::vector<TagsType>> getTagsForCollection(OperationContext* opCtx, const NamespaceString& nss) override; diff --git a/src/mongo/s/catalog/sharding_catalog_client_mock.cpp b/src/mongo/s/catalog/sharding_catalog_client_mock.cpp index b803b561185..c888086d04d 100644 --- a/src/mongo/s/catalog/sharding_catalog_client_mock.cpp +++ b/src/mongo/s/catalog/sharding_catalog_client_mock.cpp @@ -108,9 +108,8 @@ std::pair<CollectionType, std::vector<ChunkType>> ShardingCatalogClientMock::get } std::pair<CollectionType, std::vector<IndexCatalogType>> -ShardingCatalogClientMock::getCollectionAndGlobalIndexes(OperationContext* opCtx, - const NamespaceString& nss, - const repl::ReadConcernArgs& readConcern) { +ShardingCatalogClientMock::getCollectionAndShardingIndexCatalogEntries( + OperationContext* opCtx, const NamespaceString& nss, const repl::ReadConcernArgs& readConcern) { uasserted(ErrorCodes::InternalError, "Method not implemented"); } diff --git a/src/mongo/s/catalog/sharding_catalog_client_mock.h b/src/mongo/s/catalog/sharding_catalog_client_mock.h index eb88d04989b..02ff3a8fc49 100644 --- a/src/mongo/s/catalog/sharding_catalog_client_mock.h +++ b/src/mongo/s/catalog/sharding_catalog_client_mock.h @@ -83,10 +83,10 @@ public: const ChunkVersion& sinceVersion, const repl::ReadConcernArgs& readConcern) override; - std::pair<CollectionType, std::vector<IndexCatalogType>> getCollectionAndGlobalIndexes( - OperationContext* opCtx, - const NamespaceString& nss, - const repl::ReadConcernArgs& readConcern) override; + std::pair<CollectionType, std::vector<IndexCatalogType>> + getCollectionAndShardingIndexCatalogEntries(OperationContext* opCtx, + const NamespaceString& nss, + const repl::ReadConcernArgs& readConcern) override; StatusWith<std::vector<TagsType>> getTagsForCollection(OperationContext* opCtx, const NamespaceString& nss) override; diff --git a/src/mongo/s/catalog/type_index_catalog.cpp b/src/mongo/s/catalog/type_index_catalog.cpp index 337e0ba2419..64a95f8e25d 100644 --- a/src/mongo/s/catalog/type_index_catalog.cpp +++ b/src/mongo/s/catalog/type_index_catalog.cpp @@ -34,7 +34,7 @@ namespace mongo { ShardingIndexCatalogInsertEntry::ShardingIndexCatalogInsertEntry(const IndexCatalogType& idx) { setI(idx); setShardingIndexCatalogOplogEntry( - ShardingIndexCatalogOplogEntry(ShardingIndexCatalogOpEnumEnum::insert)); + ShardingIndexCatalogOplogEntry(ShardingIndexCatalogOpEnum::insert)); } ShardingIndexCatalogRemoveEntry::ShardingIndexCatalogRemoveEntry(const std::string& name, @@ -42,20 +42,20 @@ ShardingIndexCatalogRemoveEntry::ShardingIndexCatalogRemoveEntry(const std::stri const Timestamp& lastmod) : ShardingIndexCatalogRemoveEntryBase(name, uuid, lastmod) { setShardingIndexCatalogOplogEntry( - ShardingIndexCatalogOplogEntry(ShardingIndexCatalogOpEnumEnum::remove)); + ShardingIndexCatalogOplogEntry(ShardingIndexCatalogOpEnum::remove)); } ShardingIndexCatalogReplaceEntry::ShardingIndexCatalogReplaceEntry( const UUID& uuid, const Timestamp& lastmod, const std::vector<IndexCatalogType>& i) : ShardingIndexCatalogReplaceEntryBase(uuid, lastmod, i) { setShardingIndexCatalogOplogEntry( - ShardingIndexCatalogOplogEntry(ShardingIndexCatalogOpEnumEnum::replace)); + ShardingIndexCatalogOplogEntry(ShardingIndexCatalogOpEnum::replace)); } ShardingIndexCatalogDropEntry::ShardingIndexCatalogDropEntry(const UUID& uuid) : ShardingIndexCatalogDropEntryBase(uuid) { setShardingIndexCatalogOplogEntry( - ShardingIndexCatalogOplogEntry(ShardingIndexCatalogOpEnumEnum::drop)); + ShardingIndexCatalogOplogEntry(ShardingIndexCatalogOpEnum::drop)); } @@ -64,13 +64,13 @@ ShardingIndexCatalogRenameEntry::ShardingIndexCatalogRenameEntry(const Namespace const Timestamp& lastmod) : ShardingIndexCatalogRenameEntryBase(fromNss, toNss, lastmod) { setShardingIndexCatalogOplogEntry( - ShardingIndexCatalogOplogEntry(ShardingIndexCatalogOpEnumEnum::rename)); + ShardingIndexCatalogOplogEntry(ShardingIndexCatalogOpEnum::rename)); } ShardingIndexCatalogClearEntry::ShardingIndexCatalogClearEntry(const UUID& uuid) : ShardingIndexCatalogClearEntryBase(uuid) { setShardingIndexCatalogOplogEntry( - ShardingIndexCatalogOplogEntry(ShardingIndexCatalogOpEnumEnum::clear)); + ShardingIndexCatalogOplogEntry(ShardingIndexCatalogOpEnum::clear)); } } // namespace mongo diff --git a/src/mongo/s/catalog/type_index_catalog.h b/src/mongo/s/catalog/type_index_catalog.h index 4d3d3f9b22a..b3b9a6daf0b 100644 --- a/src/mongo/s/catalog/type_index_catalog.h +++ b/src/mongo/s/catalog/type_index_catalog.h @@ -33,6 +33,8 @@ namespace mongo { +static constexpr auto kShardingIndexCatalogOplogEntryName = "modifyCollectionShardingIndexCatalog"; + class ShardingIndexCatalogInsertEntry : public ShardingIndexCatalogInsertEntryBase { public: ShardingIndexCatalogInsertEntry(const IndexCatalogType& idx); diff --git a/src/mongo/s/catalog/type_index_catalog.idl b/src/mongo/s/catalog/type_index_catalog.idl index d252345fe5d..aa1cec48481 100644 --- a/src/mongo/s/catalog/type_index_catalog.idl +++ b/src/mongo/s/catalog/type_index_catalog.idl @@ -33,7 +33,7 @@ imports: - "mongo/db/basic_types.idl" enums: - ShardingIndexCatalogOpEnum: + ShardingIndexCatalogOp: description: "Sharding index catalog operation" type: string values: @@ -84,7 +84,7 @@ structs: strict: false fields: op: - type: ShardingIndexCatalogOpEnum + type: ShardingIndexCatalogOp description: "Index catalog operation type" ShardingIndexCatalogInsertEntryBase: diff --git a/src/mongo/s/catalog_cache.cpp b/src/mongo/s/catalog_cache.cpp index 218d76fc7a1..5f600abc056 100644 --- a/src/mongo/s/catalog_cache.cpp +++ b/src/mongo/s/catalog_cache.cpp @@ -173,39 +173,39 @@ StatusWith<CollectionRoutingInfo> retryUntilConsistentRoutingInfo( OperationContext* opCtx, const NamespaceString& nss, ChunkManager&& cm, - boost::optional<GlobalIndexesCache>&& gii) { + boost::optional<ShardingIndexesCatalogCache>&& sii) { const auto catalogCache = Grid::get(opCtx)->catalogCache(); try { - // A non-empty GlobalIndexesCache implies that the collection is sharded since global - // indexes cannot be created on unsharded collections. - while (gii && (!cm.isSharded() || !cm.uuidMatches(gii->getCollectionIndexes().uuid()))) { - auto nextGii = + // A non-empty ShardingIndexesCatalogCache implies that the collection is sharded since + // global indexes cannot be created on unsharded collections. + while (sii && (!cm.isSharded() || !cm.uuidMatches(sii->getCollectionIndexes().uuid()))) { + auto nextSii = uassertStatusOK(catalogCache->getCollectionRoutingInfoWithIndexRefresh(opCtx, nss)) - .gii; - if (gii.is_initialized() && nextGii.is_initialized() && - gii->getCollectionIndexes() == nextGii->getCollectionIndexes()) { + .sii; + if (sii.is_initialized() && nextSii.is_initialized() && + sii->getCollectionIndexes() == nextSii->getCollectionIndexes()) { cm = uassertStatusOK( catalogCache->getCollectionRoutingInfoWithPlacementRefresh(opCtx, nss)) .cm; } - gii = std::move(nextGii); + sii = std::move(nextSii); } } catch (const DBException& ex) { return ex.toStatus(); } - return CollectionRoutingInfo{std::move(cm), std::move(gii)}; + return CollectionRoutingInfo{std::move(cm), std::move(sii)}; } } // namespace ShardVersion CollectionRoutingInfo::getCollectionVersion() const { return ShardVersionFactory::make( - cm, gii ? boost::make_optional(gii->getCollectionIndexes()) : boost::none); + cm, sii ? boost::make_optional(sii->getCollectionIndexes()) : boost::none); } ShardVersion CollectionRoutingInfo::getShardVersion(const ShardId& shardId) const { return ShardVersionFactory::make( - cm, shardId, gii ? boost::make_optional(gii->getCollectionIndexes()) : boost::none); + cm, shardId, sii ? boost::make_optional(sii->getCollectionIndexes()) : boost::none); } AtomicWord<uint64_t> ComparableDatabaseVersion::_disambiguatingSequenceNumSource{1ULL}; @@ -430,8 +430,8 @@ StatusWith<CollectionRoutingInfo> CatalogCache::getCollectionRoutingInfoAt( OperationContext* opCtx, const NamespaceString& nss, Timestamp atClusterTime) { try { auto cm = uassertStatusOK(_getCollectionPlacementInfoAt(opCtx, nss, atClusterTime)); - auto gii = _getCollectionIndexInfoAt(opCtx, nss); - return retryUntilConsistentRoutingInfo(opCtx, nss, std::move(cm), std::move(gii)); + auto sii = _getCollectionIndexInfoAt(opCtx, nss); + return retryUntilConsistentRoutingInfo(opCtx, nss, std::move(cm), std::move(sii)); } catch (const DBException& ex) { return ex.toStatus(); } @@ -443,14 +443,14 @@ StatusWith<CollectionRoutingInfo> CatalogCache::getCollectionRoutingInfo(Operati try { auto cm = uassertStatusOK(_getCollectionPlacementInfoAt(opCtx, nss, boost::none, allowLocks)); - auto gii = _getCollectionIndexInfoAt(opCtx, nss, allowLocks); - return retryUntilConsistentRoutingInfo(opCtx, nss, std::move(cm), std::move(gii)); + auto sii = _getCollectionIndexInfoAt(opCtx, nss, allowLocks); + return retryUntilConsistentRoutingInfo(opCtx, nss, std::move(cm), std::move(sii)); } catch (const DBException& ex) { return ex.toStatus(); } } -boost::optional<GlobalIndexesCache> CatalogCache::_getCollectionIndexInfoAt( +boost::optional<ShardingIndexesCatalogCache> CatalogCache::_getCollectionIndexInfoAt( OperationContext* opCtx, const NamespaceString& nss, bool allowLocks) { if (!feature_flags::gGlobalIndexesShardingCatalog.isEnabledAndIgnoreFCV()) { @@ -497,7 +497,7 @@ boost::optional<GlobalIndexesCache> CatalogCache::_getCollectionIndexInfoAt( uassert(ShardCannotRefreshDueToLocksHeldInfo(nss), "Index info refresh did not complete", indexEntryFuture.isReady()); - return indexEntryFuture.get(opCtx)->optGii; + return indexEntryFuture.get(opCtx)->optSii; } // From this point we can guarantee that allowLocks is false @@ -509,7 +509,7 @@ boost::optional<GlobalIndexesCache> CatalogCache::_getCollectionIndexInfoAt( try { auto indexEntry = indexEntryFuture.get(opCtx); - return indexEntry->optGii; + return indexEntry->optSii; } catch (const DBException& ex) { bool isCatalogCacheRetriableError = ex.isA<ErrorCategory::SnapshotError>() || ex.code() == ErrorCodes::ConflictingOperationInProgress || @@ -1048,8 +1048,9 @@ CatalogCache::IndexCache::LookupResult CatalogCache::IndexCache::_lookupIndexes( return {vcTime.configTime(), repl::ReadConcernLevel::kSnapshotReadConcern}; } }(); - auto collAndIndexes = Grid::get(opCtx)->catalogClient()->getCollectionAndGlobalIndexes( - opCtx, nss, readConcern); + auto collAndIndexes = + Grid::get(opCtx)->catalogClient()->getCollectionAndShardingIndexCatalogEntries( + opCtx, nss, readConcern); const auto& coll = collAndIndexes.first; const auto& indexVersion = coll.getIndexVersion(); newComparableVersion.setCollectionIndexes( @@ -1063,7 +1064,8 @@ CatalogCache::IndexCache::LookupResult CatalogCache::IndexCache::_lookupIndexes( "timeInStore"_attr = previousVersion); if (!indexVersion) { - return LookupResult(OptionalGlobalIndexesInfo(), std::move(newComparableVersion)); + return LookupResult(OptionalShardingIndexCatalogInfo(), + std::move(newComparableVersion)); } IndexCatalogTypeMap newIndexesMap; @@ -1071,16 +1073,17 @@ CatalogCache::IndexCache::LookupResult CatalogCache::IndexCache::_lookupIndexes( newIndexesMap[index.getName()] = index; } - return LookupResult( - OptionalGlobalIndexesInfo(GlobalIndexesCache(*indexVersion, std::move(newIndexesMap))), - std::move(newComparableVersion)); + return LookupResult(OptionalShardingIndexCatalogInfo(ShardingIndexesCatalogCache( + *indexVersion, std::move(newIndexesMap))), + std::move(newComparableVersion)); } catch (const DBException& ex) { if (ex.code() == ErrorCodes::NamespaceNotFound) { LOGV2_FOR_CATALOG_REFRESH(7038200, 0, "Collection has found to be unsharded after refresh", "namespace"_attr = nss); - return LookupResult(OptionalGlobalIndexesInfo(), std::move(newComparableVersion)); + return LookupResult(OptionalShardingIndexCatalogInfo(), + std::move(newComparableVersion)); } LOGV2_FOR_CATALOG_REFRESH(6686304, 0, diff --git a/src/mongo/s/catalog_cache.h b/src/mongo/s/catalog_cache.h index 2e59d10562d..f8766ad35d4 100644 --- a/src/mongo/s/catalog_cache.h +++ b/src/mongo/s/catalog_cache.h @@ -36,8 +36,8 @@ #include "mongo/s/catalog/type_index_catalog.h" #include "mongo/s/catalog_cache_loader.h" #include "mongo/s/chunk_manager.h" -#include "mongo/s/global_index_cache.h" #include "mongo/s/shard_version.h" +#include "mongo/s/sharding_index_catalog_cache.h" #include "mongo/s/type_collection_common_types_gen.h" #include "mongo/util/concurrency/thread_pool.h" #include "mongo/util/read_through_cache.h" @@ -54,10 +54,10 @@ using CachedDatabaseInfo = DatabaseTypeValueHandle; struct CollectionRoutingInfo { CollectionRoutingInfo(ChunkManager&& chunkManager, - boost::optional<GlobalIndexesCache>&& globalIndexes) - : cm(std::move(chunkManager)), gii(std::move(globalIndexes)) {} + boost::optional<ShardingIndexesCatalogCache>&& shardingIndexesCatalog) + : cm(std::move(chunkManager)), sii(std::move(shardingIndexesCatalog)) {} ChunkManager cm; - boost::optional<GlobalIndexesCache> gii; + boost::optional<ShardingIndexesCatalogCache> sii; ShardVersion getCollectionVersion() const; ShardVersion getShardVersion(const ShardId& shardId) const; @@ -377,7 +377,7 @@ private: void _updateRefreshesStats(bool isIncremental, bool add); }; - class IndexCache : public GlobalIndexesCacheBase { + class IndexCache : public ShardingIndexesCatalogRTCBase { public: IndexCache(ServiceContext* service, ThreadPoolInterface& threadPool); @@ -394,9 +394,8 @@ private: boost::optional<Timestamp> atClusterTime, bool allowLocks = false); - boost::optional<GlobalIndexesCache> _getCollectionIndexInfoAt(OperationContext* opCtx, - const NamespaceString& nss, - bool allowLocks = false); + boost::optional<ShardingIndexesCatalogCache> _getCollectionIndexInfoAt( + OperationContext* opCtx, const NamespaceString& nss, bool allowLocks = false); void _triggerPlacementVersionRefresh(OperationContext* opCtx, const NamespaceString& nss); diff --git a/src/mongo/s/catalog_cache_test_fixture.cpp b/src/mongo/s/catalog_cache_test_fixture.cpp index 75efd7355b8..1e3a23d1d41 100644 --- a/src/mongo/s/catalog_cache_test_fixture.cpp +++ b/src/mongo/s/catalog_cache_test_fixture.cpp @@ -261,7 +261,7 @@ void CatalogCacheTestFixture::expectCollectionAndIndexesAggregation( UUID uuid, const ShardKeyPattern& shardKeyPattern, boost::optional<Timestamp> indexVersion, - const std::vector<BSONObj>& globalIndexes) { + const std::vector<BSONObj>& indexes) { if (feature_flags::gGlobalIndexesShardingCatalog.isEnabledAndIgnoreFCV()) { onCommand([&](const executor::RemoteCommandRequest& request) { ASSERT_EQ(request.target, kConfigHostAndPort); @@ -271,7 +271,7 @@ void CatalogCacheTestFixture::expectCollectionAndIndexesAggregation( if (indexVersion) { collType.setIndexVersion({uuid, *indexVersion}); } - return makeCollectionAndIndexesAggregationResponse(collType, globalIndexes); + return makeCollectionAndIndexesAggregationResponse(collType, indexes); }); } } diff --git a/src/mongo/s/catalog_cache_test_fixture.h b/src/mongo/s/catalog_cache_test_fixture.h index 094eeb8a8db..efdd93686f8 100644 --- a/src/mongo/s/catalog_cache_test_fixture.h +++ b/src/mongo/s/catalog_cache_test_fixture.h @@ -144,7 +144,7 @@ protected: UUID uuid, const ShardKeyPattern& shardKeyPattern, boost::optional<Timestamp> indexVersion, - const std::vector<BSONObj>& globalIndexes); + const std::vector<BSONObj>& indexes); const HostAndPort kConfigHostAndPort{"DummyConfig", 1234}; }; diff --git a/src/mongo/s/cluster_commands_helpers.cpp b/src/mongo/s/cluster_commands_helpers.cpp index 2375122c485..1d0a69e39e1 100644 --- a/src/mongo/s/cluster_commands_helpers.cpp +++ b/src/mongo/s/cluster_commands_helpers.cpp @@ -724,7 +724,7 @@ StatusWith<Shard::QueryResponse> loadIndexesFromAuthoritativeShard(OperationCont uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); auto [indexShard, listIndexesCmd] = [&]() -> std::pair<std::shared_ptr<Shard>, BSONObj> { - const auto& [cm, gii] = cri; + const auto& [cm, sii] = cri; auto cmdNoVersion = applyReadWriteConcern( opCtx, true /* appendRC */, false /* appendWC */, BSON("listIndexes" << nss.coll())); if (cm.isSharded()) { diff --git a/src/mongo/s/collection_routing_info_targeter.cpp b/src/mongo/s/collection_routing_info_targeter.cpp index a0c4bfa6ecc..a99cfafc74a 100644 --- a/src/mongo/s/collection_routing_info_targeter.cpp +++ b/src/mongo/s/collection_routing_info_targeter.cpp @@ -164,11 +164,11 @@ bool isMetadataDifferent(const CollectionRoutingInfo& managerA, if (managerA.cm.getVersion() != managerB.cm.getVersion()) return true; - if (managerA.gii.is_initialized() != managerB.gii.is_initialized()) + if (managerA.sii.is_initialized() != managerB.sii.is_initialized()) return true; - return managerA.gii.is_initialized() && - managerA.gii->getCollectionIndexes() != managerB.gii->getCollectionIndexes(); + return managerA.sii.is_initialized() && + managerA.sii->getCollectionIndexes() != managerB.sii->getCollectionIndexes(); } return managerA.cm.dbVersion() != managerB.cm.dbVersion(); @@ -198,7 +198,7 @@ CollectionRoutingInfo CollectionRoutingInfoTargeter::_init(OperationContext* opC uassertStatusOK( Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfoWithRefresh(opCtx, _nss)); } - auto [cm, gii] = uassertStatusOK(getCollectionRoutingInfoForTxnCmd(opCtx, _nss)); + auto [cm, sii] = uassertStatusOK(getCollectionRoutingInfoForTxnCmd(opCtx, _nss)); // For a sharded time-series collection, only the underlying buckets collection is stored on the // config servers. If the user operation is on the time-series view namespace, we should check @@ -223,7 +223,7 @@ CollectionRoutingInfo CollectionRoutingInfoTargeter::_init(OperationContext* opC if (bucketsPlacementInfo.isSharded()) { _nss = bucketsNs; cm = std::move(bucketsPlacementInfo); - gii = std::move(bucketsIndexInfo); + sii = std::move(bucketsIndexInfo); _isRequestOnTimeseriesViewNamespace = true; } } else if (!cm.isSharded() && _isRequestOnTimeseriesViewNamespace) { @@ -235,9 +235,9 @@ CollectionRoutingInfo CollectionRoutingInfoTargeter::_init(OperationContext* opC uassertStatusOK( Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfoWithRefresh(opCtx, _nss)); } - auto [newCm, newGii] = uassertStatusOK(getCollectionRoutingInfoForTxnCmd(opCtx, _nss)); + auto [newCm, newSii] = uassertStatusOK(getCollectionRoutingInfoForTxnCmd(opCtx, _nss)); cm = std::move(newCm); - gii = std::move(newGii); + sii = std::move(newSii); _isRequestOnTimeseriesViewNamespace = false; } @@ -247,7 +247,7 @@ CollectionRoutingInfo CollectionRoutingInfoTargeter::_init(OperationContext* opC "Collection epoch has changed", cm.getVersion().epoch() == *_targetEpoch); } - return CollectionRoutingInfo(std::move(cm), std::move(gii)); + return CollectionRoutingInfo(std::move(cm), std::move(sii)); } const NamespaceString& CollectionRoutingInfoTargeter::getNS() const { diff --git a/src/mongo/s/collection_routing_info_targeter_test.cpp b/src/mongo/s/collection_routing_info_targeter_test.cpp index 91e111bb08f..4e394920de4 100644 --- a/src/mongo/s/collection_routing_info_targeter_test.cpp +++ b/src/mongo/s/collection_routing_info_targeter_test.cpp @@ -295,8 +295,8 @@ void CollectionRoutingInfoTargeterTest:: << "hashed")); auto cm = makeCustomChunkManager(shardKeyPattern, splitPoints); - auto criTargeter = CollectionRoutingInfoTargeter( - CollectionRoutingInfo{std::move(cm), boost::optional<GlobalIndexesCache>(boost::none)}); + auto criTargeter = CollectionRoutingInfoTargeter(CollectionRoutingInfo{ + std::move(cm), boost::optional<ShardingIndexesCatalogCache>(boost::none)}); ASSERT_EQ(criTargeter.getRoutingInfo().cm.numChunks(), 5); // Cause the global chunk manager to have some other configuration. diff --git a/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp b/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp index 73a481696de..8a3930b9b1e 100644 --- a/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp +++ b/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp @@ -100,7 +100,7 @@ public: result.append("version", cachedDbInfo->getVersion().toBSON()); } else { // Return the collection's information. - const auto [cm, gii] = + const auto [cm, sii] = uassertStatusOK(catalogCache->getCollectionRoutingInfo(opCtx, nss)); uassert(ErrorCodes::NamespaceNotSharded, str::stream() << "Collection " << nss.ns() << " is not sharded.", @@ -111,8 +111,8 @@ public: result.append("versionTimestamp", cm.getVersion().getTimestamp()); - if (gii) { - result.append("indexVersion", gii->getCollectionIndexes().indexVersion()); + if (sii) { + result.append("indexVersion", sii->getCollectionIndexes().indexVersion()); } if (cmdObj["fullMetadata"].trueValue()) { @@ -141,9 +141,9 @@ public: if (!exceedsSizeLimit) { result.append("chunks", chunksArrBuilder.arr()); - if (gii) { + if (sii) { BSONArrayBuilder indexesArrBuilder; - gii->forEachIndex([&](const auto& index) { + sii->forEachIndex([&](const auto& index) { BSONObjBuilder indexB(index.toBSON()); if (result.len() + indexesArrBuilder.len() + indexB.len() > BSONObjMaxUserSize) { diff --git a/src/mongo/s/comparable_index_version_test.cpp b/src/mongo/s/comparable_index_version_test.cpp index 4e9a4fc9268..2d7e7e7c94a 100644 --- a/src/mongo/s/comparable_index_version_test.cpp +++ b/src/mongo/s/comparable_index_version_test.cpp @@ -27,7 +27,7 @@ * it in the license file. */ -#include "mongo/s/global_index_cache.h" +#include "mongo/s/sharding_index_catalog_cache.h" #include "mongo/unittest/unittest.h" namespace mongo { diff --git a/src/mongo/s/global_index_cache.cpp b/src/mongo/s/sharding_index_catalog_cache.cpp index 10cae19ce84..df57b0b5f48 100644 --- a/src/mongo/s/global_index_cache.cpp +++ b/src/mongo/s/sharding_index_catalog_cache.cpp @@ -27,45 +27,44 @@ * it in the license file. */ -#include "mongo/s/global_index_cache.h" +#include "mongo/s/sharding_index_catalog_cache.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding namespace mongo { -bool GlobalIndexesCache::empty() const { +bool ShardingIndexesCatalogCache::empty() const { return _indexes.empty(); } -CollectionIndexes GlobalIndexesCache::getCollectionIndexes() const { +CollectionIndexes ShardingIndexesCatalogCache::getCollectionIndexes() const { return _collectionIndexes; } -size_t GlobalIndexesCache::numIndexes() const { +size_t ShardingIndexesCatalogCache::numIndexes() const { return _indexes.size(); } -bool GlobalIndexesCache::contains(const StringData& name) const { +bool ShardingIndexesCatalogCache::contains(const StringData& name) const { return _indexes.contains(name); } -void GlobalIndexesCache::add(const IndexCatalogType& index, - const CollectionIndexes& collectionIndexes) { +void ShardingIndexesCatalogCache::add(const IndexCatalogType& index, + const CollectionIndexes& collectionIndexes) { tassert(7019900, - str::stream() - << "Cannot add global index with different uuid than is in the GlobalIndexesCache.", + str::stream() << "Cannot add global index with different uuid than is in the " + "ShardingIndexesCatalogCache.", collectionIndexes.uuid() == _collectionIndexes.uuid()); _collectionIndexes = collectionIndexes; _indexes.emplace(index.getName(), index); } -void GlobalIndexesCache::remove(const StringData& name, - const CollectionIndexes& collectionIndexes) { - tassert( - 7019901, - str::stream() - << "Cannot remove global index with different uuid than is in the GlobalIndexesCache.", - collectionIndexes.uuid() == _collectionIndexes.uuid()); +void ShardingIndexesCatalogCache::remove(const StringData& name, + const CollectionIndexes& collectionIndexes) { + tassert(7019901, + str::stream() << "Cannot remove global index with different uuid than is in the " + "ShardingIndexesCatalogCache.", + collectionIndexes.uuid() == _collectionIndexes.uuid()); _collectionIndexes = collectionIndexes; _indexes.erase(name); } diff --git a/src/mongo/s/global_index_cache.h b/src/mongo/s/sharding_index_catalog_cache.h index f67560166f9..1214a057f47 100644 --- a/src/mongo/s/global_index_cache.h +++ b/src/mongo/s/sharding_index_catalog_cache.h @@ -38,9 +38,9 @@ namespace mongo { using IndexCatalogTypeMap = StringMap<IndexCatalogType>; -class GlobalIndexesCache { +class ShardingIndexesCatalogCache { public: - GlobalIndexesCache(CollectionIndexes collectionIndexes, IndexCatalogTypeMap&& indexes) + ShardingIndexesCatalogCache(CollectionIndexes collectionIndexes, IndexCatalogTypeMap&& indexes) : _collectionIndexes(std::move(collectionIndexes)), _indexes(std::move(indexes)) {} bool empty() const; @@ -66,8 +66,9 @@ public: template <typename Callable> void forEachGlobalIndex(Callable&& handler) const { for (auto it = _indexes.begin(); it != _indexes.end(); it++) { - auto options = it->second.getOptions(); - if (options.getBoolField(IndexOptionsType::kGlobalFieldName) && !handler(it->second)) { + auto options = IndexOptionsType::parse(IDLParserContext("forEachGlobalIndexCtx"), + it->second.getOptions()); + if (options.getGlobal() && !handler(it->second)) { return; } } @@ -167,19 +168,19 @@ private: * indexes in the cache. The cache does not allow for an empty value, so this intermediate structure * is needed. */ -struct OptionalGlobalIndexesInfo { +struct OptionalShardingIndexCatalogInfo { // No indexes constructor. - OptionalGlobalIndexesInfo() = default; + OptionalShardingIndexCatalogInfo() = default; // Constructor with global indexes - OptionalGlobalIndexesInfo(GlobalIndexesCache gii) : optGii(std::move(gii)) {} + OptionalShardingIndexCatalogInfo(ShardingIndexesCatalogCache sii) : optSii(std::move(sii)) {} // If nullptr, the collection has an index version of boost::none and no global indexes. // Otherwise, the index version is some valid timestamp (there still may be no global indexes). - boost::optional<GlobalIndexesCache> optGii; + boost::optional<ShardingIndexesCatalogCache> optSii; }; -using GlobalIndexesCacheBase = - ReadThroughCache<NamespaceString, OptionalGlobalIndexesInfo, ComparableIndexVersion>; +using ShardingIndexesCatalogRTCBase = + ReadThroughCache<NamespaceString, OptionalShardingIndexCatalogInfo, ComparableIndexVersion>; } // namespace mongo diff --git a/src/mongo/s/global_index_cache_test.cpp b/src/mongo/s/sharding_index_catalog_cache_test.cpp index 4a5a16f0ae0..2abfe0b9da9 100644 --- a/src/mongo/s/global_index_cache_test.cpp +++ b/src/mongo/s/sharding_index_catalog_cache_test.cpp @@ -30,7 +30,7 @@ #include "mongo/platform/basic.h" #include "mongo/logv2/log.h" -#include "mongo/s/global_index_cache.h" +#include "mongo/s/sharding_index_catalog_cache.h" #include "mongo/s/sharding_router_test_fixture.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding @@ -38,13 +38,13 @@ namespace mongo { namespace { -using ShardingGlobalIndexCacheTest = ShardingTestFixture; +using ShardinglIndexCatalogCacheTest = ShardingTestFixture; -TEST_F(ShardingGlobalIndexCacheTest, CheckGlobalIndexes) { +TEST_F(ShardinglIndexCatalogCacheTest, CheckGlobalIndexes) { const UUID collUUID = UUID::gen(); IndexCatalogTypeMap indexMap; IndexOptionsType options; - GlobalIndexesCache indexCache({collUUID, Timestamp(0, 0)}, std::move(indexMap)); + ShardingIndexesCatalogCache indexCache({collUUID, Timestamp(0, 0)}, std::move(indexMap)); IndexCatalogType index("x_1", BSON("x" << 1), options.toBSON(), Timestamp(1, 0), collUUID); options.setGlobal(true); IndexCatalogType globalIndex( |