summaryrefslogtreecommitdiff
path: root/src/mongo/db/stats
diff options
context:
space:
mode:
authorSulabh Mahajan <sulabh.mahajan@mongodb.com>2022-06-28 16:02:29 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-06-28 16:58:51 +0000
commite6af52584adbc558cc9b57b18167beb58ee8ce26 (patch)
treeb65b412ede35544d542ca29bbff356f2446a6c20 /src/mongo/db/stats
parente6b088a0991af9573d6e17b1ee9beb3fe969500d (diff)
downloadmongo-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.cpp23
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()) {