diff options
author | Louis Williams <louis.williams@mongodb.com> | 2022-02-14 12:26:02 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-02-14 13:18:26 +0000 |
commit | 5821087022c74d30750f0adcc366871f33af5dc9 (patch) | |
tree | a0754d2149280bc4a6c13441f740d0077f19f83e | |
parent | b180b4d36109cdb70fc5aa2547807eca9ce64175 (diff) | |
download | mongo-5821087022c74d30750f0adcc366871f33af5dc9.tar.gz |
SERVER-63576 Add clustered collection statistics to catalogStats
-rw-r--r-- | jstests/noPassthrough/server_status_catalog_stats.js | 26 | ||||
-rw-r--r-- | src/mongo/db/catalog/catalog_stats.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/catalog/collection_catalog.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/catalog/collection_catalog.h | 2 | ||||
-rw-r--r-- | src/mongo/db/catalog/collection_mock.h | 2 |
5 files changed, 31 insertions, 8 deletions
diff --git a/jstests/noPassthrough/server_status_catalog_stats.js b/jstests/noPassthrough/server_status_catalog_stats.js index 672dc62ea8c..af17cd8cc21 100644 --- a/jstests/noPassthrough/server_status_catalog_stats.js +++ b/jstests/noPassthrough/server_status_catalog_stats.js @@ -24,6 +24,7 @@ let internalCollectionsAtStart; let internalViewsAtStart; assertCatalogStats(db1, (stats) => { assert.eq(0, stats.capped); + assert.eq(0, stats.clustered); assert.eq(0, stats.collections); assert.eq(0, stats.timeseries); assert.eq(0, stats.views); @@ -33,15 +34,18 @@ assertCatalogStats(db1, (stats) => { assert.commandWorked(db1.coll.insert({a: 1})); assert.commandWorked(db1.createCollection('capped', {capped: true, size: 1024})); +assert.commandWorked( + db1.createCollection('clustered', {clusteredIndex: {unique: true, key: {_id: 1}}})); assert.commandWorked(db1.createCollection('view', {viewOn: 'coll', pipeline: []})); assert.commandWorked(db1.createCollection('ts', {timeseries: {timeField: 't'}})); assertCatalogStats(db1, (stats) => { assert.eq(1, stats.capped); - assert.eq(2, stats.collections); + assert.eq(1, stats.clustered); + assert.eq(3, stats.collections); assert.eq(1, stats.timeseries); assert.eq(1, stats.views); - // An system.views and system.buckets collection should have been created. + // A system.views and system.buckets collection should have been created. assert.eq(internalCollectionsAtStart + 2, stats.internalCollections); assert.eq(internalViewsAtStart, stats.internalViews); }); @@ -50,7 +54,8 @@ assertCatalogStats(db1, (stats) => { assert.commandWorked(db1.runCommand({collMod: 'view', pipeline: [{$match: {a: 1}}]})); assertCatalogStats(db1, (stats) => { assert.eq(1, stats.capped); - assert.eq(2, stats.collections); + assert.eq(1, stats.clustered); + assert.eq(3, stats.collections); assert.eq(1, stats.timeseries); assert.eq(1, stats.views); // An system.views and system.buckets collection should have been created. @@ -60,12 +65,15 @@ assertCatalogStats(db1, (stats) => { assert.commandWorked(db2.coll.insert({a: 1})); assert.commandWorked(db2.createCollection('capped', {capped: true, size: 1024})); +assert.commandWorked( + db2.createCollection('clustered', {clusteredIndex: {unique: true, key: {_id: 1}}})); assert.commandWorked(db2.createCollection('view', {viewOn: 'coll', pipeline: []})); assert.commandWorked(db2.createCollection('ts', {timeseries: {timeField: 't'}})); assertCatalogStats(db1, (stats) => { assert.eq(2, stats.capped); - assert.eq(4, stats.collections); + assert.eq(2, stats.clustered); + assert.eq(6, stats.collections); assert.eq(2, stats.timeseries); assert.eq(2, stats.views); // An system.views and system.buckets collection should have been created. @@ -82,7 +90,8 @@ db2 = primary.getDB('db2'); // Ensure stats are the same after restart. assertCatalogStats(db1, (stats) => { assert.eq(2, stats.capped); - assert.eq(4, stats.collections); + assert.eq(2, stats.clustered); + assert.eq(6, stats.collections); assert.eq(2, stats.timeseries); assert.eq(2, stats.views); assert.eq(internalCollectionsAtStart + 4, stats.internalCollections); @@ -91,12 +100,14 @@ assertCatalogStats(db1, (stats) => { assert(db1.coll.drop()); assert(db1.capped.drop()); +assert(db1.clustered.drop()); assert(db1.view.drop()); assert(db1.ts.drop()); assertCatalogStats(db1, (stats) => { assert.eq(1, stats.capped); - assert.eq(2, stats.collections); + assert.eq(1, stats.clustered); + assert.eq(3, stats.collections); assert.eq(1, stats.timeseries); assert.eq(1, stats.views); // The system.views collection will stick around @@ -108,7 +119,7 @@ db1.dropDatabase(); assertCatalogStats(db1, (stats) => { assert.eq(1, stats.capped); - assert.eq(2, stats.collections); + assert.eq(3, stats.collections); assert.eq(1, stats.timeseries); assert.eq(1, stats.views); // The system.views collection should be dropped @@ -120,6 +131,7 @@ db2.dropDatabase(); assertCatalogStats(db1, (stats) => { assert.eq(0, stats.capped); + assert.eq(0, stats.clustered); assert.eq(0, stats.collections); assert.eq(0, stats.timeseries); assert.eq(0, stats.views); diff --git a/src/mongo/db/catalog/catalog_stats.cpp b/src/mongo/db/catalog/catalog_stats.cpp index 79d5ed0dfd2..f79f354a773 100644 --- a/src/mongo/db/catalog/catalog_stats.cpp +++ b/src/mongo/db/catalog/catalog_stats.cpp @@ -54,6 +54,7 @@ public: struct Stats { int collections = 0; int capped = 0; + int clustered = 0; int views = 0; int timeseries = 0; int internalCollections = 0; @@ -62,6 +63,7 @@ public: void toBson(BSONObjBuilder* builder) const { builder->append("collections", collections); builder->append("capped", capped); + builder->append("clustered", clustered); builder->append("timeseries", timeseries); builder->append("views", views); builder->append("internalCollections", internalCollections); @@ -77,6 +79,7 @@ public: const auto catalogStats = catalog->getStats(); stats.collections = catalogStats.userCollections; stats.capped = catalogStats.userCapped; + stats.clustered = catalogStats.userClustered; stats.internalCollections = catalogStats.internal; const auto viewCatalogDbNames = catalog->getViewCatalogDbNames(); diff --git a/src/mongo/db/catalog/collection_catalog.cpp b/src/mongo/db/catalog/collection_catalog.cpp index ebfcbc41501..7901809f2ca 100644 --- a/src/mongo/db/catalog/collection_catalog.cpp +++ b/src/mongo/db/catalog/collection_catalog.cpp @@ -999,6 +999,9 @@ void CollectionCatalog::registerCollection(OperationContext* opCtx, if (coll->isCapped()) { _stats.userCapped += 1; } + if (coll->isClustered()) { + _stats.userClustered += 1; + } } else { _stats.internal += 1; } @@ -1037,6 +1040,9 @@ std::shared_ptr<Collection> CollectionCatalog::deregisterCollection(OperationCon if (coll->isCapped()) { _stats.userCapped -= 1; } + if (coll->isClustered()) { + _stats.userClustered -= 1; + } } else { _stats.internal -= 1; } diff --git a/src/mongo/db/catalog/collection_catalog.h b/src/mongo/db/catalog/collection_catalog.h index cf865a0ce2d..f8ec0db2533 100644 --- a/src/mongo/db/catalog/collection_catalog.h +++ b/src/mongo/db/catalog/collection_catalog.h @@ -353,6 +353,8 @@ public: int userCollections = 0; // Non-system capped collections on non-internal databases int userCapped = 0; + // Non-system clustered collection on non-internal databases. + int userClustered = 0; // System collections or collections on internal databases int internal = 0; }; diff --git a/src/mongo/db/catalog/collection_mock.h b/src/mongo/db/catalog/collection_mock.h index 00711f95cfc..aeaf4798afd 100644 --- a/src/mongo/db/catalog/collection_mock.h +++ b/src/mongo/db/catalog/collection_mock.h @@ -257,7 +257,7 @@ public: } bool isClustered() const { - std::abort(); + return false; } boost::optional<ClusteredCollectionInfo> getClusteredInfo() const { |