summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYunhe (John) Wang <yunhe.wang@mongodb.com>2015-09-25 13:40:15 -0400
committerYunhe (John) Wang <yunhe.wang@mongodb.com>2015-09-29 09:37:18 -0400
commita6de657e2f19b9eb361a74099efbc9f68eb639e8 (patch)
tree0aec91e0f38f4748b938a0ccec857255317bc66c
parent71f8e081c466218f16de3c99f5c0eb993b80c720 (diff)
downloadmongo-a6de657e2f19b9eb361a74099efbc9f68eb639e8.tar.gz
SERVER-19405 serverStatus now has mongos cursor stats
-rw-r--r--jstests/sharding/auto2.js4
-rw-r--r--jstests/sharding/cursor_cleanup.js6
-rw-r--r--src/mongo/s/SConscript1
-rw-r--r--src/mongo/s/cluster_cursor_stats.cpp58
-rw-r--r--src/mongo/s/cursors.cpp8
5 files changed, 63 insertions, 14 deletions
diff --git a/jstests/sharding/auto2.js b/jstests/sharding/auto2.js
index ff4c44b2b4f..0a869884b1d 100644
--- a/jstests/sharding/auto2.js
+++ b/jstests/sharding/auto2.js
@@ -118,7 +118,7 @@ for ( i =0; i<100; i++ )
t.save( { _id : i } );
for ( i=0; i<100; i++ ){
t.find().batchSize( 2 ).next();
- // TODO: Re-eneble when SERVER-19405 is imlpemented.
+ // TODO: Re-enable when SERVER-20194 is implemented.
//assert.lt(0 , db.serverStatus().metrics.cursor.open.total, "cursor1");
gc();
}
@@ -126,7 +126,7 @@ for ( i=0; i<100; i++ ){
for ( i=0; i<100; i++ ){
gc();
}
-// TODO: Re-enable when SERVER-19405 is implemented.
+// TODO: Re-enable when SERVER-20194 is implemented.
//assert.eq(0, db.serverStatus().metrics.cursor.open.total, "cursor2");
// Stop the balancer, otherwise it may grab some connections from the pool for itself
diff --git a/jstests/sharding/cursor_cleanup.js b/jstests/sharding/cursor_cleanup.js
index cf2810b38f2..9e345a94223 100644
--- a/jstests/sharding/cursor_cleanup.js
+++ b/jstests/sharding/cursor_cleanup.js
@@ -46,8 +46,7 @@ jsTest.log("Check whether the cursor is registered in the cursor info.");
var cursorInfo = admin.serverStatus().metrics.cursor;
printjson(cursorInfo);
-// TODO: Re-enable when SERVER-19405 is implemented.
-//assert.eq(cursorInfo.open.multiTarget, 1);
+assert.eq(cursorInfo.open.multiTarget, 1);
jsTest.log("End the cursors.");
@@ -57,8 +56,7 @@ unshardedCursor.itcount();
var cursorInfo = admin.serverStatus().metrics.cursor;;
printjson(cursorInfo);
-// TODO: Re-enable when SERVER-19405 is implemented.
-//assert.eq(cursorInfo.open.multiTarget, 0);
+assert.eq(cursorInfo.open.multiTarget, 0);
jsTest.log("DONE!");
diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript
index 83bffd1f055..821ce644be6 100644
--- a/src/mongo/s/SConscript
+++ b/src/mongo/s/SConscript
@@ -158,6 +158,7 @@ env.Library(
target='mongoscore',
source=[
'balance.cpp',
+ 'cluster_cursor_stats.cpp',
'cluster_last_error_info.cpp',
'cursors.cpp',
'request.cpp',
diff --git a/src/mongo/s/cluster_cursor_stats.cpp b/src/mongo/s/cluster_cursor_stats.cpp
new file mode 100644
index 00000000000..cdf3f46ab4d
--- /dev/null
+++ b/src/mongo/s/cluster_cursor_stats.cpp
@@ -0,0 +1,58 @@
+/**
+ * Copyright (C) 2015 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/db/commands/server_status_metric.h"
+#include "mongo/s/grid.h"
+
+namespace mongo {
+namespace {
+
+//
+// ServerStatus metric cursor counts.
+//
+
+class ClusterCursorStats final : public ServerStatusMetric {
+public:
+ ClusterCursorStats() : ServerStatusMetric("cursor.open") {}
+
+ void appendAtLeaf(BSONObjBuilder& b) const final {
+ BSONObjBuilder openBob(b.subobjStart(_leafName));
+ auto stats = grid.getCursorManager()->stats();
+
+ openBob.append("multiTarget", static_cast<long long>(stats.cursorsSharded));
+ openBob.append("singleTarget", static_cast<long long>(stats.cursorsNotSharded));
+ openBob.append("total",
+ static_cast<long long>(stats.cursorsSharded + stats.cursorsNotSharded));
+ openBob.done();
+ }
+} clusterCursorStats;
+
+} // namespace
+} // namespace mongo
diff --git a/src/mongo/s/cursors.cpp b/src/mongo/s/cursors.cpp
index e896453f54c..f96ad4658d0 100644
--- a/src/mongo/s/cursors.cpp
+++ b/src/mongo/s/cursors.cpp
@@ -78,14 +78,6 @@ public:
static CursorStatsSum cursorStatsTotalOpen;
-static ServerStatusMetricField<Counter64> dCursorStatsMultiTarget("cursor.open.multiTarget",
- &cursorStatsMultiTarget);
-static ServerStatusMetricField<Counter64> dCursorStatsSingleTarget("cursor.open.singleTarget",
- &cursorStatsSingleTarget);
-static ServerStatusMetricField<CursorStatsSum> dCursorStatsTotalOpen("cursor.open.total",
- &cursorStatsTotalOpen);
-
-
// -------- ShardedCursor -----------
ShardedClientCursor::ShardedClientCursor(QueryMessage& q, ParallelSortClusteredCursor* cursor) {