diff options
author | Ted Tuckman <ted.tuckman@mongodb.com> | 2018-10-10 10:15:51 -0400 |
---|---|---|
committer | Ted Tuckman <ted.tuckman@mongodb.com> | 2018-10-10 11:00:43 -0400 |
commit | 549616025c9d471767bc7ede342a9919cb3e6f94 (patch) | |
tree | 81eb64f21ccd81a935d2eb850d5e08194d3f8fb5 | |
parent | 72e12b7765a932da1814cb62cb1b964e1121f696 (diff) | |
download | mongo-549616025c9d471767bc7ede342a9919cb3e6f94.tar.gz |
SERVER-37436 Add fields to idleCursor object in curOp
-rw-r--r-- | jstests/core/currentop_cursors.js | 41 | ||||
-rw-r--r-- | src/mongo/db/pipeline/mongo_process_common.cpp | 13 |
2 files changed, 51 insertions, 3 deletions
diff --git a/jstests/core/currentop_cursors.js b/jstests/core/currentop_cursors.js index f46d7c82f84..66cc3ff267d 100644 --- a/jstests/core/currentop_cursors.js +++ b/jstests/core/currentop_cursors.js @@ -8,6 +8,8 @@ (function() { "use strict"; const coll = db.jstests_currentop_cursors; + // Will skip lsid tests if not in commands read mode. + const commandReadMode = db.getMongo().readMode() == "commands"; load("jstests/libs/fixture_helpers.js"); // for FixtureHelpers @@ -19,8 +21,7 @@ } /** * runTest creates a new collection called jstests_currentop_cursors and then runs the provided - * find - * query. It calls $currentOp and does some basic assertions to make sure idleCursors is + * find query. It calls $currentOp and does some basic assertions to make sure idleCursors is * behaving as intended in each case. * findFunc: A function that runs a find query. Is expected to return a cursorID. * Arbitrary code can be run in findFunc as long as it returns a cursorID. @@ -40,7 +41,7 @@ {$match: {$and: [{type: "idleCursor"}, {"cursor.cursorId": findOut}]}} ]) .toArray(); - assert.eq(result[0].cursor.ns, coll.getFullName(), result); + assert.eq(result[0].ns, coll.getFullName(), result); assert.eq(result[0].cursor.originatingCommand.find, coll.getName(), result); assertFunc(findOut, result); const noIdle = @@ -58,6 +59,7 @@ assert.eq(noIdle.length, 0, tojson(noFlag)); } + // Basic test with default values. runTest({ findFunc: function() { return assert @@ -72,6 +74,12 @@ } else { assert(!result[0].hasOwnProperty("planSummary"), result); } + // Lsid will not exist if not in command read mode. + if (commandReadMode) { + assert(result[0].lsid.hasOwnProperty('id'), result); + assert(result[0].lsid.hasOwnProperty('uid'), result); + } + assert.eq(result[0].host, getHostName(), result); const idleCursor = result[0].cursor; assert.eq(idleCursor.nDocsReturned, 2, result); assert.eq(idleCursor.nBatchesReturned, 1, result); @@ -80,9 +88,14 @@ assert.eq(idleCursor.noCursorTimeout, false, result); assert.eq(idleCursor.originatingCommand.batchSize, 2, result); assert.lte(idleCursor.createdDate, idleCursor.lastAccessDate, result); + // Make sure that the top level fields do not also appear in the cursor subobject. assert(!idleCursor.hasOwnProperty("planSummary"), result); + assert(!idleCursor.hasOwnProperty('host'), result); + assert(!idleCursor.hasOwnProperty('lsid'), result); } }); + + // Test that tailable, awaitData, and noCursorTimeout are set. runTest({ findFunc: function() { return assert @@ -105,6 +118,8 @@ assert.eq(idleCursor.originatingCommand.batchSize, 2, result); } }); + + // Test that dates are set correctly. runTest({ findFunc: function() { return assert @@ -137,6 +152,7 @@ } }); + // Test larger batch size. runTest({ findFunc: function() { return assert @@ -154,6 +170,7 @@ } }); + // Test batchSize and nDocs are incremented correctly. runTest({ findFunc: function() { return assert @@ -220,4 +237,22 @@ } }); } + // Test lsid.id value is correct if in commandReadMode. + if (commandReadMode) { + const session = db.getMongo().startSession(); + runTest({ + findFunc: function() { + const sessionDB = session.getDatabase("test"); + return assert + .commandWorked( + sessionDB.runCommand({find: "jstests_currentop_cursors", batchSize: 2})) + .cursor.id; + }, + assertFunc: function(cursorId, result) { + assert.eq(result.length, 1, result); + assert.eq(session.getSessionId().id, result[0].lsid.id); + } + }); + } + })(); diff --git a/src/mongo/db/pipeline/mongo_process_common.cpp b/src/mongo/db/pipeline/mongo_process_common.cpp index 1c97921e237..ac434ae88e5 100644 --- a/src/mongo/db/pipeline/mongo_process_common.cpp +++ b/src/mongo/db/pipeline/mongo_process_common.cpp @@ -37,6 +37,7 @@ #include "mongo/db/operation_context.h" #include "mongo/db/pipeline/expression_context.h" #include "mongo/db/service_context.h" +#include "mongo/util/net/socket_utils.h" namespace mongo { @@ -79,7 +80,17 @@ std::vector<BSONObj> MongoProcessCommon::getCurrentOps( for (auto&& cursor : getIdleCursors(expCtx, userMode)) { BSONObjBuilder cursorObj; + auto ns = cursor.getNs(); + auto lsid = cursor.getLsid(); cursorObj.append("type", "idleCursor"); + cursorObj.append("host", getHostNameCached()); + cursorObj.append("ns", ns->toString()); + // If in legacy read mode, lsid is not present. + if (lsid) { + cursorObj.append("lsid", lsid->toBSON()); + } + cursor.setNs(boost::none); + cursor.setLsid(boost::none); // On mongos, planSummary is not present. auto planSummaryData = cursor.getPlanSummary(); if (planSummaryData) { @@ -94,6 +105,8 @@ std::vector<BSONObj> MongoProcessCommon::getCurrentOps( cursorObj.append("cursor", cursor.toBSON()); } ops.emplace_back(cursorObj.obj()); + cursor.setNs(ns); + cursor.setLsid(lsid); } } |