summaryrefslogtreecommitdiff
path: root/src/mongo/db/stats
diff options
context:
space:
mode:
authorAllison Easton <allison.easton@mongodb.com>2022-05-31 07:03:59 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-05-31 07:33:10 +0000
commit2a7a609a78eb12dd5a237933b49b5f6bd03043f2 (patch)
treee6ca4f3716eaeef3a35c7f44ab694a6622b6c403 /src/mongo/db/stats
parent6220cd6acadf334edee5168e4729c79c85327345 (diff)
downloadmongo-2a7a609a78eb12dd5a237933b49b5f6bd03043f2.tar.gz
SERVER-64242 Make `collStats` aggregation stage retrieve orphans from BalancerStatisticsRegistry
Diffstat (limited to 'src/mongo/db/stats')
-rw-r--r--src/mongo/db/stats/SConscript2
-rw-r--r--src/mongo/db/stats/storage_stats.cpp39
2 files changed, 5 insertions, 36 deletions
diff --git a/src/mongo/db/stats/SConscript b/src/mongo/db/stats/SConscript
index 4769af29bea..524f8d897cb 100644
--- a/src/mongo/db/stats/SConscript
+++ b/src/mongo/db/stats/SConscript
@@ -126,9 +126,7 @@ env.Library(
'$BUILD_DIR/mongo/db/catalog/index_catalog',
'$BUILD_DIR/mongo/db/commands/server_status',
'$BUILD_DIR/mongo/db/db_raii',
- '$BUILD_DIR/mongo/db/dbdirectclient', # TODO (SERVER-64162) remove
'$BUILD_DIR/mongo/db/index/index_access_method',
- '$BUILD_DIR/mongo/db/pipeline/aggregation_request_helper', # TODO (SERVER-64162) remove
'$BUILD_DIR/mongo/db/pipeline/document_sources_idl',
'$BUILD_DIR/mongo/db/timeseries/bucket_catalog',
'$BUILD_DIR/mongo/db/timeseries/timeseries_stats',
diff --git a/src/mongo/db/stats/storage_stats.cpp b/src/mongo/db/stats/storage_stats.cpp
index 1bac7d233ae..8e3252e61b8 100644
--- a/src/mongo/db/stats/storage_stats.cpp
+++ b/src/mongo/db/stats/storage_stats.cpp
@@ -35,10 +35,9 @@
#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/catalog/index_catalog.h"
#include "mongo/db/db_raii.h"
-#include "mongo/db/dbdirectclient.h" // TODO (SERVER-64162) remove
#include "mongo/db/index/index_access_method.h"
#include "mongo/db/index/index_descriptor.h"
-#include "mongo/db/pipeline/aggregate_command_gen.h" // TODO (SERVER-64162) remove
+#include "mongo/db/s/balancer_stats_registry.h"
#include "mongo/db/timeseries/bucket_catalog.h"
#include "mongo/db/timeseries/timeseries_stats.h"
#include "mongo/logv2/log.h"
@@ -51,36 +50,6 @@
namespace mongo {
-namespace {
-long long countOrphanDocsForCollection(OperationContext* opCtx, const UUID& uuid) {
- // TODO (SERVER-64162): move this function to range_deletion_util.cpp and replace
- // "collectionUuid" and "numOrphanDocs" with RangeDeletionTask field names.
- DBDirectClient client(opCtx);
- std::vector<BSONObj> pipeline;
- pipeline.push_back(BSON("$match" << BSON("collectionUuid" << uuid)));
- pipeline.push_back(BSON("$group" << BSON("_id"
- << "numOrphans"
- << "count"
- << BSON("$sum"
- << "$numOrphanDocs"))));
- AggregateCommandRequest aggRequest(NamespaceString::kRangeDeletionNamespace, pipeline);
- auto swCursor = DBClientCursor::fromAggregationRequest(
- &client, aggRequest, false /* secondaryOk */, true /* useExhaust */);
- if (!swCursor.isOK()) {
- return 0;
- }
- auto cursor = std::move(swCursor.getValue());
- if (!cursor->more()) {
- return 0;
- }
- auto res = cursor->nextSafe();
- invariant(!cursor->more());
- auto numOrphans = res.getField("count");
- invariant(numOrphans);
- return numOrphans.exactNumberLong();
-}
-} // namespace
-
Status appendCollectionStorageStats(OperationContext* opCtx,
const NamespaceString& nss,
const StorageStatsSpec& storageStatsSpec,
@@ -147,8 +116,10 @@ Status appendCollectionStorageStats(OperationContext* opCtx,
if (serverGlobalParams.featureCompatibility.isVersionInitialized() &&
feature_flags::gOrphanTracking.isEnabled(serverGlobalParams.featureCompatibility)) {
- result->appendNumber(kOrphanCountField,
- countOrphanDocsForCollection(opCtx, collection->uuid()));
+ result->appendNumber(
+ kOrphanCountField,
+ BalancerStatsRegistry::get(opCtx)->getCollNumOrphanDocsFromDiskIfNeeded(
+ opCtx, collection->uuid()));
}
const RecordStore* recordStore = collection->getRecordStore();