summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEsha Maharishi <esha.maharishi@mongodb.com>2018-04-27 17:42:44 -0400
committerEsha Maharishi <esha.maharishi@mongodb.com>2018-04-30 11:11:23 -0400
commit69b6d9846e3fae2fea9313757c7563b1061cf585 (patch)
tree59ca460db205a8e5ed7e8408aaab26203b1e22d6
parent91504c83ade2ef9c9544a16cfa3e7f8deaafe1b9 (diff)
downloadmongo-69b6d9846e3fae2fea9313757c7563b1061cf585.tar.gz
SERVER-34736 Make ClusterFind::explain directly call scatterGather() rather than go through Strategy::explainFind
-rw-r--r--src/mongo/s/commands/cluster_find_cmd.cpp48
1 files changed, 40 insertions, 8 deletions
diff --git a/src/mongo/s/commands/cluster_find_cmd.cpp b/src/mongo/s/commands/cluster_find_cmd.cpp
index 502061514fa..50050ad9778 100644
--- a/src/mongo/s/commands/cluster_find_cmd.cpp
+++ b/src/mongo/s/commands/cluster_find_cmd.cpp
@@ -38,8 +38,11 @@
#include "mongo/db/stats/counters.h"
#include "mongo/db/views/resolved_view.h"
#include "mongo/rpc/get_status_from_command_result.h"
+#include "mongo/s/catalog_cache.h"
#include "mongo/s/commands/cluster_aggregate.h"
-#include "mongo/s/commands/strategy.h"
+#include "mongo/s/commands/cluster_commands_helpers.h"
+#include "mongo/s/commands/cluster_explain.h"
+#include "mongo/s/grid.h"
#include "mongo/s/query/cluster_find.h"
namespace mongo {
@@ -111,20 +114,49 @@ public:
const NamespaceString nss(CommandHelpers::parseNsCollectionRequired(dbname, cmdObj));
// Parse the command BSON to a QueryRequest.
bool isExplain = true;
- auto qr = QueryRequest::makeFromFindCommand(std::move(nss), cmdObj, isExplain);
- if (!qr.isOK()) {
- return qr.getStatus();
+ auto swQr = QueryRequest::makeFromFindCommand(std::move(nss), cmdObj, isExplain);
+ if (!swQr.isOK()) {
+ return swQr.getStatus();
}
-
+ auto& qr = *swQr.getValue();
try {
- Strategy::explainFind(
- opCtx, cmdObj, *qr.getValue(), verbosity, ReadPreferenceSetting::get(opCtx), out);
+ const auto explainCmd = ClusterExplain::wrapAsExplain(cmdObj, verbosity);
+
+ long long millisElapsed;
+ std::vector<AsyncRequestsSender::Response> shardResponses;
+
+ // We will time how long it takes to run the commands on the shards.
+ Timer timer;
+ const auto routingInfo = uassertStatusOK(
+ Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, qr.nss()));
+ shardResponses =
+ scatterGatherVersionedTargetByRoutingTable(opCtx,
+ qr.nss().db(),
+ qr.nss(),
+ routingInfo,
+ explainCmd,
+ ReadPreferenceSetting::get(opCtx),
+ Shard::RetryPolicy::kIdempotent,
+ qr.getFilter(),
+ qr.getCollation());
+ millisElapsed = timer.millis();
+
+ const char* mongosStageName =
+ ClusterExplain::getStageNameForReadOp(shardResponses.size(), cmdObj);
+
+ uassertStatusOK(ClusterExplain::buildExplainResult(
+ opCtx,
+ ClusterExplain::downconvert(opCtx, shardResponses),
+ mongosStageName,
+ millisElapsed,
+ out));
+
return Status::OK();
} catch (const ExceptionFor<ErrorCodes::CommandOnShardedViewNotSupportedOnMongod>& ex) {
out->resetToEmpty();
- auto aggCmdOnView = qr.getValue().get()->asAggregationCommand();
+ auto aggCmdOnView = qr.asAggregationCommand();
if (!aggCmdOnView.isOK()) {
return aggCmdOnView.getStatus();
}