diff options
author | David Percy <david.percy@mongodb.com> | 2019-11-11 22:29:48 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-11-11 22:29:48 +0000 |
commit | b26181808380c2a448687d331dab7d19e9f9f2e4 (patch) | |
tree | a0bc6667d3556e49ab1ef43414e03d2d1ab33c56 /src/mongo/db/query | |
parent | e9d6bf00473292b6169fbdecb85e52a1fe1f808a (diff) | |
download | mongo-b26181808380c2a448687d331dab7d19e9f9f2e4.tar.gz |
SERVER-38691 Include serverInfo in explain output for aggregation and sharding
Diffstat (limited to 'src/mongo/db/query')
-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 |
5 files changed, 101 insertions, 20 deletions
diff --git a/src/mongo/db/query/SConscript b/src/mongo/db/query/SConscript index 4c526ba5845..0d44a77e91a 100644 --- a/src/mongo/db/query/SConscript +++ b/src/mongo/db/query/SConscript @@ -93,6 +93,7 @@ env.CppUnitTest( 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 f39f959b545..5cd84b98fa8 100644 --- a/src/mongo/db/query/explain.cpp +++ b/src/mongo/db/query/explain.cpp @@ -45,6 +45,7 @@ #include "mongo/db/exec/working_set_common.h" #include "mongo/db/keypattern.h" #include "mongo/db/query/canonical_query_encoder.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" @@ -746,17 +747,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. @@ -866,6 +856,8 @@ void Explain::explainPipelineExecutor(PlanExecutor* exec, } *out << "stages" << Value(pps->writeExplainOps(verbosity)); + + explain_common::generateServerInfo(out); } // static @@ -898,7 +890,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 |