diff options
author | Sulabh Mahajan <sulabh.mahajan@mongodb.com> | 2022-06-28 16:02:29 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-06-28 16:58:51 +0000 |
commit | e6af52584adbc558cc9b57b18167beb58ee8ce26 (patch) | |
tree | b65b412ede35544d542ca29bbff356f2446a6c20 /src/mongo/db/stats | |
parent | e6b088a0991af9573d6e17b1ee9beb3fe969500d (diff) | |
download | mongo-e6af52584adbc558cc9b57b18167beb58ee8ce26.tar.gz |
SERVER-64535 Add clustered index information to collStats output
Diffstat (limited to 'src/mongo/db/stats')
-rw-r--r-- | src/mongo/db/stats/storage_stats.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/mongo/db/stats/storage_stats.cpp b/src/mongo/db/stats/storage_stats.cpp index 9d239c69ea5..b128bb7958f 100644 --- a/src/mongo/db/stats/storage_stats.cpp +++ b/src/mongo/db/stats/storage_stats.cpp @@ -30,6 +30,7 @@ #include "mongo/platform/basic.h" +#include "mongo/db/catalog/clustered_collection_util.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/database_holder.h" @@ -148,11 +149,29 @@ Status appendCollectionStorageStats(OperationContext* opCtx, } const IndexCatalog* indexCatalog = collection->getIndexCatalog(); - result->append("nindexes", indexCatalog->numIndexesTotal(opCtx)); - BSONObjBuilder indexDetails; std::vector<std::string> indexBuilds; + auto numIndexes = indexCatalog->numIndexesTotal(opCtx); + if (collection->isClustered() && !collection->ns().isTimeseriesBucketsCollection()) { + // There is an implicit 'clustered' index on a clustered collection. Increment the total + // index count to reflect that. + numIndexes++; + + BSONObj collation; + if (auto collator = collection->getDefaultCollator()) { + collation = collator->getSpec().toBSON(); + } + auto clusteredSpec = clustered_util::formatClusterKeyForListIndexes( + collection->getClusteredInfo().get(), collation); + auto indexSpec = collection->getClusteredInfo()->getIndexSpec(); + auto nameOptional = indexSpec.getName(); + // An index name is always expected. + invariant(nameOptional); + indexDetails.append(*nameOptional, clusteredSpec); + } + result->append("nindexes", numIndexes); + auto it = indexCatalog->getIndexIterator( opCtx, IndexCatalog::InclusionPolicy::kReady | IndexCatalog::InclusionPolicy::kUnfinished); while (it->more()) { |