diff options
Diffstat (limited to 'src/mongo/s/commands')
29 files changed, 100 insertions, 107 deletions
diff --git a/src/mongo/s/commands/cluster_analyze_cmd.cpp b/src/mongo/s/commands/cluster_analyze_cmd.cpp index 04dae01aadf..ea0ccdb84a7 100644 --- a/src/mongo/s/commands/cluster_analyze_cmd.cpp +++ b/src/mongo/s/commands/cluster_analyze_cmd.cpp @@ -78,13 +78,13 @@ public: const NamespaceString& nss = ns(); - auto routingInfo = uassertStatusOK( + auto cri = uassertStatusOK( Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); auto shardResponses = scatterGatherVersionedTargetByRoutingTable( opCtx, nss.db(), nss, - routingInfo, + cri, applyReadWriteConcern( opCtx, this, diff --git a/src/mongo/s/commands/cluster_analyze_shard_key_cmd.cpp b/src/mongo/s/commands/cluster_analyze_shard_key_cmd.cpp index 9cd6f2f6eb7..1d1a2568296 100644 --- a/src/mongo/s/commands/cluster_analyze_shard_key_cmd.cpp +++ b/src/mongo/s/commands/cluster_analyze_shard_key_cmd.cpp @@ -48,17 +48,18 @@ namespace { * Returns a new command object with shard version and/or database version appended to it based on * the given routing info. */ -BSONObj makeVersionedCmdObj(const ChunkManager& cm, +BSONObj makeVersionedCmdObj(const CollectionRoutingInfo& cri, const BSONObj& unversionedCmdObj, ShardId shardId) { - if (cm.isSharded()) { - auto placementVersion = cm.getVersion(shardId); + if (cri.cm.isSharded()) { return appendShardVersion( unversionedCmdObj, - ShardVersion(placementVersion, boost::optional<CollectionIndexes>(boost::none))); + ShardVersion(cri.cm.getVersion(shardId), + cri.gii ? boost::make_optional(cri.gii->getCollectionIndexes()) + : boost::none)); } auto versionedCmdObj = appendShardVersion(unversionedCmdObj, ShardVersion::UNSHARDED()); - return appendDbVersionIfPresent(versionedCmdObj, cm.dbVersion()); + return appendDbVersionIfPresent(versionedCmdObj, cri.cm.dbVersion()); } class AnalyzeShardKeyCmd : public TypedCommand<AnalyzeShardKeyCmd> { @@ -73,13 +74,13 @@ public: Response typedRun(OperationContext* opCtx) { const auto& nss = ns(); const auto& catalogCache = Grid::get(opCtx)->catalogCache(); - const auto cm = uassertStatusOK(catalogCache->getCollectionRoutingInfo(opCtx, nss)); + const auto cri = uassertStatusOK(catalogCache->getCollectionRoutingInfo(opCtx, nss)); std::set<ShardId> candidateShardIds; - if (cm.isSharded()) { - cm.getAllShardIds(&candidateShardIds); + if (cri.cm.isSharded()) { + cri.cm.getAllShardIds(&candidateShardIds); } else { - candidateShardIds.insert(cm.dbPrimary()); + candidateShardIds.insert(cri.cm.dbPrimary()); } const auto unversionedCmdObj = @@ -97,7 +98,7 @@ public: shardId != ShardId::kConfigServerId); // Build a versioned command for the selected shard. - auto versionedCmdObj = makeVersionedCmdObj(cm, unversionedCmdObj, shardId); + auto versionedCmdObj = makeVersionedCmdObj(cri, unversionedCmdObj, shardId); // Execute the command against the shard. auto shard = diff --git a/src/mongo/s/commands/cluster_clear_jumbo_flag_cmd.cpp b/src/mongo/s/commands/cluster_clear_jumbo_flag_cmd.cpp index bf3a2017da2..20d8645fac4 100644 --- a/src/mongo/s/commands/cluster_clear_jumbo_flag_cmd.cpp +++ b/src/mongo/s/commands/cluster_clear_jumbo_flag_cmd.cpp @@ -75,8 +75,8 @@ public: void run(OperationContext* opCtx, rpc::ReplyBuilderInterface* result) override { const auto cm = uassertStatusOK( - Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfoWithRefresh(opCtx, - ns())); + Grid::get(opCtx)->catalogCache()->getShardedCollectionPlacementInfoWithRefresh( + opCtx, ns())); uassert(ErrorCodes::InvalidOptions, "bounds can only have exactly 2 elements", diff --git a/src/mongo/s/commands/cluster_coll_stats_cmd.cpp b/src/mongo/s/commands/cluster_coll_stats_cmd.cpp index 416ae71d287..862517f3254 100644 --- a/src/mongo/s/commands/cluster_coll_stats_cmd.cpp +++ b/src/mongo/s/commands/cluster_coll_stats_cmd.cpp @@ -35,8 +35,8 @@ #include "mongo/db/timeseries/timeseries_commands_conversion_helper.h" #include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" -#include "mongo/s/chunk_manager_targeter.h" #include "mongo/s/cluster_commands_helpers.h" +#include "mongo/s/collection_routing_info_targeter.h" #include "mongo/s/grid.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand @@ -208,8 +208,9 @@ public: const NamespaceString nss(parseNs(dbName, cmdObj)); - const auto targeter = ChunkManagerTargeter(opCtx, nss); - const auto cm = targeter.getRoutingInfo(); + const auto targeter = CollectionRoutingInfoTargeter(opCtx, nss); + const auto cri = targeter.getRoutingInfo(); + const auto& cm = cri.cm; if (cm.isSharded()) { result.appendBool("sharded", true); } else { @@ -241,7 +242,7 @@ public: opCtx, nss.db(), targeter.getNS(), - cm, + cri, applyReadWriteConcern( opCtx, this, CommandHelpers::filterCommandRequestForPassthrough(cmdObjToSend)), ReadPreferenceSetting::get(opCtx), diff --git a/src/mongo/s/commands/cluster_collection_mod_cmd.cpp b/src/mongo/s/commands/cluster_collection_mod_cmd.cpp index 03afdbe6feb..6a2a66272a5 100644 --- a/src/mongo/s/commands/cluster_collection_mod_cmd.cpp +++ b/src/mongo/s/commands/cluster_collection_mod_cmd.cpp @@ -37,7 +37,6 @@ #include "mongo/db/coll_mod_reply_validation.h" #include "mongo/db/commands.h" #include "mongo/logv2/log.h" -#include "mongo/s/chunk_manager_targeter.h" #include "mongo/s/cluster_commands_helpers.h" #include "mongo/s/grid.h" #include "mongo/s/request_types/sharded_ddl_commands_gen.h" diff --git a/src/mongo/s/commands/cluster_convert_to_capped_cmd.cpp b/src/mongo/s/commands/cluster_convert_to_capped_cmd.cpp index a34450631fb..a7644419d8b 100644 --- a/src/mongo/s/commands/cluster_convert_to_capped_cmd.cpp +++ b/src/mongo/s/commands/cluster_convert_to_capped_cmd.cpp @@ -44,19 +44,19 @@ namespace { bool nonShardedCollectionCommandPassthrough(OperationContext* opCtx, const DatabaseName& dbName, const NamespaceString& nss, - const ChunkManager& cm, + const CollectionRoutingInfo& cri, const BSONObj& cmdObj, Shard::RetryPolicy retryPolicy, BSONObjBuilder* out) { const StringData cmdName(cmdObj.firstElementFieldName()); uassert(ErrorCodes::IllegalOperation, str::stream() << "Can't do command: " << cmdName << " on a sharded collection", - !cm.isSharded()); + !cri.cm.isSharded()); auto responses = scatterGatherVersionedTargetByRoutingTable(opCtx, dbName.toStringWithTenantId(), nss, - cm, + cri, cmdObj, ReadPreferenceSetting::get(opCtx), retryPolicy, @@ -108,11 +108,11 @@ public: const BSONObj& cmdObj, BSONObjBuilder& result) override { const NamespaceString nss(parseNs(dbName, cmdObj)); - const auto cm = + const auto cri = uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); uassert(ErrorCodes::IllegalOperation, "You can't convertToCapped a sharded collection", - !cm.isSharded()); + !cri.cm.isSharded()); // convertToCapped creates a temp collection and renames it at the end. It will require // special handling for create collection. @@ -120,7 +120,7 @@ public: opCtx, dbName, nss, - cm, + cri, applyReadWriteConcern( opCtx, this, CommandHelpers::filterCommandRequestForPassthrough(cmdObj)), Shard::RetryPolicy::kIdempotent, diff --git a/src/mongo/s/commands/cluster_count_cmd.h b/src/mongo/s/commands/cluster_count_cmd.h index 622fc297bb3..565740d14aa 100644 --- a/src/mongo/s/commands/cluster_count_cmd.h +++ b/src/mongo/s/commands/cluster_count_cmd.h @@ -129,14 +129,14 @@ public: } } countRequest.setSkip(boost::none); - const auto routingInfo = uassertStatusOK( + const auto cri = uassertStatusOK( Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); const auto collation = countRequest.getCollation().get_value_or(BSONObj()); shardResponses = scatterGatherVersionedTargetByRoutingTable( opCtx, nss.db(), nss, - routingInfo, + cri, applyReadWriteConcern( opCtx, this, @@ -241,13 +241,13 @@ public: std::vector<AsyncRequestsSender::Response> shardResponses; try { - const auto routingInfo = uassertStatusOK( + const auto cri = uassertStatusOK( Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); shardResponses = scatterGatherVersionedTargetByRoutingTable(opCtx, nss.db(), nss, - routingInfo, + cri, explainCmd, ReadPreferenceSetting::get(opCtx), Shard::RetryPolicy::kIdempotent, diff --git a/src/mongo/s/commands/cluster_create_indexes_cmd.cpp b/src/mongo/s/commands/cluster_create_indexes_cmd.cpp index 7699a802d01..29e71ac203e 100644 --- a/src/mongo/s/commands/cluster_create_indexes_cmd.cpp +++ b/src/mongo/s/commands/cluster_create_indexes_cmd.cpp @@ -36,9 +36,9 @@ #include "mongo/db/timeseries/timeseries_commands_conversion_helper.h" #include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" -#include "mongo/s/chunk_manager_targeter.h" #include "mongo/s/cluster_commands_helpers.h" #include "mongo/s/cluster_ddl.h" +#include "mongo/s/collection_routing_info_targeter.h" #include "mongo/s/grid.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand @@ -104,7 +104,7 @@ public: // TODO SERVER-67798 Change cluster::createDatabase to use DatabaseName cluster::createDatabase(opCtx, dbName.toStringWithTenantId()); - auto targeter = ChunkManagerTargeter(opCtx, nss); + auto targeter = CollectionRoutingInfoTargeter(opCtx, nss); auto routingInfo = targeter.getRoutingInfo(); auto cmdToBeSent = cmdObj; if (targeter.timeseriesNamespaceNeedsRewrite(nss)) { diff --git a/src/mongo/s/commands/cluster_data_size_cmd.cpp b/src/mongo/s/commands/cluster_data_size_cmd.cpp index 32e5ff6140c..dda5ed02fcf 100644 --- a/src/mongo/s/commands/cluster_data_size_cmd.cpp +++ b/src/mongo/s/commands/cluster_data_size_cmd.cpp @@ -74,14 +74,14 @@ public: const auto& cmd = request(); const auto& nss = ns(); - auto routingInfo = uassertStatusOK( + auto cri = uassertStatusOK( Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); auto shardResults = scatterGatherVersionedTargetByRoutingTable( opCtx, nss.db(), nss, - routingInfo, + cri, applyReadWriteConcern( opCtx, this, diff --git a/src/mongo/s/commands/cluster_distinct_cmd.cpp b/src/mongo/s/commands/cluster_distinct_cmd.cpp index 7715373f0d4..5df1cd7989f 100644 --- a/src/mongo/s/commands/cluster_distinct_cmd.cpp +++ b/src/mongo/s/commands/cluster_distinct_cmd.cpp @@ -135,13 +135,13 @@ public: std::vector<AsyncRequestsSender::Response> shardResponses; try { - const auto routingInfo = uassertStatusOK( + const auto cri = uassertStatusOK( Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); shardResponses = scatterGatherVersionedTargetByRoutingTable(opCtx, nss.db(), nss, - routingInfo, + cri, explainCmd, ReadPreferenceSetting::get(opCtx), Shard::RetryPolicy::kIdempotent, @@ -211,22 +211,23 @@ public: CollatorFactoryInterface::get(opCtx->getServiceContext())->makeFromBSON(collation)); } - auto swCM = getCollectionRoutingInfoForTxnCmd(opCtx, nss); - if (swCM == ErrorCodes::NamespaceNotFound) { + auto swCri = getCollectionRoutingInfoForTxnCmd(opCtx, nss); + if (swCri == ErrorCodes::NamespaceNotFound) { // If the database doesn't exist, we successfully return an empty result set without // creating a cursor. result.appendArray("values", BSONObj()); return true; } - const auto cm = uassertStatusOK(std::move(swCM)); + const auto cri = uassertStatusOK(std::move(swCri)); + const auto& cm = cri.cm; std::vector<AsyncRequestsSender::Response> shardResponses; try { shardResponses = scatterGatherVersionedTargetByRoutingTable( opCtx, nss.db(), nss, - cm, + cri, applyReadWriteConcern( opCtx, this, CommandHelpers::filterCommandRequestForPassthrough(cmdObj)), ReadPreferenceSetting::get(opCtx), diff --git a/src/mongo/s/commands/cluster_filemd5_cmd.cpp b/src/mongo/s/commands/cluster_filemd5_cmd.cpp index 600f41ba3bd..d4afd9021d7 100644 --- a/src/mongo/s/commands/cluster_filemd5_cmd.cpp +++ b/src/mongo/s/commands/cluster_filemd5_cmd.cpp @@ -94,7 +94,7 @@ public: BSONObjBuilder& result) override { const NamespaceString nss(parseNs(dbName, cmdObj)); - const auto cm = + const auto cri = uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); const auto callShardFn = [&](const BSONObj& cmdObj, const BSONObj& routingQuery) { @@ -102,7 +102,7 @@ public: scatterGatherVersionedTargetByRoutingTable(opCtx, nss.db(), nss, - cm, + cri, cmdObj, ReadPreferenceSetting::get(opCtx), Shard::RetryPolicy::kIdempotent, @@ -121,6 +121,7 @@ public: // If the collection is not sharded, or is sharded only on the 'files_id' field, we only // need to target a single shard, because the files' chunks can only be contained in a // single sharded chunk + const auto& cm = cri.cm; if (!cm.isSharded() || SimpleBSONObjComparator::kInstance.evaluate(cm.getShardKeyPattern().toBSON() == BSON("files_id" << 1))) { diff --git a/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp b/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp index 0cb32b8bcff..54252bce4d7 100644 --- a/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp +++ b/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp @@ -404,8 +404,9 @@ public: }(); const NamespaceString nss(CommandHelpers::parseNsCollectionRequired(dbName, cmdObj)); - const auto cm = + const auto cri = uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); + const auto& cm = cri.cm; std::shared_ptr<Shard> shard; if (cm.isSharded()) { @@ -432,16 +433,14 @@ public: BSONObjBuilder bob; if (cm.isSharded()) { - ChunkVersion placementVersion = cm.getVersion(shard->getId()); - _runCommand( - opCtx, - shard->getId(), - ShardVersion(placementVersion, boost::optional<CollectionIndexes>(boost::none)), - boost::none, - nss, - applyReadWriteConcern(opCtx, false, false, explainCmd), - true /* isExplain */, - &bob); + _runCommand(opCtx, + shard->getId(), + cri.getShardVersion(shard->getId()), + boost::none, + nss, + applyReadWriteConcern(opCtx, false, false, explainCmd), + true /* isExplain */, + &bob); } else { _runCommand(opCtx, shard->getId(), @@ -499,7 +498,8 @@ public: // Append mongoS' runtime constants to the command object before forwarding it to the shard. auto cmdObjForShard = appendLegacyRuntimeConstantsToCommandObject(opCtx, cmdObj); - const auto cm = uassertStatusOK(getCollectionRoutingInfoForTxnCmd(opCtx, nss)); + const auto cri = uassertStatusOK(getCollectionRoutingInfoForTxnCmd(opCtx, nss)); + const auto& cm = cri.cm; if (cm.isSharded()) { const BSONObj query = cmdObjForShard.getObjectField("query"); @@ -522,16 +522,14 @@ public: // key. This means that we always assume that a findAndModify request using _id is // targetable to a single shard. auto chunk = cm.findIntersectingChunk(shardKey, collation, true); - ChunkVersion placementVersion = cm.getVersion(chunk.getShardId()); - _runCommand( - opCtx, - chunk.getShardId(), - ShardVersion(placementVersion, boost::optional<CollectionIndexes>(boost::none)), - boost::none, - nss, - applyReadWriteConcern(opCtx, this, cmdObjForShard), - false /* isExplain */, - &result); + _runCommand(opCtx, + chunk.getShardId(), + cri.getShardVersion(chunk.getShardId()), + boost::none, + nss, + applyReadWriteConcern(opCtx, this, cmdObjForShard), + false /* isExplain */, + &result); } } else { _runCommand(opCtx, diff --git a/src/mongo/s/commands/cluster_find_cmd.h b/src/mongo/s/commands/cluster_find_cmd.h index b533b9abe40..360b2e6ce1b 100644 --- a/src/mongo/s/commands/cluster_find_cmd.h +++ b/src/mongo/s/commands/cluster_find_cmd.h @@ -148,14 +148,14 @@ public: // We will time how long it takes to run the commands on the shards. Timer timer; - const auto routingInfo = + const auto cri = uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo( opCtx, *findCommand->getNamespaceOrUUID().nss())); shardResponses = scatterGatherVersionedTargetByRoutingTable( opCtx, findCommand->getNamespaceOrUUID().nss()->db(), *findCommand->getNamespaceOrUUID().nss(), - routingInfo, + cri, explainCmd, ReadPreferenceSetting::get(opCtx), Shard::RetryPolicy::kIdempotent, 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 8062c712298..99bc49b43b3 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,8 @@ public: result.append("version", cachedDbInfo->getVersion().toBSON()); } else { // Return the collection's information. - const auto cm = uassertStatusOK(catalogCache->getCollectionRoutingInfo(opCtx, nss)); + const auto [cm, gii] = + uassertStatusOK(catalogCache->getCollectionRoutingInfo(opCtx, nss)); uassert(ErrorCodes::NamespaceNotSharded, str::stream() << "Collection " << nss.ns() << " is not sharded.", cm.isSharded()); diff --git a/src/mongo/s/commands/cluster_index_filter_cmd.cpp b/src/mongo/s/commands/cluster_index_filter_cmd.cpp index 976508dbd4c..d3d6fe68efc 100644 --- a/src/mongo/s/commands/cluster_index_filter_cmd.cpp +++ b/src/mongo/s/commands/cluster_index_filter_cmd.cpp @@ -89,13 +89,13 @@ public: BSONObjBuilder& result) override { const NamespaceString nss(parseNs(dbName, cmdObj)); const BSONObj query; - const auto routingInfo = + const auto cri = uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); auto shardResponses = scatterGatherVersionedTargetByRoutingTable( opCtx, nss.db(), nss, - routingInfo, + cri, applyReadWriteConcern( opCtx, this, CommandHelpers::filterCommandRequestForPassthrough(cmdObj)), ReadPreferenceSetting::get(opCtx), diff --git a/src/mongo/s/commands/cluster_list_indexes_cmd.cpp b/src/mongo/s/commands/cluster_list_indexes_cmd.cpp index 44cbdde7854..214d8f7b614 100644 --- a/src/mongo/s/commands/cluster_list_indexes_cmd.cpp +++ b/src/mongo/s/commands/cluster_list_indexes_cmd.cpp @@ -35,8 +35,8 @@ #include "mongo/db/list_indexes_gen.h" #include "mongo/db/timeseries/timeseries_commands_conversion_helper.h" #include "mongo/rpc/get_status_from_command_result.h" -#include "mongo/s/chunk_manager_targeter.h" #include "mongo/s/cluster_commands_helpers.h" +#include "mongo/s/collection_routing_info_targeter.h" #include "mongo/s/query/store_possible_cursor.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand @@ -47,13 +47,13 @@ namespace { ListIndexesReply cursorCommandPassthroughShardWithMinKeyChunk(OperationContext* opCtx, const NamespaceString& nss, - const ChunkManager& cm, + const CollectionRoutingInfo& cri, const BSONObj& cmdObj, const PrivilegeVector& privileges) { auto response = executeCommandAgainstShardWithMinKeyChunk( opCtx, nss, - cm, + cri, CommandHelpers::filterCommandRequestForPassthrough(cmdObj), ReadPreferenceSetting::get(opCtx), Shard::RetryPolicy::kIdempotent); @@ -118,8 +118,8 @@ public: // The command's IDL definition permits namespace or UUID, but mongos requires a // namespace. - auto targeter = ChunkManagerTargeter(opCtx, ns()); - auto cm = targeter.getRoutingInfo(); + auto targeter = CollectionRoutingInfoTargeter(opCtx, ns()); + auto cri = targeter.getRoutingInfo(); auto cmdToBeSent = request().toBSON({}); if (targeter.timeseriesNamespaceNeedsRewrite(ns())) { cmdToBeSent = @@ -132,7 +132,7 @@ public: return cursorCommandPassthroughShardWithMinKeyChunk( opCtx, targeter.getNS(), - cm, + cri, applyReadWriteConcern(opCtx, this, cmdToBeSent), {Privilege(ResourcePattern::forExactNamespace(ns()), ActionType::listIndexes)}); } diff --git a/src/mongo/s/commands/cluster_map_reduce_agg.cpp b/src/mongo/s/commands/cluster_map_reduce_agg.cpp index 0e26dd1b5a5..6ea0461e8d9 100644 --- a/src/mongo/s/commands/cluster_map_reduce_agg.cpp +++ b/src/mongo/s/commands/cluster_map_reduce_agg.cpp @@ -166,7 +166,7 @@ bool runAggregationMapReduce(OperationContext* opCtx, involvedNamespaces.insert(resolvedOutNss); } - auto cm = uassertStatusOK( + auto [cm, _] = uassertStatusOK( sharded_agg_helpers::getExecutionNsRoutingInfo(opCtx, parsedMr.getNamespace())); auto expCtx = makeExpressionContext(opCtx, parsedMr, cm, verbosity); diff --git a/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp b/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp index b318b2e2bd0..df268cd3901 100644 --- a/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp +++ b/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp @@ -133,7 +133,7 @@ public: } auto const cm = - Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfo(opCtx, nss); + Grid::get(opCtx)->catalogCache()->getShardedCollectionPlacementInfo(opCtx, nss); if (!cm.getShardKeyPattern().isShardKey(minKey) || !cm.getShardKeyPattern().isShardKey(maxKey)) { diff --git a/src/mongo/s/commands/cluster_move_chunk_cmd.cpp b/src/mongo/s/commands/cluster_move_chunk_cmd.cpp index 8c56bfea1f9..e7f1957011a 100644 --- a/src/mongo/s/commands/cluster_move_chunk_cmd.cpp +++ b/src/mongo/s/commands/cluster_move_chunk_cmd.cpp @@ -104,8 +104,8 @@ public: Timer t; const auto chunkManager = uassertStatusOK( - Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfoWithRefresh(opCtx, - ns())); + Grid::get(opCtx)->catalogCache()->getShardedCollectionPlacementInfoWithRefresh( + opCtx, ns())); uassert(ErrorCodes::InvalidOptions, "bounds can only have exactly 2 elements", diff --git a/src/mongo/s/commands/cluster_plan_cache_clear_cmd.cpp b/src/mongo/s/commands/cluster_plan_cache_clear_cmd.cpp index 338014024c4..a4ea58823a7 100644 --- a/src/mongo/s/commands/cluster_plan_cache_clear_cmd.cpp +++ b/src/mongo/s/commands/cluster_plan_cache_clear_cmd.cpp @@ -93,13 +93,13 @@ bool ClusterPlanCacheClearCmd::run(OperationContext* opCtx, BSONObjBuilder& result) { const NamespaceString nss(CommandHelpers::parseNsCollectionRequired(dbName, cmdObj)); const BSONObj query; - const auto routingInfo = + const auto cri = uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); auto shardResponses = scatterGatherVersionedTargetByRoutingTable( opCtx, nss.db(), nss, - routingInfo, + cri, applyReadWriteConcern( opCtx, this, CommandHelpers::filterCommandRequestForPassthrough(cmdObj)), ReadPreferenceSetting::get(opCtx), diff --git a/src/mongo/s/commands/cluster_query_without_shard_key_cmd.cpp b/src/mongo/s/commands/cluster_query_without_shard_key_cmd.cpp index d2ecf14a582..ff7cbdeb260 100644 --- a/src/mongo/s/commands/cluster_query_without_shard_key_cmd.cpp +++ b/src/mongo/s/commands/cluster_query_without_shard_key_cmd.cpp @@ -109,7 +109,7 @@ public: // Get all shard ids for shards that have chunks in the desired namespace. const NamespaceString nss( CommandHelpers::parseNsCollectionRequired(ns().dbName(), request().getWriteCmd())); - const auto cm = uassertStatusOK(getCollectionRoutingInfoForTxnCmd(opCtx, nss)); + const auto cri = uassertStatusOK(getCollectionRoutingInfoForTxnCmd(opCtx, nss)); auto parsedInfoFromRequest = [&] { const auto commandName = request().getWriteCmd().firstElementFieldNameStringData(); BSONObjBuilder bob(request().getWriteCmd()); @@ -145,18 +145,13 @@ public: }(); auto allShardsContainingChunksForNs = - getShardsToTarget(opCtx, cm, nss, parsedInfoFromRequest); + getShardsToTarget(opCtx, cri.cm, nss, parsedInfoFromRequest); auto cmdObj = createAggregateCmdObj(opCtx, parsedInfoFromRequest, nss); std::vector<AsyncRequestsSender::Request> requests; for (const auto& shardId : allShardsContainingChunksForNs) { - ChunkVersion placementVersion = cm.getVersion(shardId); - requests.emplace_back( - shardId, - appendShardVersion( - cmdObj, - ShardVersion(placementVersion, - boost::optional<CollectionIndexes>(boost::none)))); + requests.emplace_back(shardId, + appendShardVersion(cmdObj, cri.getShardVersion(shardId))); } MultiStatementTransactionRequestsSender ars( diff --git a/src/mongo/s/commands/cluster_rename_collection_cmd.cpp b/src/mongo/s/commands/cluster_rename_collection_cmd.cpp index 8920eb793be..e30db4ef030 100644 --- a/src/mongo/s/commands/cluster_rename_collection_cmd.cpp +++ b/src/mongo/s/commands/cluster_rename_collection_cmd.cpp @@ -109,7 +109,6 @@ public: !request().getCollectionUUID()); } const auto dbInfo = uassertStatusOK(swDbInfo); - auto cri = uassertStatusOK(catalogCache->getCollectionRoutingInfo(opCtx, fromNss)); auto shard = uassertStatusOK( Grid::get(opCtx)->shardRegistry()->getShard(opCtx, dbInfo->getPrimary())); diff --git a/src/mongo/s/commands/cluster_set_index_commit_quorum_cmd.cpp b/src/mongo/s/commands/cluster_set_index_commit_quorum_cmd.cpp index 62be2f3595a..d82f46b45ef 100644 --- a/src/mongo/s/commands/cluster_set_index_commit_quorum_cmd.cpp +++ b/src/mongo/s/commands/cluster_set_index_commit_quorum_cmd.cpp @@ -108,13 +108,13 @@ public: "namespace"_attr = nss, "command"_attr = redact(cmdObj)); - auto routingInfo = + auto cri = uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); auto shardResponses = scatterGatherVersionedTargetByRoutingTable( opCtx, nss.db(), nss, - routingInfo, + cri, applyReadWriteConcern( opCtx, this, CommandHelpers::filterCommandRequestForPassthrough(cmdObj)), ReadPreferenceSetting::get(opCtx), diff --git a/src/mongo/s/commands/cluster_split_cmd.cpp b/src/mongo/s/commands/cluster_split_cmd.cpp index 61f1a8ff519..6fb08d165f8 100644 --- a/src/mongo/s/commands/cluster_split_cmd.cpp +++ b/src/mongo/s/commands/cluster_split_cmd.cpp @@ -136,8 +136,8 @@ public: const NamespaceString nss(parseNs({boost::none, dbname}, cmdObj)); const auto cm = uassertStatusOK( - Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfoWithRefresh(opCtx, - nss)); + Grid::get(opCtx)->catalogCache()->getShardedCollectionPlacementInfoWithRefresh(opCtx, + nss)); const BSONField<BSONObj> findField("find", BSONObj()); const BSONField<BSONArray> boundsField("bounds", BSONArray()); diff --git a/src/mongo/s/commands/cluster_split_vector_cmd.cpp b/src/mongo/s/commands/cluster_split_vector_cmd.cpp index 7bd4c4eb900..5f8f589396d 100644 --- a/src/mongo/s/commands/cluster_split_vector_cmd.cpp +++ b/src/mongo/s/commands/cluster_split_vector_cmd.cpp @@ -78,8 +78,8 @@ public: "Performing splitVector across dbs isn't supported via mongos", nss.dbName() == dbName); - const auto cm = - uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); + const auto cm = uassertStatusOK( + Grid::get(opCtx)->catalogCache()->getCollectionPlacementInfo(opCtx, nss)); uassert(ErrorCodes::IllegalOperation, str::stream() << "can't do command: " << getName() << " on sharded collection", !cm.isSharded()); diff --git a/src/mongo/s/commands/cluster_validate_cmd.cpp b/src/mongo/s/commands/cluster_validate_cmd.cpp index 237895fa301..ceea29b8e89 100644 --- a/src/mongo/s/commands/cluster_validate_cmd.cpp +++ b/src/mongo/s/commands/cluster_validate_cmd.cpp @@ -80,13 +80,13 @@ public: BSONObjBuilder& output) override { const NamespaceString nss(parseNs(dbName, cmdObj)); - const auto routingInfo = + const auto cri = uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); auto results = scatterGatherVersionedTargetByRoutingTable( opCtx, nss.db(), nss, - routingInfo, + cri, applyReadWriteConcern( opCtx, this, CommandHelpers::filterCommandRequestForPassthrough(cmdObj)), ReadPreferenceSetting::get(opCtx), diff --git a/src/mongo/s/commands/cluster_write_cmd.cpp b/src/mongo/s/commands/cluster_write_cmd.cpp index 45dcd81274a..98c4daef9a6 100644 --- a/src/mongo/s/commands/cluster_write_cmd.cpp +++ b/src/mongo/s/commands/cluster_write_cmd.cpp @@ -42,11 +42,11 @@ #include "mongo/executor/task_executor_pool.h" #include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" -#include "mongo/s/chunk_manager_targeter.h" #include "mongo/s/client/num_hosts_targeted_metrics.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/cluster_commands_helpers.h" #include "mongo/s/cluster_write.h" +#include "mongo/s/collection_routing_info_targeter.h" #include "mongo/s/commands/cluster_explain.h" #include "mongo/s/commands/document_shard_key_update_util.h" #include "mongo/s/grid.h" @@ -460,7 +460,7 @@ void ClusterWriteCmd::_commandOpWrite(OperationContext* opCtx, auto endpoints = [&] { // Note that this implementation will not handle targeting retries and does not // completely emulate write behavior - ChunkManagerTargeter targeter(opCtx, nss); + CollectionRoutingInfoTargeter targeter(opCtx, nss); if (targetingBatchItem.getOpType() == BatchedCommandRequest::BatchType_Insert) { return std::vector{targeter.targetInsert(opCtx, targetingBatchItem.getDocument())}; diff --git a/src/mongo/s/commands/cluster_write_without_shard_key_cmd.cpp b/src/mongo/s/commands/cluster_write_without_shard_key_cmd.cpp index 7d62962846c..8febed42c7d 100644 --- a/src/mongo/s/commands/cluster_write_without_shard_key_cmd.cpp +++ b/src/mongo/s/commands/cluster_write_without_shard_key_cmd.cpp @@ -113,15 +113,12 @@ public: const BSONObj cmdObj = _createCmdObj(writeCmd, commandName, targetDocId, nss); - const auto cm = uassertStatusOK(getCollectionRoutingInfoForTxnCmd(opCtx, nss)); + const auto cri = uassertStatusOK(getCollectionRoutingInfoForTxnCmd(opCtx, nss)); uassert(ErrorCodes::InvalidOptions, "_clusterWriteWithoutShardKey can only be run against sharded collections.", - cm.isSharded()); + cri.cm.isSharded()); - ChunkVersion placementVersion = cm.getVersion(shardId); - auto versionedCmdObj = appendShardVersion( - cmdObj, - ShardVersion(placementVersion, boost::optional<CollectionIndexes>(boost::none))); + auto versionedCmdObj = appendShardVersion(cmdObj, cri.getShardVersion(shardId)); AsyncRequestsSender::Request arsRequest(shardId, versionedCmdObj); std::vector<AsyncRequestsSender::Request> arsRequestVector({arsRequest}); diff --git a/src/mongo/s/commands/strategy.cpp b/src/mongo/s/commands/strategy.cpp index 7affe1bcefa..c50ac6ff18b 100644 --- a/src/mongo/s/commands/strategy.cpp +++ b/src/mongo/s/commands/strategy.cpp @@ -1000,7 +1000,7 @@ void ParseAndRunCommand::RunAndRetry::_checkRetryForTransaction(Status& status) if (!txnRouter.canContinueOnStaleShardOrDbError(_parc->_commandName, status)) { if (status.code() == ErrorCodes::ShardInvalidatedForTargeting) { auto catalogCache = Grid::get(opCtx)->catalogCache(); - (void)catalogCache->getCollectionRoutingInfoWithRefresh( + (void)catalogCache->getCollectionPlacementInfoWithRefresh( opCtx, status.extraInfo<ShardInvalidatedForTargetingInfo>()->getNss()); } |