diff options
author | Jason Rassi <rassi@10gen.com> | 2015-09-11 16:35:07 -0400 |
---|---|---|
committer | Jason Rassi <rassi@10gen.com> | 2015-09-11 21:02:38 -0400 |
commit | 69ad8e1a275a3783d139d1b8832d17cad892d4e3 (patch) | |
tree | af821193db81d3064001d38c6769115cf3915c8c | |
parent | d03334dfa87386feef4b8331f0e183d80495808c (diff) | |
download | mongo-69ad8e1a275a3783d139d1b8832d17cad892d4e3.tar.gz |
SERVER-20267 Move runExplain() to Strategy to fix circular dependency
libmongoscore intentionally depends on libcluster_query, but prior
work for SERVER-20267 introduced a call to Strategy::commandOp()
(libmongoscore) from ClusterFind::runExplain() (libcluster_query),
which created a two-cycle.
This issue is addressed by moving ClusterFind::runExplain() to
Strategy::explainFind().
-rw-r--r-- | src/mongo/s/commands/cluster_find_cmd.cpp | 3 | ||||
-rw-r--r-- | src/mongo/s/query/cluster_find.cpp | 31 | ||||
-rw-r--r-- | src/mongo/s/query/cluster_find.h | 15 | ||||
-rw-r--r-- | src/mongo/s/strategy.cpp | 36 | ||||
-rw-r--r-- | src/mongo/s/strategy.h | 21 |
5 files changed, 57 insertions, 49 deletions
diff --git a/src/mongo/s/commands/cluster_find_cmd.cpp b/src/mongo/s/commands/cluster_find_cmd.cpp index 0b0e60a8a13..445e0870bfe 100644 --- a/src/mongo/s/commands/cluster_find_cmd.cpp +++ b/src/mongo/s/commands/cluster_find_cmd.cpp @@ -36,6 +36,7 @@ #include "mongo/db/query/cursor_response.h" #include "mongo/db/stats/counters.h" #include "mongo/s/query/cluster_find.h" +#include "mongo/s/strategy.h" namespace mongo { namespace { @@ -115,7 +116,7 @@ public: return lpq.getStatus(); } - return ClusterFind::runExplain( + return Strategy::explainFind( txn, cmdObj, *lpq.getValue(), verbosity, serverSelectionMetadata, out); } diff --git a/src/mongo/s/query/cluster_find.cpp b/src/mongo/s/query/cluster_find.cpp index 289f8b29797..abc496f7a37 100644 --- a/src/mongo/s/query/cluster_find.cpp +++ b/src/mongo/s/query/cluster_find.cpp @@ -428,37 +428,6 @@ StatusWith<CursorResponse> ClusterFind::runGetMore(OperationContext* txn, return CursorResponse(request.nss, idToReturn, std::move(batch), startingFrom); } -Status ClusterFind::runExplain(OperationContext* txn, - const BSONObj& findCommand, - const LiteParsedQuery& lpq, - ExplainCommon::Verbosity verbosity, - const rpc::ServerSelectionMetadata& serverSelectionMetadata, - BSONObjBuilder* out) { - BSONObjBuilder explainCmdBob; - int options = 0; - ClusterExplain::wrapAsExplain( - findCommand, verbosity, serverSelectionMetadata, &explainCmdBob, &options); - - // We will time how long it takes to run the commands on the shards. - Timer timer; - - std::vector<Strategy::CommandResult> shardResults; - Strategy::commandOp(txn, - lpq.nss().db().toString(), - explainCmdBob.obj(), - options, - lpq.nss().toString(), - lpq.getFilter(), - &shardResults); - - long long millisElapsed = timer.millis(); - - const char* mongosStageName = ClusterExplain::getStageNameForReadOp(shardResults, findCommand); - - return ClusterExplain::buildExplainResult( - txn, shardResults, mongosStageName, millisElapsed, out); -} - StatusWith<ReadPreferenceSetting> ClusterFind::extractUnwrappedReadPref(const BSONObj& cmdObj, const bool isSlaveOk) { BSONElement queryOptionsElt; diff --git a/src/mongo/s/query/cluster_find.h b/src/mongo/s/query/cluster_find.h index 7a7d3deac69..64821512ded 100644 --- a/src/mongo/s/query/cluster_find.h +++ b/src/mongo/s/query/cluster_find.h @@ -76,21 +76,6 @@ public: const GetMoreRequest& request); /** - * Helper to run an explain of a find operation on the shards. Fills 'out' with the result of - * the of the explain command on success. On failure, returns a non-OK status and does not - * modify 'out'. - * - * Used both if mongos receives an explain command and if it receives an OP_QUERY find with the - * $explain modifier. - */ - static Status runExplain(OperationContext* txn, - const BSONObj& findCommand, - const LiteParsedQuery& lpq, - ExplainCommon::Verbosity verbosity, - const rpc::ServerSelectionMetadata& serverSelectionMetadata, - BSONObjBuilder* out); - - /** * Extracts the read preference from 'cmdObj', or determines the read pref based on 'isSlaveOk' * if 'cmdObj' does not contain a read preference. * diff --git a/src/mongo/s/strategy.cpp b/src/mongo/s/strategy.cpp index 4cd7ec26101..88b3dd35f64 100644 --- a/src/mongo/s/strategy.cpp +++ b/src/mongo/s/strategy.cpp @@ -53,6 +53,7 @@ #include "mongo/s/bson_serializable.h" #include "mongo/s/catalog/catalog_cache.h" #include "mongo/s/client/shard_registry.h" +#include "mongo/s/cluster_explain.h" #include "mongo/s/chunk_manager.h" #include "mongo/s/chunk_version.h" #include "mongo/s/config.h" @@ -212,8 +213,8 @@ void Strategy::queryOp(OperationContext* txn, Request& request) { rpc::ServerSelectionMetadata metadata(secondaryOk, readPreference); BSONObjBuilder explainBuilder; - uassertStatusOK(ClusterFind::runExplain( - txn, findCommand, lpq, verbosity, metadata, &explainBuilder)); + uassertStatusOK( + Strategy::explainFind(txn, findCommand, lpq, verbosity, metadata, &explainBuilder)); BSONObj explainObj = explainBuilder.done(); replyToQuery(0, // query result flags @@ -799,4 +800,35 @@ void Strategy::writeOp(OperationContext* txn, int op, Request& request) { break; } } + +Status Strategy::explainFind(OperationContext* txn, + const BSONObj& findCommand, + const LiteParsedQuery& lpq, + ExplainCommon::Verbosity verbosity, + const rpc::ServerSelectionMetadata& serverSelectionMetadata, + BSONObjBuilder* out) { + BSONObjBuilder explainCmdBob; + int options = 0; + ClusterExplain::wrapAsExplain( + findCommand, verbosity, serverSelectionMetadata, &explainCmdBob, &options); + + // We will time how long it takes to run the commands on the shards. + Timer timer; + + std::vector<Strategy::CommandResult> shardResults; + Strategy::commandOp(txn, + lpq.nss().db().toString(), + explainCmdBob.obj(), + options, + lpq.nss().toString(), + lpq.getFilter(), + &shardResults); + + long long millisElapsed = timer.millis(); + + const char* mongosStageName = ClusterExplain::getStageNameForReadOp(shardResults, findCommand); + + return ClusterExplain::buildExplainResult( + txn, shardResults, mongosStageName, millisElapsed, out); +} } diff --git a/src/mongo/s/strategy.h b/src/mongo/s/strategy.h index 8ac55de81f0..75416719999 100644 --- a/src/mongo/s/strategy.h +++ b/src/mongo/s/strategy.h @@ -28,14 +28,20 @@ #pragma once +#include "mongo/db/query/explain_common.h" #include "mongo/client/connection_string.h" #include "mongo/s/client/shard.h" #include "mongo/s/request.h" namespace mongo { +class LiteParsedQuery; class OperationContext; +namespace rpc { +class ServerSelectionMetadata; +} // namespace rpc + // A spigot to enable the ClusterClientCursor codepath. extern bool useClusterClientCursor; @@ -52,6 +58,21 @@ public: static void writeOp(OperationContext* txn, int op, Request& request); + /** + * Helper to run an explain of a find operation on the shards. Fills 'out' with the result of + * the of the explain command on success. On failure, returns a non-OK status and does not + * modify 'out'. + * + * Used both if mongos receives an explain command and if it receives an OP_QUERY find with the + * $explain modifier. + */ + static Status explainFind(OperationContext* txn, + const BSONObj& findCommand, + const LiteParsedQuery& lpq, + ExplainCommon::Verbosity verbosity, + const rpc::ServerSelectionMetadata& serverSelectionMetadata, + BSONObjBuilder* out); + struct CommandResult { ShardId shardTargetId; ConnectionString target; |