diff options
author | Ted Tuckman <ted.tuckman@mongodb.com> | 2018-10-02 17:12:12 -0400 |
---|---|---|
committer | Ted Tuckman <ted.tuckman@mongodb.com> | 2018-10-09 10:59:41 -0400 |
commit | addc24e5dcc8c2053df56697d35162a8776446e5 (patch) | |
tree | 16990f2d3dccbfe5e9e7f360339b04c98fd85077 /src/mongo | |
parent | 3dc5e5979bc9a4a914b0a479e88e70078bd02552 (diff) | |
download | mongo-addc24e5dcc8c2053df56697d35162a8776446e5.tar.gz |
SERVER-37007 Add planSummary to idleCursor
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/clientcursor.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/clientcursor.h | 11 | ||||
-rw-r--r-- | src/mongo/db/generic_cursor.idl | 4 | ||||
-rw-r--r-- | src/mongo/db/pipeline/mongo_process_common.cpp | 20 |
4 files changed, 35 insertions, 5 deletions
diff --git a/src/mongo/db/clientcursor.cpp b/src/mongo/db/clientcursor.cpp index 756f1fbc7eb..92e6a1ffb30 100644 --- a/src/mongo/db/clientcursor.cpp +++ b/src/mongo/db/clientcursor.cpp @@ -47,6 +47,7 @@ #include "mongo/db/commands/server_status_metric.h" #include "mongo/db/cursor_server_params.h" #include "mongo/db/jsobj.h" +#include "mongo/db/query/explain.h" #include "mongo/db/repl/repl_client_info.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/util/background.h" @@ -92,7 +93,8 @@ ClientCursor::ClientCursor(ClientCursorParams params, _exec(std::move(params.exec)), _operationUsingCursor(operationUsingCursor), _lastUseDate(now), - _createdDate(now) { + _createdDate(now), + _planSummary(Explain::getPlanSummary(_exec.get())) { invariant(_cursorManager); invariant(_exec); invariant(_operationUsingCursor); @@ -143,6 +145,7 @@ GenericCursor ClientCursor::toGenericCursor() const { gc.setLastAccessDate(getLastUseDate()); gc.setCreatedDate(getCreatedDate()); gc.setNBatchesReturned(getNBatches()); + gc.setPlanSummary(getPlanSummary()); if (auto opCtx = _operationUsingCursor) { gc.setOperationUsingCursorId(opCtx->getOpID()); } diff --git a/src/mongo/db/clientcursor.h b/src/mongo/db/clientcursor.h index 96cae17da5b..83b326b93da 100644 --- a/src/mongo/db/clientcursor.h +++ b/src/mongo/db/clientcursor.h @@ -209,6 +209,14 @@ public: return _createdDate; } + void setPlanSummary(std::string ps) { + _planSummary = std::move(ps); + } + + StringData getPlanSummary() const { + return StringData(_planSummary); + } + /** * Returns a generic cursor containing diagnostics about this cursor. * The caller must either have this cursor pinned or hold a mutex from the cursor manager. @@ -374,6 +382,9 @@ private: Date_t _lastUseDate; Date_t _createdDate; + + // A string with the plan summary of the cursor's query. + std::string _planSummary; }; /** diff --git a/src/mongo/db/generic_cursor.idl b/src/mongo/db/generic_cursor.idl index 24661fa9221..2792a9db88e 100644 --- a/src/mongo/db/generic_cursor.idl +++ b/src/mongo/db/generic_cursor.idl @@ -71,6 +71,10 @@ structs: lsid: type: LogicalSessionId optional: true + planSummary: + description: The plan summary of this cursor's query. + type: string + optional: true operationUsingCursorId: description: The op ID of the operation pinning the cursor. Will be empty for idle cursors. type: long diff --git a/src/mongo/db/pipeline/mongo_process_common.cpp b/src/mongo/db/pipeline/mongo_process_common.cpp index aae991ba05f..1c97921e237 100644 --- a/src/mongo/db/pipeline/mongo_process_common.cpp +++ b/src/mongo/db/pipeline/mongo_process_common.cpp @@ -78,10 +78,22 @@ std::vector<BSONObj> MongoProcessCommon::getCurrentOps( if (cursorMode == CurrentOpCursorMode::kIncludeCursors) { for (auto&& cursor : getIdleCursors(expCtx, userMode)) { - ops.push_back(BSON("type" - << "idleCursor" - << "cursor" - << cursor.toBSON())); + BSONObjBuilder cursorObj; + cursorObj.append("type", "idleCursor"); + // On mongos, planSummary is not present. + auto planSummaryData = cursor.getPlanSummary(); + if (planSummaryData) { + auto planSummaryText = planSummaryData->toString(); + // Plan summary has to appear in the top level object, not the cursor object. + // We remove it, create the op, then put it back. + cursor.setPlanSummary(boost::none); + cursorObj.append("planSummary", planSummaryText); + cursorObj.append("cursor", cursor.toBSON()); + cursor.setPlanSummary(StringData(planSummaryText)); + } else { + cursorObj.append("cursor", cursor.toBSON()); + } + ops.emplace_back(cursorObj.obj()); } } |