summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPol Pinol Castuera <pol.pinol@mongodb.com>2022-11-29 07:58:42 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-11-29 08:32:31 +0000
commite6459ee3049b2bfa1010142394e9d0df290b68ec (patch)
tree98ff2c1c438db6b0d102e0e75ff574230b3fc451
parent7a7330887436349debb5cc0e5d73adae484a7e64 (diff)
downloadmongo-e6459ee3049b2bfa1010142394e9d0df290b68ec.tar.gz
SERVER-68576 Added number of sharded collections to serverStatus command.
-rw-r--r--jstests/sharding/resharding_feature_flagging.js2
-rw-r--r--jstests/sharding/sharding_statistics_server_status.js18
-rw-r--r--src/mongo/db/s/sharding_server_status.cpp11
3 files changed, 30 insertions, 1 deletions
diff --git a/jstests/sharding/resharding_feature_flagging.js b/jstests/sharding/resharding_feature_flagging.js
index 9b48021d526..2195788d56f 100644
--- a/jstests/sharding/resharding_feature_flagging.js
+++ b/jstests/sharding/resharding_feature_flagging.js
@@ -47,7 +47,7 @@ assert.commandFailedWithCode(
const serverStatusCmd = ({serverStatus: 1, shardingStatistics: 1});
let res = assert.commandWorked(configPrimary.adminCommand(serverStatusCmd));
-assert(!res.hasOwnProperty("shardingStatistics"), res.shardingStatistics);
+assert(!res.shardingStatistics.hasOwnProperty("resharding"), res.shardingStatistics);
const shardPrimary = st.shard0.rs.getPrimary();
res = assert.commandWorked(shardPrimary.adminCommand(serverStatusCmd));
diff --git a/jstests/sharding/sharding_statistics_server_status.js b/jstests/sharding/sharding_statistics_server_status.js
index 9e5c08956a0..9dc81bba1a6 100644
--- a/jstests/sharding/sharding_statistics_server_status.js
+++ b/jstests/sharding/sharding_statistics_server_status.js
@@ -64,6 +64,13 @@ function checkServerStatusAbortedMigrationCount(shardConn, count) {
assert.eq(count, shardStats.countDonorMoveChunkAbortConflictingIndexOperation);
}
+function checkServerStatusNumShardedCollections(conn, count) {
+ const shardStats =
+ assert.commandWorked(conn.adminCommand({serverStatus: 1})).shardingStatistics;
+ assert(shardStats.hasOwnProperty("numShardedCollections"));
+ assert.eq(count, shardStats.numShardedCollections);
+}
+
function runConcurrentMoveChunk(host, ns, toShard) {
const mongos = new Mongo(host);
// Helper function to run moveChunk, retrying on ConflictingOperationInProgress. We need to
@@ -129,6 +136,17 @@ st.ensurePrimaryShard(coll.getDB() + "", st.shard0.shardName);
assert.commandWorked(admin.runCommand({shardCollection: coll + "", key: {_id: 1}}));
assert.commandWorked(admin.runCommand({split: coll + "", middle: {_id: 0}}));
+// Check the number of sharded collections.
+const testDB = st.rs0.getPrimary().getDB(dbName);
+const fcvDoc = testDB.adminCommand({getParameter: 1, featureCompatibilityVersion: 1});
+if (MongoRunner.compareBinVersions(fcvDoc.featureCompatibilityVersion.version, '5.0') >= 0) {
+ st.shardColl(dbName + ".coll2", {_id: 1}, false);
+ st.shardColl(dbName + ".coll3", {_id: 1}, false);
+ const configCollections = mongos.getCollection("config.collections");
+ checkServerStatusNumShardedCollections(st.configRS.getPrimary(),
+ configCollections.countDocuments({}));
+}
+
// Move chunk from shard0 to shard1 without docs.
assert.commandWorked(
mongos.adminCommand({moveChunk: coll + '', find: {_id: 1}, to: st.shard1.shardName}));
diff --git a/src/mongo/db/s/sharding_server_status.cpp b/src/mongo/db/s/sharding_server_status.cpp
index 3489612493c..c431ee4a876 100644
--- a/src/mongo/db/s/sharding_server_status.cpp
+++ b/src/mongo/db/s/sharding_server_status.cpp
@@ -31,6 +31,7 @@
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/db/commands/server_status.h"
+#include "mongo/db/db_raii.h"
#include "mongo/db/s/active_migrations_registry.h"
#include "mongo/db/s/collection_sharding_state.h"
#include "mongo/db/s/resharding/resharding_metrics.h"
@@ -122,6 +123,16 @@ public:
->serializeCumulativeOpMetrics(&subObjBuilder);
}
+ // To calculate the number of sharded collection we simply get the number of records from
+ // `config.collections` collection. This count must only be appended when serverStatus is
+ // invoked on the config server.
+ if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) {
+ AutoGetCollectionForRead autoColl(opCtx, CollectionType::ConfigNS);
+ const auto& collection = autoColl.getCollection();
+ const auto numShardedCollections = collection ? collection->numRecords(opCtx) : 0;
+ result.append("numShardedCollections", numShardedCollections);
+ }
+
return result.obj();
}