diff options
author | David Percy <david.percy@mongodb.com> | 2019-11-04 17:32:44 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-11-04 17:32:44 +0000 |
commit | 80e0497ebaaaf87707239f661cac2ab99ca9a88c (patch) | |
tree | 88fd20872871d1b6864d1f826bcc0435c8571b53 /src | |
parent | 3ee34d4b15bb263106427688b7915bb8571eaecd (diff) | |
download | mongo-80e0497ebaaaf87707239f661cac2ab99ca9a88c.tar.gz |
SERVER-38691 Include serverInfo in explain output for aggregation and sharding
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/query/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/db/query/explain.cpp | 16 | ||||
-rw-r--r-- | src/mongo/db/query/explain.h | 8 | ||||
-rw-r--r-- | src/mongo/db/query/explain_common.cpp | 50 | ||||
-rw-r--r-- | src/mongo/db/query/explain_common.h | 46 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_explain.cpp | 2 | ||||
-rw-r--r-- | src/mongo/s/query/cluster_aggregate.cpp | 7 |
7 files changed, 109 insertions, 21 deletions
diff --git a/src/mongo/db/query/SConscript b/src/mongo/db/query/SConscript index 4e21c1b2417..b39bf5d553d 100644 --- a/src/mongo/db/query/SConscript +++ b/src/mongo/db/query/SConscript @@ -85,6 +85,7 @@ env.Library( env.Library( target="query_common", source=[ + "explain_common.cpp", "find_common.cpp", "parsed_distinct.cpp", ], diff --git a/src/mongo/db/query/explain.cpp b/src/mongo/db/query/explain.cpp index 3466e16240c..9fa426ad53b 100644 --- a/src/mongo/db/query/explain.cpp +++ b/src/mongo/db/query/explain.cpp @@ -47,6 +47,7 @@ #include "mongo/db/keypattern.h" #include "mongo/db/query/canonical_query_encoder.h" #include "mongo/db/query/collection_query_info.h" +#include "mongo/db/query/explain_common.h" #include "mongo/db/query/get_executor.h" #include "mongo/db/query/plan_executor.h" #include "mongo/db/query/plan_summary_stats.h" @@ -757,17 +758,6 @@ void Explain::generateSinglePlanExecutionInfo(const PlanStageStats* stats, stagesBob.doneFast(); } -// static -void Explain::generateServerInfo(BSONObjBuilder* out) { - BSONObjBuilder serverBob(out->subobjStart("serverInfo")); - out->append("host", getHostNameCached()); - out->appendNumber("port", serverGlobalParams.port); - auto&& vii = VersionInfoInterface::instance(); - out->append("version", vii.version()); - out->append("gitVersion", vii.gitVersion()); - serverBob.doneFast(); -} - std::unique_ptr<PlanStageStats> Explain::getWinningPlanTrialStats(PlanExecutor* exec) { // Inspect the tree to see if there is a MultiPlanStage. Plan selection has already happened at // this point, since we have a PlanExecutor. @@ -877,6 +867,8 @@ void Explain::explainPipelineExecutor(PlanExecutor* exec, } *out << "stages" << Value(pps->writeExplainOps(verbosity)); + + explain_common::generateServerInfo(out); } // static @@ -909,7 +901,7 @@ void Explain::explainStages(PlanExecutor* exec, extraInfo, out); - generateServerInfo(out); + explain_common::generateServerInfo(out); } // static diff --git a/src/mongo/db/query/explain.h b/src/mongo/db/query/explain.h index e6ad7cc0c5c..2fff62ac1d2 100644 --- a/src/mongo/db/query/explain.h +++ b/src/mongo/db/query/explain.h @@ -236,14 +236,6 @@ private: Status executePlanStatus, PlanStageStats* winningPlanTrialStats, BSONObjBuilder* out); - - /** - * Adds the 'serverInfo' explain section to the BSON object being build - * by 'out'. - * - * This is a helper for generating explain BSON. It is used by explainStages(...). - */ - static void generateServerInfo(BSONObjBuilder* out); }; } // namespace mongo diff --git a/src/mongo/db/query/explain_common.cpp b/src/mongo/db/query/explain_common.cpp new file mode 100644 index 00000000000..01242acf6fd --- /dev/null +++ b/src/mongo/db/query/explain_common.cpp @@ -0,0 +1,50 @@ +/** + * Copyright (C) 2019-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/db/query/explain_common.h" + +#include "mongo/db/server_options.h" +#include "mongo/util/net/socket_utils.h" +#include "mongo/util/version.h" + +namespace mongo::explain_common { + +void generateServerInfo(BSONObjBuilder* out) { + BSONObjBuilder serverBob(out->subobjStart("serverInfo")); + out->append("host", getHostNameCached()); + out->appendNumber("port", serverGlobalParams.port); + auto&& vii = VersionInfoInterface::instance(); + out->append("version", vii.version()); + out->append("gitVersion", vii.gitVersion()); + serverBob.doneFast(); +} + +} // namespace mongo::explain_common diff --git a/src/mongo/db/query/explain_common.h b/src/mongo/db/query/explain_common.h new file mode 100644 index 00000000000..d9b035beb8f --- /dev/null +++ b/src/mongo/db/query/explain_common.h @@ -0,0 +1,46 @@ +/** + * Copyright (C) 2019-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#pragma once + +#include "mongo/bson/bsonobjbuilder.h" + +/** + * Namespace for static methods that are shared between explain on mongod and on mongos. + */ +namespace mongo::explain_common { + +/** + * Adds the 'serverInfo' explain section to the BSON object being built by 'out'. + * + * This section include the host, port, version, and gitVersion. + */ +void generateServerInfo(BSONObjBuilder* out); + +} // namespace mongo::explain_common diff --git a/src/mongo/s/commands/cluster_explain.cpp b/src/mongo/s/commands/cluster_explain.cpp index 3082a34fc7b..ce55b18d38d 100644 --- a/src/mongo/s/commands/cluster_explain.cpp +++ b/src/mongo/s/commands/cluster_explain.cpp @@ -32,6 +32,7 @@ #include "mongo/bson/bsonmisc.h" #include "mongo/db/command_generic_argument.h" #include "mongo/db/commands.h" +#include "mongo/db/query/explain_common.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/commands/cluster_explain.h" @@ -356,6 +357,7 @@ Status ClusterExplain::buildExplainResult(OperationContext* opCtx, buildPlannerInfo(opCtx, shardResults, mongosStageName, out); buildExecStats(shardResults, mongosStageName, millisElapsed, out); + explain_common::generateServerInfo(out); return Status::OK(); } diff --git a/src/mongo/s/query/cluster_aggregate.cpp b/src/mongo/s/query/cluster_aggregate.cpp index 4696181c003..972628a1498 100644 --- a/src/mongo/s/query/cluster_aggregate.cpp +++ b/src/mongo/s/query/cluster_aggregate.cpp @@ -50,6 +50,7 @@ #include "mongo/db/pipeline/sharded_agg_helpers.h" #include "mongo/db/query/collation/collator_factory_interface.h" #include "mongo/db/query/cursor_response.h" +#include "mongo/db/query/explain_common.h" #include "mongo/db/query/find_common.h" #include "mongo/db/views/resolved_view.h" #include "mongo/db/views/view.h" @@ -208,6 +209,10 @@ Status ClusterAggregate::runAggregate(OperationContext* opCtx, } auto targeter = std::move(targetingStatus.getValue()); + if (request.getExplain()) { + explain_common::generateServerInfo(result); + } + switch (targeter.policy) { case sharded_agg_helpers::AggregationTargeter::TargetingPolicy::kPassthrough: { // A pipeline with $changeStream should never be allowed to passthrough. @@ -222,8 +227,8 @@ Status ClusterAggregate::runAggregate(OperationContext* opCtx, } case sharded_agg_helpers::AggregationTargeter::TargetingPolicy::kMongosRequired: { - auto expCtx = targeter.pipeline->getContext(); // If this is an explain write the explain output and return. + auto expCtx = targeter.pipeline->getContext(); if (expCtx->explain) { *result << "splitPipeline" << BSONNULL << "mongos" << Document{ |