diff options
author | Cheahuychou Mao <mao.cheahuychou@gmail.com> | 2022-11-07 17:04:29 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-11-07 17:39:23 +0000 |
commit | 7a42b1279680f18b7199b183c9a4f1eb09dbbe0e (patch) | |
tree | 6be65ddd1d4027b132bcacc7e8f1cc1901eaffe6 /src/mongo/s | |
parent | 1b49631dd22d39c4d3e7b544397b4c93b6855deb (diff) | |
download | mongo-7a42b1279680f18b7199b183c9a4f1eb09dbbe0e.tar.gz |
SERVER-71115 Add test coverage that explain queries are not sampled
Diffstat (limited to 'src/mongo/s')
-rw-r--r-- | src/mongo/s/commands/cluster_find_and_modify_cmd.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
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 767287c10db..3c21c4b71c5 100644 --- a/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp +++ b/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp @@ -438,6 +438,7 @@ public: boost::none, nss, applyReadWriteConcern(opCtx, false, false, explainCmd), + true /* isExplain */, &bob); } else { _runCommand(opCtx, @@ -446,6 +447,7 @@ public: cm.dbVersion(), nss, applyReadWriteConcern(opCtx, false, false, explainCmd), + true /* isExplain */, &bob); } @@ -517,6 +519,7 @@ public: boost::none, nss, applyReadWriteConcern(opCtx, this, cmdObjForShard), + false /* isExplain */, &result); } else { _runCommand(opCtx, @@ -525,6 +528,7 @@ public: cm.dbVersion(), nss, applyReadWriteConcern(opCtx, this, cmdObjForShard), + false /* isExplain */, &result); } @@ -549,6 +553,7 @@ private: const boost::optional<DatabaseVersion>& dbVersion, const NamespaceString& nss, const BSONObj& cmdObj, + bool isExplain, BSONObjBuilder* result) { auto txnRouter = TransactionRouter::get(opCtx); bool isRetryableWrite = opCtx->getTxnNumber() && !txnRouter; @@ -556,9 +561,11 @@ private: const auto response = [&] { std::vector<AsyncRequestsSender::Request> requests; BSONObj filteredCmdObj = CommandHelpers::filterCommandRequestForPassthrough(cmdObj); - if (auto sampleId = analyze_shard_key::tryGenerateSampleId(opCtx, nss)) { - filteredCmdObj = analyze_shard_key::appendSampleId(std::move(filteredCmdObj), - std::move(*sampleId)); + if (!isExplain) { + if (auto sampleId = analyze_shard_key::tryGenerateSampleId(opCtx, nss)) { + filteredCmdObj = analyze_shard_key::appendSampleId(std::move(filteredCmdObj), + std::move(*sampleId)); + } } BSONObj cmdObjWithVersions(std::move(filteredCmdObj)); @@ -677,8 +684,14 @@ private: // cmdObj. The transaction commit will still use the WC, because it uses the WC // from the opCtx (which has been set previously in Strategy). documentShardKeyUpdateUtil::startTransactionForShardKeyUpdate(opCtx); - _runCommand( - opCtx, shardId, shardVersion, dbVersion, nss, stripWriteConcern(cmdObj), result); + _runCommand(opCtx, + shardId, + shardVersion, + dbVersion, + nss, + stripWriteConcern(cmdObj), + false /* isExplain */, + result); uassertStatusOK(getStatusFromCommandResult(result->asTempObj())); auto commitResponse = documentShardKeyUpdateUtil::commitShardKeyUpdateTransaction(opCtx); |