summaryrefslogtreecommitdiff
path: root/src/mongo/s/commands/cluster_pipeline_cmd.cpp
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2017-02-10 11:52:18 -0500
committerDavid Storch <david.storch@10gen.com>2017-03-13 09:46:14 -0400
commit82b16740f8a66093b453a73a04b3b9bd00e5d7a0 (patch)
tree62d156fc9676526ecbea19cd03ef7a293579c4df /src/mongo/s/commands/cluster_pipeline_cmd.cpp
parent73f9e8b8a8422becf8694fe3d82c0e647dc71189 (diff)
downloadmongo-82b16740f8a66093b453a73a04b3b9bd00e5d7a0.tar.gz
SERVER-19758 add support for "executionStats" and "allPlansExecution" to agg explain
Like other explainable commands, aggregate can now be explained using the explain command, e.g. db.runCommand({explain: {aggregate: ...}, verbosity: "executionStats"}). The existing explain:true flag corresponds to "queryPlanner" mode and is still supported. However, explain:true cannot be specified when explaining aggregate via the explain command. Additional execution information is provided only in the $cursor section of the aggregation explain output. Having aggregation stages themselves track and report execution info is further work.
Diffstat (limited to 'src/mongo/s/commands/cluster_pipeline_cmd.cpp')
-rw-r--r--src/mongo/s/commands/cluster_pipeline_cmd.cpp45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/mongo/s/commands/cluster_pipeline_cmd.cpp b/src/mongo/s/commands/cluster_pipeline_cmd.cpp
index e533ae05392..21571bd6e4f 100644
--- a/src/mongo/s/commands/cluster_pipeline_cmd.cpp
+++ b/src/mongo/s/commands/cluster_pipeline_cmd.cpp
@@ -35,6 +35,7 @@
#include "mongo/base/status.h"
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/commands.h"
+#include "mongo/rpc/metadata/server_selection_metadata.h"
#include "mongo/s/commands/cluster_aggregate.h"
namespace mongo {
@@ -80,13 +81,55 @@ public:
BSONObjBuilder& result) {
const NamespaceString nss(parseNsCollectionRequired(dbname, cmdObj));
+ auto request = AggregationRequest::parseFromBSON(nss, cmdObj);
+ if (!request.isOK()) {
+ return appendCommandStatus(result, request.getStatus());
+ }
+
ClusterAggregate::Namespaces nsStruct;
nsStruct.requestedNss = nss;
nsStruct.executionNss = std::move(nss);
- auto status = ClusterAggregate::runAggregate(opCtx, nsStruct, cmdObj, options, &result);
+ auto status = ClusterAggregate::runAggregate(
+ opCtx, nsStruct, request.getValue(), cmdObj, options, &result);
appendCommandStatus(result, status);
return status.isOK();
}
+
+ Status explain(OperationContext* opCtx,
+ const std::string& dbName,
+ const BSONObj& cmdObj,
+ ExplainOptions::Verbosity verbosity,
+ const rpc::ServerSelectionMetadata& serverSelectionMetadata,
+ BSONObjBuilder* out) const override {
+ const NamespaceString nss(parseNsCollectionRequired(dbName, cmdObj));
+
+ auto request = AggregationRequest::parseFromBSON(nss, cmdObj, verbosity);
+ if (!request.isOK()) {
+ return request.getStatus();
+ }
+
+ // Add the server selection metadata to the aggregate command in the "unwrapped" format that
+ // runAggregate() expects: {aggregate: ..., $queryOptions: {$readPreference: ...}}.
+ BSONObjBuilder aggCmdBuilder;
+ aggCmdBuilder.appendElements(cmdObj);
+ if (auto readPref = serverSelectionMetadata.getReadPreference()) {
+ auto readPrefObj = readPref->toBSON();
+ aggCmdBuilder.append(QueryRequest::kUnwrappedReadPrefField,
+ BSON("$readPreference" << readPrefObj));
+ }
+
+ int options = 0;
+ if (serverSelectionMetadata.isSecondaryOk()) {
+ options |= QueryOption_SlaveOk;
+ }
+
+ ClusterAggregate::Namespaces nsStruct;
+ nsStruct.requestedNss = nss;
+ nsStruct.executionNss = std::move(nss);
+
+ return ClusterAggregate::runAggregate(
+ opCtx, nsStruct, request.getValue(), cmdObj, options, out);
+ }
} clusterPipelineCmd;
} // namespace