summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBernard Gorman <bernard.gorman@gmail.com>2017-03-03 14:56:40 +0000
committerDavid Storch <david.storch@10gen.com>2017-03-07 11:07:35 -0500
commit3cba97198638df3750e3b455e2ad57af7ee536ae (patch)
tree44a314410a2a47ca4d4ef6503a9c0b6db8614470 /src
parentc2c8abc0a682be21c911e51ad368b09fd5d73ed7 (diff)
downloadmongo-3cba97198638df3750e3b455e2ad57af7ee536ae.tar.gz
SERVER-28196 Make legacy query and getMore appear in a consistent format across currentOp, profiler and logs
Closes #1139 Signed-off-by: David Storch <david.storch@10gen.com>
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/curop.cpp27
-rw-r--r--src/mongo/db/curop.h17
-rw-r--r--src/mongo/db/query/find.cpp10
3 files changed, 34 insertions, 20 deletions
diff --git a/src/mongo/db/curop.cpp b/src/mongo/db/curop.cpp
index 3b5f71f23ce..51016d486ce 100644
--- a/src/mongo/db/curop.cpp
+++ b/src/mongo/db/curop.cpp
@@ -39,7 +39,6 @@
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
#include "mongo/db/commands/server_status_metric.h"
-#include "mongo/db/cursor_id.h"
#include "mongo/db/json.h"
#include "mongo/db/query/getmore_request.h"
#include "mongo/db/query/plan_summary_stats.h"
@@ -69,10 +68,8 @@ const std::vector<const char*> kDollarQueryModifiers = {
"$maxTimeMS",
};
-/**
- * For a find using the OP_QUERY protocol (as opposed to the commands protocol), upconverts the
- * "query" field so that the profiling entry matches that of the find command.
- */
+} // namespace
+
BSONObj upconvertQueryEntry(const BSONObj& query,
const NamespaceString& nss,
int ntoreturn,
@@ -128,10 +125,6 @@ BSONObj upconvertQueryEntry(const BSONObj& query,
return bob.obj();
}
-/**
- * For a getMore using OP_GET_MORE, as opposed to getMore command, upconverts the "query" field so
- * that the profiling entry matches that of the getMore command.
- */
BSONObj upconvertGetMoreEntry(const NamespaceString& nss, CursorId cursorId, int ntoreturn) {
return GetMoreRequest(nss,
cursorId,
@@ -143,8 +136,6 @@ BSONObj upconvertGetMoreEntry(const NamespaceString& nss, CursorId cursorId, int
.toBSON();
}
-} // namespace
-
/**
* This type decorates a Client object with a stack of active CurOp objects.
*
@@ -432,7 +423,16 @@ string OpDebug::report(Client* client,
}
}
- auto query = curop.query();
+ BSONObj query;
+
+ // If necessary, upconvert legacy find operations so that their log lines resemble their find
+ // command counterpart.
+ if (!iscommand && networkOp == dbQuery) {
+ query =
+ upconvertQueryEntry(curop.query(), NamespaceString(curop.getNS()), ntoreturn, ntoskip);
+ } else {
+ query = curop.query();
+ }
if (!query.isEmpty()) {
if (iscommand) {
@@ -556,9 +556,6 @@ void OpDebug::append(const CurOp& curop,
upconvertQueryEntry(curop.query(), nss, ntoreturn, ntoskip),
maxElementSize,
&b);
- } else if (!iscommand && networkOp == dbGetMore) {
- appendAsObjOrString(
- "query", upconvertGetMoreEntry(nss, cursorid, ntoreturn), maxElementSize, &b);
} else if (curop.haveQuery()) {
const char* fieldName = (logicalOp == LogicalOp::opCommand) ? "command" : "query";
appendAsObjOrString(fieldName, curop.query(), maxElementSize, &b);
diff --git a/src/mongo/db/curop.h b/src/mongo/db/curop.h
index f0aea88f81d..4e0ef0d2d7b 100644
--- a/src/mongo/db/curop.h
+++ b/src/mongo/db/curop.h
@@ -33,6 +33,7 @@
#include "mongo/base/disallow_copying.h"
#include "mongo/db/commands.h"
+#include "mongo/db/cursor_id.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/server_options.h"
#include "mongo/platform/atomic_word.h"
@@ -327,7 +328,7 @@ public:
}
/**
- * Sets the original command object. Used only by the getMore command.
+ * Sets the original command object.
*/
void setOriginatingCommand_inlock(const BSONObj& commandObj) {
_originatingCommand = commandObj.getOwned();
@@ -457,4 +458,18 @@ private:
std::string _planSummary;
};
+
+/**
+ * Upconverts a legacy query object such that it matches the format of the find command.
+ */
+BSONObj upconvertQueryEntry(const BSONObj& query,
+ const NamespaceString& nss,
+ int ntoreturn,
+ int ntoskip);
+
+/**
+ * Generates a getMore command object from the specified namespace, cursor ID and batchsize.
+ */
+BSONObj upconvertGetMoreEntry(const NamespaceString& nss, CursorId cursorId, int ntoreturn);
+
} // namespace mongo
diff --git a/src/mongo/db/query/find.cpp b/src/mongo/db/query/find.cpp
index 9fcaa7cef02..f60bbe33ae5 100644
--- a/src/mongo/db/query/find.cpp
+++ b/src/mongo/db/query/find.cpp
@@ -380,9 +380,11 @@ Message getMore(OperationContext* txn,
stdx::lock_guard<Client> lk(*txn->getClient());
curOp.setPlanSummary_inlock(planSummary);
- // Ensure that the original query or command object is available in the slow query log,
- // profiler and currentOp.
- curOp.setQuery_inlock(cc->getQuery());
+ // Ensure that the original query object is available in the slow query log, profiler
+ // and currentOp. Upconvert _query to resemble a getMore command, and set the original
+ // command or upconverted legacy query in the originatingCommand field.
+ curOp.setQuery_inlock(upconvertGetMoreEntry(nss, cursorid, ntoreturn));
+ curOp.setOriginatingCommand_inlock(cc->getQuery());
}
PlanExecutor::ExecState state;
@@ -673,7 +675,7 @@ std::string runQuery(OperationContext* txn,
nss.ns(),
txn->recoveryUnit()->isReadingFromMajorityCommittedSnapshot(),
qr.getOptions(),
- qr.getFilter()});
+ upconvertQueryEntry(q.query, qr.nss(), q.ntoreturn, q.ntoskip)});
ccId = pinnedCursor.getCursor()->cursorid();
LOG(5) << "caching executor with cursorid " << ccId << " after returning " << numResults