diff options
author | Gregory Noma <gregory.noma@gmail.com> | 2021-01-12 18:26:18 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-01-13 07:11:59 +0000 |
commit | b196c637c409ab9d84df96fe8f3595cea9e5b6fa (patch) | |
tree | 171215a998d358e63ce465f939bde277d528217f /src/mongo/db/stats | |
parent | 7e7352c8661afdca59ae011d950bf8e0ffddd136 (diff) | |
download | mongo-b196c637c409ab9d84df96fe8f3595cea9e5b6fa.tar.gz |
SERVER-53618 Add collStats for time-series collections
Diffstat (limited to 'src/mongo/db/stats')
-rw-r--r-- | src/mongo/db/stats/SConscript | 2 | ||||
-rw-r--r-- | src/mongo/db/stats/storage_stats.cpp | 30 |
2 files changed, 27 insertions, 5 deletions
diff --git a/src/mongo/db/stats/SConscript b/src/mongo/db/stats/SConscript index 679545ba324..86aa08006f2 100644 --- a/src/mongo/db/stats/SConscript +++ b/src/mongo/db/stats/SConscript @@ -130,7 +130,9 @@ env.Library( 'top', ], LIBDEPS_PRIVATE=[ + '$BUILD_DIR/mongo/db/catalog/database_holder', '$BUILD_DIR/mongo/db/commands/server_status', + '$BUILD_DIR/mongo/db/timeseries/bucket_catalog', ], ) diff --git a/src/mongo/db/stats/storage_stats.cpp b/src/mongo/db/stats/storage_stats.cpp index e7355f42ed4..9927e03e034 100644 --- a/src/mongo/db/stats/storage_stats.cpp +++ b/src/mongo/db/stats/storage_stats.cpp @@ -32,10 +32,13 @@ #include "mongo/platform/basic.h" #include "mongo/db/catalog/collection.h" +#include "mongo/db/catalog/database_holder.h" #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/db_raii.h" #include "mongo/db/index/index_access_method.h" #include "mongo/db/index/index_descriptor.h" +#include "mongo/db/timeseries/bucket_catalog.h" +#include "mongo/db/views/view_catalog.h" #include "mongo/logv2/log.h" #include "mongo/db/stats/storage_stats.h" @@ -59,10 +62,17 @@ Status appendCollectionStorageStats(OperationContext* opCtx, bool verbose = param["verbose"].trueValue(); bool waitForLock = !param.hasField("waitForLock") || param["waitForLock"].trueValue(); + bool isTimeseries = false; + if (auto viewCatalog = DatabaseHolder::get(opCtx)->getViewCatalog(opCtx, nss.db())) { + if (auto viewDef = viewCatalog->lookupWithoutValidatingDurableViews(opCtx, nss.ns())) { + isTimeseries = viewDef->timeseries().has_value(); + } + } + boost::optional<AutoGetCollectionForReadCommand> autoColl; try { autoColl.emplace(opCtx, - nss, + isTimeseries ? nss.makeTimeseriesBucketsNamespace() : nss, AutoGetCollectionViewMode::kViewsForbidden, waitForLock ? Date_t::max() : Date_t::now()); } catch (const ExceptionForCat<ErrorCategory::Interruption>&) { @@ -89,11 +99,21 @@ Status appendCollectionStorageStats(OperationContext* opCtx, long long size = collection->dataSize(opCtx) / scale; result->appendNumber("size", size); - long long numRecords = collection->numRecords(opCtx); - result->appendNumber("count", numRecords); - if (numRecords) - result->append("avgObjSize", collection->averageObjectSize(opCtx)); + long long numRecords = collection->numRecords(opCtx); + if (isTimeseries) { + result->append("bucketsNs", nss.makeTimeseriesBucketsNamespace().ns()); + result->appendNumber("bucketCount", numRecords); + if (numRecords) { + result->append("avgBucketSize", collection->averageObjectSize(opCtx)); + } + BucketCatalog::get(opCtx).appendExecutionStats(nss, result); + } else { + result->appendNumber("count", numRecords); + if (numRecords) { + result->append("avgObjSize", collection->averageObjectSize(opCtx)); + } + } const RecordStore* recordStore = collection->getRecordStore(); auto storageSize = |