diff options
author | Cheahuychou Mao <mao.cheahuychou@gmail.com> | 2023-03-24 16:28:56 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-03-24 21:13:26 +0000 |
commit | d55fa78cbb7c31e1d78bd771fb72e3dfd89a697a (patch) | |
tree | a08d62d6db999545c8fbf0dab8ec29516d5626c0 /src/mongo/db/commands/count_cmd.cpp | |
parent | d01f286e19bea0b5d035acf520132f5fee68ec27 (diff) | |
download | mongo-d55fa78cbb7c31e1d78bd771fb72e3dfd89a697a.tar.gz |
SERVER-74065 Support query sampling on replica sets
Diffstat (limited to 'src/mongo/db/commands/count_cmd.cpp')
-rw-r--r-- | src/mongo/db/commands/count_cmd.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/mongo/db/commands/count_cmd.cpp b/src/mongo/db/commands/count_cmd.cpp index b564094df93..a3829237d91 100644 --- a/src/mongo/db/commands/count_cmd.cpp +++ b/src/mongo/db/commands/count_cmd.cpp @@ -46,6 +46,7 @@ #include "mongo/db/s/collection_sharding_state.h" #include "mongo/db/s/query_analysis_writer.h" #include "mongo/logv2/log.h" +#include "mongo/s/query_analysis_sampler_util.h" #include "mongo/util/database_name_util.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand @@ -255,13 +256,16 @@ public: invocation->markMirrored(); } - if (analyze_shard_key::supportsPersistingSampledQueries() && request.getSampleId()) { - analyze_shard_key::QueryAnalysisWriter::get(opCtx) - ->addCountQuery(*request.getSampleId(), - nss, - request.getQuery(), - request.getCollation().value_or(BSONObj())) - .getAsync([](auto) {}); + if (!request.getMirrored()) { + if (auto sampleId = analyze_shard_key::getOrGenerateSampleId( + opCtx, nss, analyze_shard_key::SampledCommandNameEnum::kCount, request)) { + analyze_shard_key::QueryAnalysisWriter::get(opCtx) + ->addCountQuery(*sampleId, + nss, + request.getQuery(), + request.getCollation().value_or(BSONObj())) + .getAsync([](auto) {}); + } } if (ctx->getView()) { |