summaryrefslogtreecommitdiff
path: root/src/mongo/db/stats
diff options
context:
space:
mode:
authorRui Liu <rui.liu@mongodb.com>2021-08-17 13:44:53 +0100
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-10-18 08:02:54 +0000
commit293e6137188554be8b6f777669c9df9cd2f70023 (patch)
tree160e4f642ca1f44d6a659ce4febc1408066fe84c /src/mongo/db/stats
parentf8a7a0ff78762f4e71ed85083b01ca8611ee8085 (diff)
downloadmongo-293e6137188554be8b6f777669c9df9cd2f70023.tar.gz
SERVER-57589 Translate timeseries namespace for collStats command and expand the sharding test case
(cherry picked from commit a69fb9840a42b3e348e4f6e9a5aebddf830f657d)
Diffstat (limited to 'src/mongo/db/stats')
-rw-r--r--src/mongo/db/stats/storage_stats.cpp23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/mongo/db/stats/storage_stats.cpp b/src/mongo/db/stats/storage_stats.cpp
index 6fa79c4ed52..96067384f6a 100644
--- a/src/mongo/db/stats/storage_stats.cpp
+++ b/src/mongo/db/stats/storage_stats.cpp
@@ -53,21 +53,20 @@ Status appendCollectionStorageStats(OperationContext* opCtx,
bool verbose = storageStatsSpec.getVerbose();
bool waitForLock = storageStatsSpec.getWaitForLock();
- bool isTimeseries = false;
- if (auto viewCatalog = DatabaseHolder::get(opCtx)->getViewCatalog(opCtx, nss.db())) {
- if (auto viewDef = viewCatalog->lookupWithoutValidatingDurableViews(opCtx, nss.ns())) {
- isTimeseries = viewDef->timeseries();
- }
- }
+ const auto bucketNss = nss.makeTimeseriesBucketsNamespace();
+ const auto isTimeseries = nss.isTimeseriesBucketsCollection() ||
+ CollectionCatalog::get(opCtx)->lookupCollectionByNamespaceForRead(opCtx, bucketNss);
+ const auto collNss =
+ (isTimeseries && !nss.isTimeseriesBucketsCollection()) ? std::move(bucketNss) : nss;
boost::optional<AutoGetCollectionForReadCommand> autoColl;
try {
autoColl.emplace(opCtx,
- isTimeseries ? nss.makeTimeseriesBucketsNamespace() : nss,
+ collNss,
AutoGetCollectionViewMode::kViewsForbidden,
waitForLock ? Date_t::max() : Date_t::now());
} catch (const ExceptionForCat<ErrorCategory::Interruption>&) {
- LOGV2_DEBUG(3088801, 2, "Failed to retrieve storage statistics", logAttrs(nss));
+ LOGV2_DEBUG(3088801, 2, "Failed to retrieve storage statistics", logAttrs(collNss));
return Status::OK();
}
@@ -83,8 +82,8 @@ Status appendCollectionStorageStats(OperationContext* opCtx,
result->append("indexSizes", BSONObj());
result->append("scaleFactor", scale);
std::string errmsg = !autoColl->getDb()
- ? "Database [" + nss.db().toString() + "] not found."
- : "Collection [" + nss.toString() + "] not found.";
+ ? "Database [" + collNss.db().toString() + "] not found."
+ : "Collection [" + collNss.toString() + "] not found.";
return {ErrorCodes::NamespaceNotFound, errmsg};
}
@@ -94,12 +93,12 @@ Status appendCollectionStorageStats(OperationContext* opCtx,
long long numRecords = collection->numRecords(opCtx);
if (isTimeseries) {
BSONObjBuilder bob(result->subobjStart("timeseries"));
- bob.append("bucketsNs", nss.makeTimeseriesBucketsNamespace().ns());
+ bob.append("bucketsNs", collNss.ns());
bob.appendNumber("bucketCount", numRecords);
if (numRecords) {
bob.append("avgBucketSize", collection->averageObjectSize(opCtx));
}
- BucketCatalog::get(opCtx).appendExecutionStats(nss, &bob);
+ BucketCatalog::get(opCtx).appendExecutionStats(collNss.getTimeseriesViewNamespace(), &bob);
} else {
result->appendNumber("count", numRecords);
if (numRecords) {