diff options
-rw-r--r-- | jstests/sharding/resharding_feature_flagging.js | 2 | ||||
-rw-r--r-- | jstests/sharding/sharding_statistics_server_status.js | 18 | ||||
-rw-r--r-- | src/mongo/db/s/sharding_server_status.cpp | 11 |
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(); } |