diff options
author | Pol Pinol Castuera <pol.pinol@mongodb.com> | 2022-11-29 07:57:44 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-11-29 09:07:08 +0000 |
commit | 48476ee2af534a9efdd238f753ac7e271ec660dd (patch) | |
tree | 65860e1f807889cf8ca911a272b13ff3ba660788 | |
parent | 7090cf539845798a84ee4ac6488faf66783826c2 (diff) | |
download | mongo-48476ee2af534a9efdd238f753ac7e271ec660dd.tar.gz |
SERVER-68576 Added number of sharded collections to serverStatus command.
-rw-r--r-- | jstests/sharding/resharding_abort_command.js | 2 | ||||
-rw-r--r-- | jstests/sharding/resharding_feature_flagging.js | 2 | ||||
-rw-r--r-- | jstests/sharding/resharding_metrics.js | 3 | ||||
-rw-r--r-- | jstests/sharding/sharding_statistics_server_status.js | 18 | ||||
-rw-r--r-- | src/mongo/db/s/sharding_server_status.cpp | 11 |
5 files changed, 32 insertions, 4 deletions
diff --git a/jstests/sharding/resharding_abort_command.js b/jstests/sharding/resharding_abort_command.js index f8e7aeaf9f5..7c5f4a95cb0 100644 --- a/jstests/sharding/resharding_abort_command.js +++ b/jstests/sharding/resharding_abort_command.js @@ -177,7 +177,7 @@ const runAbortWithFailpoint = (failpointName, failpointNodeType, abortLocation, // Resharding has not been attempted yet, so resharding metrics will not be reported. This means // shardingStatistics will be empty, and thus not reported. So we assert that the serverStatus // does not have shardingStatistics yet. - assert(!status.hasOwnProperty('shardingStatistics'), status); + assert(!status.shardingStatistics.hasOwnProperty("resharding"), status); let expectedAbortErrorCodes = ErrorCodes.OK; let expectedReshardingErrorCode = ErrorCodes.ReshardCollectionAborted; diff --git a/jstests/sharding/resharding_feature_flagging.js b/jstests/sharding/resharding_feature_flagging.js index 6e964a2237c..8b023168865 100644 --- a/jstests/sharding/resharding_feature_flagging.js +++ b/jstests/sharding/resharding_feature_flagging.js @@ -46,7 +46,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/resharding_metrics.js b/jstests/sharding/resharding_metrics.js index c4cedb11711..7e1d3a830a2 100644 --- a/jstests/sharding/resharding_metrics.js +++ b/jstests/sharding/resharding_metrics.js @@ -50,8 +50,7 @@ function testMetricsArePresent(mongo, expectedMetrics, minOplogEntriesFetchedAnd function verifyStatsMissing(mongo) { const stats = mongo.getDB('admin').serverStatus({}); - assert(!stats.hasOwnProperty('shardingStatistics') || - !stats.shardingStatistics.hasOwnProperty('resharding'), + assert(!stats.shardingStatistics.hasOwnProperty('resharding'), `Resharding section not expected in ${tojson(stats)}`); } diff --git a/jstests/sharding/sharding_statistics_server_status.js b/jstests/sharding/sharding_statistics_server_status.js index 67e22039403..a9a4f6a273d 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 @@ -132,6 +139,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, '6.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 5a331364032..a6728345834 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" @@ -123,6 +124,16 @@ public: CollectionShardingState::appendInfoForServerStatus(opCtx, &result); } + // 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); + } + // The serverStatus command is run before the FCV is initialized so we ignore it when // checking whether the resharding feature is enabled here. if (resharding::gFeatureFlagResharding.isEnabledAndIgnoreFCV()) { |