diff options
Diffstat (limited to 'src/mongo/s')
-rw-r--r-- | src/mongo/s/cluster_commands_helpers.cpp | 60 | ||||
-rw-r--r-- | src/mongo/s/cluster_commands_helpers.h | 26 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_analyze_cmd.cpp | 6 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_coll_stats_cmd.cpp | 6 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_convert_to_capped_cmd.cpp | 6 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_count_cmd.h | 8 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_create_indexes_cmd.cpp | 6 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_data_size_cmd.cpp | 6 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_distinct_cmd.cpp | 6 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_filemd5_cmd.cpp | 4 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_find_cmd.h | 4 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_index_filter_cmd.cpp | 4 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_plan_cache_clear_cmd.cpp | 4 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_set_index_commit_quorum_cmd.cpp | 6 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_validate_cmd.cpp | 6 |
15 files changed, 124 insertions, 34 deletions
diff --git a/src/mongo/s/cluster_commands_helpers.cpp b/src/mongo/s/cluster_commands_helpers.cpp index 345c4eae3f7..1619df5129f 100644 --- a/src/mongo/s/cluster_commands_helpers.cpp +++ b/src/mongo/s/cluster_commands_helpers.cpp @@ -132,7 +132,7 @@ namespace { * sample id for it. */ std::vector<AsyncRequestsSender::Request> buildVersionedRequestsForTargetedShards( - OperationContext* opCtx, + boost::intrusive_ptr<ExpressionContext> expCtx, const NamespaceString& nss, const CollectionRoutingInfo& cri, const std::set<ShardId>& shardsToSkip, @@ -140,6 +140,7 @@ std::vector<AsyncRequestsSender::Request> buildVersionedRequestsForTargetedShard const BSONObj& query, const BSONObj& collation, bool eligibleForSampling = false) { + auto opCtx = expCtx->opCtx; const auto& cm = cri.cm; @@ -180,7 +181,6 @@ std::vector<AsyncRequestsSender::Request> buildVersionedRequestsForTargetedShard CollatorFactoryInterface::get(opCtx->getServiceContext())->makeFromBSON(collation)); } - auto expCtx = make_intrusive<ExpressionContext>(opCtx, std::move(collator), nss); getShardIdsForQuery(expCtx, query, collation, cm, &shardIds, nullptr /* info */); const auto targetedSampleId = eligibleForSampling @@ -422,11 +422,37 @@ std::vector<AsyncRequestsSender::Response> scatterGatherVersionedTargetByRouting Shard::RetryPolicy retryPolicy, const BSONObj& query, const BSONObj& collation, + const boost::optional<BSONObj>& letParameters, + const boost::optional<LegacyRuntimeConstants>& runtimeConstants, bool eligibleForSampling) { - const auto requests = buildVersionedRequestsForTargetedShards( - opCtx, nss, cri, {} /* shardsToSkip */, cmdObj, query, collation, eligibleForSampling); + auto expCtx = makeExpressionContextWithDefaultsForTargeter( + opCtx, nss, collation, boost::none /*explainVerbosity*/, letParameters, runtimeConstants); + return scatterGatherVersionedTargetByRoutingTable(expCtx, + dbName, + nss, + cri, + cmdObj, + readPref, + retryPolicy, + query, + collation, + eligibleForSampling); +} - return gatherResponses(opCtx, dbName, readPref, retryPolicy, requests); +[[nodiscard]] std::vector<AsyncRequestsSender::Response> scatterGatherVersionedTargetByRoutingTable( + boost::intrusive_ptr<ExpressionContext> expCtx, + StringData dbName, + const NamespaceString& nss, + const CollectionRoutingInfo& cri, + const BSONObj& cmdObj, + const ReadPreferenceSetting& readPref, + Shard::RetryPolicy retryPolicy, + const BSONObj& query, + const BSONObj& collation, + bool eligibleForSampling) { + const auto requests = buildVersionedRequestsForTargetedShards( + expCtx, nss, cri, {} /* shardsToSkip */, cmdObj, query, collation, eligibleForSampling); + return gatherResponses(expCtx->opCtx, dbName, readPref, retryPolicy, requests); } std::vector<AsyncRequestsSender::Response> @@ -440,9 +466,13 @@ scatterGatherVersionedTargetByRoutingTableNoThrowOnStaleShardVersionErrors( const ReadPreferenceSetting& readPref, Shard::RetryPolicy retryPolicy, const BSONObj& query, - const BSONObj& collation) { + const BSONObj& collation, + const boost::optional<BSONObj>& letParameters, + const boost::optional<LegacyRuntimeConstants>& runtimeConstants) { + auto expCtx = makeExpressionContextWithDefaultsForTargeter( + opCtx, nss, collation, boost::none /*explainVerbosity*/, letParameters, runtimeConstants); const auto requests = buildVersionedRequestsForTargetedShards( - opCtx, nss, cri, shardsToSkip, cmdObj, query, collation); + expCtx, nss, cri, shardsToSkip, cmdObj, query, collation); return gatherResponsesNoThrowOnStaleShardVersionErrors( opCtx, dbName, readPref, retryPolicy, requests); @@ -477,6 +507,12 @@ AsyncRequestsSender::Response executeCommandAgainstShardWithMinKeyChunk( const BSONObj& cmdObj, const ReadPreferenceSetting& readPref, Shard::RetryPolicy retryPolicy) { + auto expCtx = makeExpressionContextWithDefaultsForTargeter(opCtx, + nss, + BSONObj() /*collation*/, + boost::none /*explainVerbosity*/, + boost::none /*letParameters*/, + boost::none /*runtimeConstants*/); const auto query = cri.cm.isSharded() ? cri.cm.getShardKeyPattern().getKeyPattern().globalMin() : BSONObj(); @@ -487,7 +523,7 @@ AsyncRequestsSender::Response executeCommandAgainstShardWithMinKeyChunk( readPref, retryPolicy, buildVersionedRequestsForTargetedShards( - opCtx, nss, cri, {} /* shardsToSkip */, cmdObj, query, BSONObj() /* collation */)); + expCtx, nss, cri, {} /* shardsToSkip */, cmdObj, query, BSONObj() /* collation */)); return std::move(responses.front()); } @@ -670,10 +706,14 @@ std::vector<std::pair<ShardId, BSONObj>> getVersionedRequestsForTargetedShards( const CollectionRoutingInfo& cri, const BSONObj& cmdObj, const BSONObj& query, - const BSONObj& collation) { + const BSONObj& collation, + const boost::optional<BSONObj>& letParameters, + const boost::optional<LegacyRuntimeConstants>& runtimeConstants) { + auto expCtx = makeExpressionContextWithDefaultsForTargeter( + opCtx, nss, collation, boost::none /*explainVerbosity*/, letParameters, runtimeConstants); std::vector<std::pair<ShardId, BSONObj>> requests; auto ars_requests = buildVersionedRequestsForTargetedShards( - opCtx, nss, cri, {} /* shardsToSkip */, cmdObj, query, collation); + expCtx, nss, cri, {} /* shardsToSkip */, cmdObj, query, collation); std::transform(std::make_move_iterator(ars_requests.begin()), std::make_move_iterator(ars_requests.end()), std::back_inserter(requests), diff --git a/src/mongo/s/cluster_commands_helpers.h b/src/mongo/s/cluster_commands_helpers.h index 549e91b529c..b69b114025b 100644 --- a/src/mongo/s/cluster_commands_helpers.h +++ b/src/mongo/s/cluster_commands_helpers.h @@ -183,8 +183,24 @@ std::vector<AsyncRequestsSender::Response> scatterGatherUnversionedTargetAllShar Shard::RetryPolicy retryPolicy, const BSONObj& query, const BSONObj& collation, + const boost::optional<BSONObj>& letParameters, + const boost::optional<LegacyRuntimeConstants>& runtimeConstants, + bool eligibleForSampling = false); +/** + * This overload is for callers which already have a fully initialized 'ExpressionContext' (e.g. + * callers from the aggregation framework). Most callers should prefer the overload above. + */ +[[nodiscard]] std::vector<AsyncRequestsSender::Response> scatterGatherVersionedTargetByRoutingTable( + boost::intrusive_ptr<ExpressionContext> expCtx, + StringData dbName, + const NamespaceString& nss, + const CollectionRoutingInfo& cri, + const BSONObj& cmdObj, + const ReadPreferenceSetting& readPref, + Shard::RetryPolicy retryPolicy, + const BSONObj& query, + const BSONObj& collation, bool eligibleForSampling = false); - /** * Utility for dispatching versioned commands on a namespace, deciding which shards to @@ -205,7 +221,9 @@ scatterGatherVersionedTargetByRoutingTableNoThrowOnStaleShardVersionErrors( const ReadPreferenceSetting& readPref, Shard::RetryPolicy retryPolicy, const BSONObj& query, - const BSONObj& collation); + const BSONObj& collation, + const boost::optional<BSONObj>& letParameters, + const boost::optional<LegacyRuntimeConstants>& runtimeConstants); /** * Utility for dispatching commands against the primary of a database and attaching the appropriate @@ -297,7 +315,9 @@ std::vector<std::pair<ShardId, BSONObj>> getVersionedRequestsForTargetedShards( const CollectionRoutingInfo& cri, const BSONObj& cmdObj, const BSONObj& query, - const BSONObj& collation); + const BSONObj& collation, + const boost::optional<BSONObj>& letParameters, + const boost::optional<LegacyRuntimeConstants>& runtimeConstants); /** * If the command is running in a transaction, returns the proper routing table to use for targeting diff --git a/src/mongo/s/commands/cluster_analyze_cmd.cpp b/src/mongo/s/commands/cluster_analyze_cmd.cpp index ea0ccdb84a7..208d7df1621 100644 --- a/src/mongo/s/commands/cluster_analyze_cmd.cpp +++ b/src/mongo/s/commands/cluster_analyze_cmd.cpp @@ -91,8 +91,10 @@ public: CommandHelpers::filterCommandRequestForPassthrough(unparsedRequest().body)), ReadPreferenceSetting::get(opCtx), Shard::RetryPolicy::kIdempotent, - BSONObj() /* query */, - BSONObj() /* collation */); + BSONObj() /*query*/, + BSONObj() /*collation*/, + boost::none /*letParameters*/, + boost::none /*runtimeConstants*/); for (const auto& shardResult : shardResponses) { const auto& shardResponse = uassertStatusOK(std::move(shardResult.swResponse)); diff --git a/src/mongo/s/commands/cluster_coll_stats_cmd.cpp b/src/mongo/s/commands/cluster_coll_stats_cmd.cpp index d830e04415c..2f0d84ed2ad 100644 --- a/src/mongo/s/commands/cluster_coll_stats_cmd.cpp +++ b/src/mongo/s/commands/cluster_coll_stats_cmd.cpp @@ -247,8 +247,10 @@ public: opCtx, this, CommandHelpers::filterCommandRequestForPassthrough(cmdObjToSend)), ReadPreferenceSetting::get(opCtx), Shard::RetryPolicy::kIdempotent, - {}, - {}); + {} /*query*/, + {} /*collation*/, + boost::none /*letParameters*/, + boost::none /*runtimeConstants*/); BSONObjBuilder shardStats; std::map<std::string, long long> counts; 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 6fa1d62d5d7..30e8e904bbd 100644 --- a/src/mongo/s/commands/cluster_convert_to_capped_cmd.cpp +++ b/src/mongo/s/commands/cluster_convert_to_capped_cmd.cpp @@ -60,8 +60,10 @@ bool nonShardedCollectionCommandPassthrough(OperationContext* opCtx, cmdObj, ReadPreferenceSetting::get(opCtx), retryPolicy, - {}, - {}); + {} /*query*/, + {} /*collation*/, + boost::none /*letParameters*/, + boost::none /*runtimeConstants*/); invariant(responses.size() == 1); const auto cmdResponse = uassertStatusOK(std::move(responses.front().swResponse)); diff --git a/src/mongo/s/commands/cluster_count_cmd.h b/src/mongo/s/commands/cluster_count_cmd.h index 1325c89a21e..045b1895728 100644 --- a/src/mongo/s/commands/cluster_count_cmd.h +++ b/src/mongo/s/commands/cluster_count_cmd.h @@ -152,7 +152,9 @@ public: Shard::RetryPolicy::kIdempotent, countRequest.getQuery(), collation, - true /* eligibleForSampling */); + boost::none /*letParameters*/, + boost::none /*runtimeConstants*/, + true /*eligibleForSampling*/); } catch (const ExceptionFor<ErrorCodes::CommandOnShardedViewNotSupportedOnMongod>& ex) { // Rewrite the count command as an aggregation. auto countRequest = CountCommandRequest::parse(IDLParserContext("count"), cmdObj); @@ -260,7 +262,9 @@ public: ReadPreferenceSetting::get(opCtx), Shard::RetryPolicy::kIdempotent, targetingQuery, - targetingCollation); + targetingCollation, + boost::none /*letParameters*/, + boost::none /*runtimeConstants*/); } catch (const ExceptionFor<ErrorCodes::CommandOnShardedViewNotSupportedOnMongod>& ex) { CountCommandRequest countRequest(NamespaceStringOrUUID(NamespaceString{})); try { diff --git a/src/mongo/s/commands/cluster_create_indexes_cmd.cpp b/src/mongo/s/commands/cluster_create_indexes_cmd.cpp index e07aa1700e0..095ccd6bbe9 100644 --- a/src/mongo/s/commands/cluster_create_indexes_cmd.cpp +++ b/src/mongo/s/commands/cluster_create_indexes_cmd.cpp @@ -121,8 +121,10 @@ public: applyReadWriteConcern(opCtx, this, cmdToBeSent)), ReadPreferenceSetting(ReadPreference::PrimaryOnly), Shard::RetryPolicy::kNoRetry, - BSONObj() /* query */, - BSONObj() /* collation */); + BSONObj() /*query*/, + BSONObj() /*collation*/, + boost::none /*letParameters*/, + boost::none /*runtimeConstants*/); std::string errmsg; const bool ok = diff --git a/src/mongo/s/commands/cluster_data_size_cmd.cpp b/src/mongo/s/commands/cluster_data_size_cmd.cpp index dda5ed02fcf..057f9e8ad73 100644 --- a/src/mongo/s/commands/cluster_data_size_cmd.cpp +++ b/src/mongo/s/commands/cluster_data_size_cmd.cpp @@ -88,8 +88,10 @@ public: CommandHelpers::filterCommandRequestForPassthrough(cmd.toBSON({}))), ReadPreferenceSetting::get(opCtx), Shard::RetryPolicy::kIdempotent, - {}, - {}); + {} /*query*/, + {} /*collation*/, + boost::none /*letParameters*/, + boost::none /*runtimeConstants*/); std::int64_t size = 0; std::int64_t numObjects = 0; diff --git a/src/mongo/s/commands/cluster_distinct_cmd.cpp b/src/mongo/s/commands/cluster_distinct_cmd.cpp index 3c9ff302f7a..5fb9a701419 100644 --- a/src/mongo/s/commands/cluster_distinct_cmd.cpp +++ b/src/mongo/s/commands/cluster_distinct_cmd.cpp @@ -146,7 +146,9 @@ public: ReadPreferenceSetting::get(opCtx), Shard::RetryPolicy::kIdempotent, targetingQuery, - targetingCollation); + targetingCollation, + boost::none /*letParameters*/, + boost::none /*runtimeConstants*/); } catch (const ExceptionFor<ErrorCodes::CommandOnShardedViewNotSupportedOnMongod>& ex) { auto parsedDistinct = ParsedDistinct::parse( opCtx, ex->getNamespace(), cmdObj, ExtensionsCallbackNoop(), true); @@ -234,6 +236,8 @@ public: Shard::RetryPolicy::kIdempotent, query, collation, + boost::none /*letParameters*/, + boost::none /*runtimeConstants*/, true /* eligibleForSampling */); } catch (const ExceptionFor<ErrorCodes::CommandOnShardedViewNotSupportedOnMongod>& ex) { auto parsedDistinct = ParsedDistinct::parse( diff --git a/src/mongo/s/commands/cluster_filemd5_cmd.cpp b/src/mongo/s/commands/cluster_filemd5_cmd.cpp index 63b5a2a5033..12ab9f07730 100644 --- a/src/mongo/s/commands/cluster_filemd5_cmd.cpp +++ b/src/mongo/s/commands/cluster_filemd5_cmd.cpp @@ -107,7 +107,9 @@ public: ReadPreferenceSetting::get(opCtx), Shard::RetryPolicy::kIdempotent, routingQuery, - CollationSpec::kSimpleSpec); + CollationSpec::kSimpleSpec, + boost::none /*letParameters*/, + boost::none /*runtimeConstants*/); invariant(shardResults.size() == 1); const auto shardResponse = uassertStatusOK(std::move(shardResults[0].swResponse)); uassertStatusOK(shardResponse.status); diff --git a/src/mongo/s/commands/cluster_find_cmd.h b/src/mongo/s/commands/cluster_find_cmd.h index e8ed843575a..cd46d911895 100644 --- a/src/mongo/s/commands/cluster_find_cmd.h +++ b/src/mongo/s/commands/cluster_find_cmd.h @@ -161,7 +161,9 @@ public: ReadPreferenceSetting::get(opCtx), Shard::RetryPolicy::kIdempotent, findCommand->getFilter(), - findCommand->getCollation()); + findCommand->getCollation(), + findCommand->getLet(), + findCommand->getLegacyRuntimeConstants()); millisElapsed = timer.millis(); const char* mongosStageName = diff --git a/src/mongo/s/commands/cluster_index_filter_cmd.cpp b/src/mongo/s/commands/cluster_index_filter_cmd.cpp index f2a1bf18dba..cd81e568d77 100644 --- a/src/mongo/s/commands/cluster_index_filter_cmd.cpp +++ b/src/mongo/s/commands/cluster_index_filter_cmd.cpp @@ -101,7 +101,9 @@ public: ReadPreferenceSetting::get(opCtx), Shard::RetryPolicy::kIdempotent, query, - CollationSpec::kSimpleSpec); + CollationSpec::kSimpleSpec, + boost::none /*letParameters*/, + boost::none /*runtimeConstants*/); // Sort shard responses by shard id. std::sort(shardResponses.begin(), 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 b1e9ff01062..5e75487858c 100644 --- a/src/mongo/s/commands/cluster_plan_cache_clear_cmd.cpp +++ b/src/mongo/s/commands/cluster_plan_cache_clear_cmd.cpp @@ -105,7 +105,9 @@ bool ClusterPlanCacheClearCmd::run(OperationContext* opCtx, ReadPreferenceSetting::get(opCtx), Shard::RetryPolicy::kIdempotent, query, - CollationSpec::kSimpleSpec); + CollationSpec::kSimpleSpec, + boost::none /*letParameters*/, + boost::none /*runtimeConstants*/); // Sort shard responses by shard id. std::sort(shardResponses.begin(), 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 3cd1e398325..e60c92d29d8 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 @@ -116,8 +116,10 @@ public: opCtx, this, CommandHelpers::filterCommandRequestForPassthrough(cmdObj)), ReadPreferenceSetting::get(opCtx), Shard::RetryPolicy::kNotIdempotent, - BSONObj() /* query */, - BSONObj() /* collation */); + BSONObj() /*query*/, + BSONObj() /*collation*/, + boost::none /*letParameters*/, + boost::none /*runtimeConstants*/); std::string errmsg; const bool ok = diff --git a/src/mongo/s/commands/cluster_validate_cmd.cpp b/src/mongo/s/commands/cluster_validate_cmd.cpp index 3d9e62e8e45..36512d0c920 100644 --- a/src/mongo/s/commands/cluster_validate_cmd.cpp +++ b/src/mongo/s/commands/cluster_validate_cmd.cpp @@ -91,8 +91,10 @@ public: opCtx, this, CommandHelpers::filterCommandRequestForPassthrough(cmdObj)), ReadPreferenceSetting::get(opCtx), Shard::RetryPolicy::kIdempotent, - {}, - {}); + {} /*query*/, + {} /*collation*/, + boost::none /*letParameters*/, + boost::none /*runtimeConstants*/); Status firstFailedShardStatus = Status::OK(); bool isValid = true; |