summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2015-12-09 17:48:30 -0500
committerDavid Storch <david.storch@10gen.com>2015-12-11 13:33:44 -0500
commit6670ca3ffaf09f79eff8e4e9f618cd1a13481398 (patch)
tree35b18e021e91ce8f0e4089c16d0f8f94ec80b202
parent218539ae2c5699e95f543f8d247823570c0cb264 (diff)
downloadmongo-6670ca3ffaf09f79eff8e4e9f618cd1a13481398.tar.gz
SERVER-21750 clean up getMore logging and profiling
--Omit ntoreturn and ntoskip from the getMore command log line. --Add nreturned to the getMore command log line. --Upconvert OP_GET_MORE profiler entries to match getMore cmd. (cherry picked from commit bb7e1e539da115da4ee1146c79e47c23109dce95)
-rw-r--r--jstests/core/profile4.js14
-rw-r--r--src/mongo/db/SConscript1
-rw-r--r--src/mongo/db/commands/getmore_cmd.cpp6
-rw-r--r--src/mongo/db/curop.cpp19
-rw-r--r--src/mongo/db/instance.cpp15
5 files changed, 53 insertions, 2 deletions
diff --git a/jstests/core/profile4.js b/jstests/core/profile4.js
index ed290367811..11f09184713 100644
--- a/jstests/core/profile4.js
+++ b/jstests/core/profile4.js
@@ -157,6 +157,20 @@ try {
assert.eq(lastOp.op, "getmore");
assert.eq(lastOp.ns, coll.getFullName());
+ // getMore entry created by iterating the cursor should have the same format, regardless of
+ // readMode.
+ coll.find().batchSize(3).itcount();
+ lastOp = getLastOp();
+ assert.eq(lastOp.op, "getmore");
+ assert.eq(lastOp.ns, coll.getFullName());
+ assert("getMore" in lastOp.query);
+ assert.eq(lastOp.query.getMore, lastOp.cursorid);
+ assert.eq(lastOp.query.collection, coll.getName());
+ assert.eq(lastOp.query.batchSize, 3)
+ assert.eq(lastOp.cursorExhausted, true)
+ assert.eq(lastOp.nreturned, 2);
+ assert("responseLength" in lastOp);
+
// Ensure that special $-prefixed OP_QUERY options like $hint and $returnKey get added to the
// profiler entry correctly.
coll.find().hint({_id: 1}).itcount();
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index b52da371023..8932a2f6555 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -153,6 +153,7 @@ env.Library(
'$BUILD_DIR/mongo/bson/mutable/mutable_bson',
'$BUILD_DIR/mongo/db/concurrency/lock_manager',
'$BUILD_DIR/mongo/db/service_context',
+ '$BUILD_DIR/mongo/db/query/command_request_response',
'$BUILD_DIR/mongo/util/fail_point',
'$BUILD_DIR/mongo/util/net/network',
'$BUILD_DIR/mongo/util/progress_meter',
diff --git a/src/mongo/db/commands/getmore_cmd.cpp b/src/mongo/db/commands/getmore_cmd.cpp
index eae59f65b17..177f216231e 100644
--- a/src/mongo/db/commands/getmore_cmd.cpp
+++ b/src/mongo/db/commands/getmore_cmd.cpp
@@ -159,6 +159,8 @@ public:
}
const GetMoreRequest& request = parseStatus.getValue();
+ CurOp::get(txn)->debug().cursorid = request.cursorid;
+
// Disable shard version checking - getmore commands are always unversioned
OperationShardVersion::get(txn).setShardVersion(request.nss, ChunkVersion::IGNORED());
@@ -373,6 +375,10 @@ public:
nextBatch.done(respondWithId, request.nss.ns());
+ // Ensure log and profiler include the number of results returned in this getMore's response
+ // batch.
+ CurOp::get(txn)->debug().nreturned = numResults;
+
if (respondWithId) {
cursorFreer.Dismiss();
diff --git a/src/mongo/db/curop.cpp b/src/mongo/db/curop.cpp
index f8a1d52209b..ae939fa0ff8 100644
--- a/src/mongo/db/curop.cpp
+++ b/src/mongo/db/curop.cpp
@@ -37,7 +37,9 @@
#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/util/fail_point_service.h"
#include "mongo/util/log.h"
@@ -121,6 +123,20 @@ 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,
+ ntoreturn,
+ boost::none, // awaitDataTimeout
+ boost::none, // term
+ boost::none // lastKnownCommittedOpTime
+ ).toBSON();
+}
+
} // namespace
/**
@@ -586,6 +602,9 @@ void OpDebug::append(const CurOp& curop,
if (!iscommand && networkOp == dbQuery) {
appendAsObjOrString(
"query", upconvertQueryEntry(query, nss, ntoreturn, ntoskip), maxElementSize, &b);
+ } else if (!iscommand && networkOp == dbGetMore) {
+ appendAsObjOrString(
+ "query", upconvertGetMoreEntry(nss, cursorid, ntoreturn), maxElementSize, &b);
} else if (!query.isEmpty()) {
const char* fieldName = (logicalOp == LogicalOp::opCommand) ? "command" : "query";
appendAsObjOrString(fieldName, query, maxElementSize, &b);
diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp
index c5acf4fc433..1000a132cbb 100644
--- a/src/mongo/db/instance.cpp
+++ b/src/mongo/db/instance.cpp
@@ -215,6 +215,17 @@ void generateLegacyQueryErrorResponse(const AssertionException* exception,
response->setData(msgdata.view2ptr(), true);
}
+/**
+ * Fills out CurOp / OpDebug with basic command info.
+ */
+void beginCommandOp(OperationContext* txn, const NamespaceString& nss, const BSONObj& queryObj) {
+ auto curop = CurOp::get(txn);
+ curop->debug().query = queryObj;
+ stdx::lock_guard<Client> lk(*txn->getClient());
+ curop->setQuery_inlock(queryObj);
+ curop->setNS_inlock(nss.ns());
+}
+
} // namespace
static void receivedCommand(OperationContext* txn,
@@ -238,7 +249,7 @@ static void receivedCommand(OperationContext* txn,
rpc::LegacyRequest request{&message};
// Auth checking for Commands happens later.
int nToReturn = queryMessage.ntoreturn;
- beginQueryOp(txn, nss, queryMessage.query, nToReturn, queryMessage.ntoskip);
+ beginCommandOp(txn, nss, queryMessage.query);
{
stdx::lock_guard<Client> lk(*txn->getClient());
op->markCommand_inlock();
@@ -284,7 +295,7 @@ void receivedRpc(OperationContext* txn, Client& client, DbResponse& dbResponse,
// We construct a legacy $cmd namespace so we can fill in curOp using
// the existing logic that existed for OP_QUERY commands
NamespaceString nss(request.getDatabase(), "$cmd");
- beginQueryOp(txn, nss, request.getCommandArgs(), 1, 0);
+ beginCommandOp(txn, nss, request.getCommandArgs());
{
stdx::lock_guard<Client> lk(*txn->getClient());
curOp->markCommand_inlock();