summaryrefslogtreecommitdiff
path: root/src/mongo/s/cluster_commands_helpers.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s/cluster_commands_helpers.cpp')
-rw-r--r--src/mongo/s/cluster_commands_helpers.cpp82
1 files changed, 11 insertions, 71 deletions
diff --git a/src/mongo/s/cluster_commands_helpers.cpp b/src/mongo/s/cluster_commands_helpers.cpp
index 1a84121bf9e..5c0469ab245 100644
--- a/src/mongo/s/cluster_commands_helpers.cpp
+++ b/src/mongo/s/cluster_commands_helpers.cpp
@@ -35,8 +35,6 @@
#include "mongo/s/cluster_commands_helpers.h"
-#include "mongo/bson/mutable/algorithm.h"
-#include "mongo/bson/mutable/document.h"
#include "mongo/bson/util/bson_extract.h"
#include "mongo/db/catalog/collection_uuid_mismatch_info.h"
#include "mongo/db/commands.h"
@@ -48,7 +46,6 @@
#include "mongo/db/query/collation/collator_factory_interface.h"
#include "mongo/db/query/cursor_response.h"
#include "mongo/db/repl/read_concern_args.h"
-#include "mongo/db/repl/read_concern_level.h"
#include "mongo/executor/task_executor_pool.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/rpc/write_concern_error_detail.h"
@@ -64,11 +61,6 @@
#include "mongo/s/transaction_router.h"
#include "mongo/util/scopeguard.h"
-#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand
-
-using mongo::repl::ReadConcernArgs;
-using mongo::repl::ReadConcernLevel;
-
namespace mongo {
void appendWriteConcernErrorDetailToCmdResponse(const ShardId& shardId,
@@ -139,14 +131,13 @@ namespace {
* caller.
*/
std::vector<AsyncRequestsSender::Request> buildVersionedRequestsForTargetedShards(
- boost::intrusive_ptr<ExpressionContext> expCtx,
+ OperationContext* opCtx,
const NamespaceString& nss,
const ChunkManager& cm,
const std::set<ShardId>& shardsToSkip,
const BSONObj& cmdObj,
const BSONObj& query,
const BSONObj& collation) {
- auto opCtx = expCtx->opCtx;
auto cmdToSend = cmdObj;
@@ -179,6 +170,7 @@ std::vector<AsyncRequestsSender::Request> buildVersionedRequestsForTargetedShard
CollatorFactoryInterface::get(opCtx->getServiceContext())->makeFromBSON(collation));
}
+ auto expCtx = make_intrusive<ExpressionContext>(opCtx, std::move(collator), nss);
cm.getShardIdsForQuery(expCtx, query, collation, &shardIds);
for (const ShardId& shardId : shardIds) {
@@ -400,20 +392,6 @@ std::vector<AsyncRequestsSender::Response> scatterGatherUnversionedTargetAllShar
return gatherResponses(opCtx, dbName, readPref, retryPolicy, requests);
}
-std::vector<AsyncRequestsSender::Response> scatterGatherUnversionedTargetConfigServerAndShards(
- OperationContext* opCtx,
- StringData dbName,
- const BSONObj& cmdObj,
- const ReadPreferenceSetting& readPref,
- Shard::RetryPolicy retryPolicy) {
- std::vector<AsyncRequestsSender::Request> requests;
- for (auto shardId : Grid::get(opCtx)->shardRegistry()->getAllShardIds(opCtx))
- requests.emplace_back(std::move(shardId), cmdObj);
- auto configShardId = Grid::get(opCtx)->shardRegistry()->getConfigShard()->getId();
- requests.emplace_back(std::move(configShardId), cmdObj);
- return gatherResponses(opCtx, dbName, readPref, retryPolicy, requests);
-}
-
std::vector<AsyncRequestsSender::Response> scatterGatherVersionedTargetByRoutingTable(
OperationContext* opCtx,
StringData dbName,
@@ -423,28 +401,11 @@ std::vector<AsyncRequestsSender::Response> scatterGatherVersionedTargetByRouting
const ReadPreferenceSetting& readPref,
Shard::RetryPolicy retryPolicy,
const BSONObj& query,
- const BSONObj& collation,
- const boost::optional<BSONObj>& letParameters,
- const boost::optional<LegacyRuntimeConstants>& runtimeConstants) {
- auto expCtx = makeExpressionContextWithDefaultsForTargeter(
- opCtx, nss, collation, boost::none /*explainVerbosity*/, letParameters, runtimeConstants);
- return scatterGatherVersionedTargetByRoutingTable(
- expCtx, dbName, nss, cm, cmdObj, readPref, retryPolicy, query, collation);
-}
-
-[[nodiscard]] std::vector<AsyncRequestsSender::Response> scatterGatherVersionedTargetByRoutingTable(
- boost::intrusive_ptr<ExpressionContext> expCtx,
- StringData dbName,
- const NamespaceString& nss,
- const ChunkManager& cm,
- const BSONObj& cmdObj,
- const ReadPreferenceSetting& readPref,
- Shard::RetryPolicy retryPolicy,
- const BSONObj& query,
const BSONObj& collation) {
const auto requests = buildVersionedRequestsForTargetedShards(
- expCtx, nss, cm, {} /* shardsToSkip */, cmdObj, query, collation);
- return gatherResponses(expCtx->opCtx, dbName, readPref, retryPolicy, requests);
+ opCtx, nss, cm, {} /* shardsToSkip */, cmdObj, query, collation);
+
+ return gatherResponses(opCtx, dbName, readPref, retryPolicy, requests);
}
std::vector<AsyncRequestsSender::Response>
@@ -458,13 +419,9 @@ scatterGatherVersionedTargetByRoutingTableNoThrowOnStaleShardVersionErrors(
const ReadPreferenceSetting& readPref,
Shard::RetryPolicy retryPolicy,
const BSONObj& query,
- 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 BSONObj& collation) {
const auto requests = buildVersionedRequestsForTargetedShards(
- expCtx, nss, cm, shardsToSkip, cmdObj, query, collation);
+ opCtx, nss, cm, shardsToSkip, cmdObj, query, collation);
return gatherResponsesNoThrowOnStaleShardVersionErrors(
opCtx, dbName, readPref, retryPolicy, requests);
@@ -499,12 +456,6 @@ 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 =
cm.isSharded() ? cm.getShardKeyPattern().getKeyPattern().globalMin() : BSONObj();
@@ -515,7 +466,7 @@ AsyncRequestsSender::Response executeCommandAgainstShardWithMinKeyChunk(
readPref,
retryPolicy,
buildVersionedRequestsForTargetedShards(
- expCtx, nss, cm, {} /* shardsToSkip */, cmdObj, query, BSONObj() /* collation */));
+ opCtx, nss, cm, {} /* shardsToSkip */, cmdObj, query, BSONObj() /* collation */));
return std::move(responses.front());
}
@@ -662,7 +613,7 @@ bool appendEmptyResultSet(OperationContext* opCtx,
const std::string& ns) {
invariant(!status.isOK());
- CurOp::get(opCtx)->debug().additiveMetrics.nreturned = 0;
+ CurOp::get(opCtx)->debug().nreturned = 0;
CurOp::get(opCtx)->debug().nShards = 0;
if (status == ErrorCodes::NamespaceNotFound) {
@@ -698,14 +649,10 @@ std::vector<std::pair<ShardId, BSONObj>> getVersionedRequestsForTargetedShards(
const ChunkManager& cm,
const BSONObj& cmdObj,
const BSONObj& query,
- 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 BSONObj& collation) {
std::vector<std::pair<ShardId, BSONObj>> requests;
auto ars_requests = buildVersionedRequestsForTargetedShards(
- expCtx, nss, cm, {} /* shardsToSkip */, cmdObj, query, collation);
+ opCtx, nss, cm, {} /* shardsToSkip */, cmdObj, query, collation);
std::transform(std::make_move_iterator(ars_requests.begin()),
std::make_move_iterator(ars_requests.end()),
std::back_inserter(requests),
@@ -746,13 +693,6 @@ StatusWith<Shard::QueryResponse> loadIndexesFromAuthoritativeShard(OperationCont
auto [indexShard, listIndexesCmd] = [&]() -> std::pair<std::shared_ptr<Shard>, BSONObj> {
auto cmdNoVersion = applyReadWriteConcern(
opCtx, true /* appendRC */, false /* appendWC */, BSON("listIndexes" << nss.coll()));
-
- // force the read concern level to "local" as other values are not supported for listIndexes
- BSONObjBuilder bob(cmdNoVersion.removeField(ReadConcernArgs::kReadConcernFieldName));
- bob.append(ReadConcernArgs::kReadConcernFieldName,
- BSON(ReadConcernArgs::kLevelFieldName << repl::readConcernLevels::kLocalName));
- cmdNoVersion = bob.obj();
-
if (cm.isSharded()) {
// For a sharded collection we must load indexes from a shard with chunks. For
// consistency with cluster listIndexes, load from the shard that owns the minKey chunk.