summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/balancer_stats_registry.cpp
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
commit4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch)
tree1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/db/s/balancer_stats_registry.cpp
parentaa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff)
parent8f0827553e09872941945a093b647a4211a9db7f (diff)
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0' with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/db/s/balancer_stats_registry.cpp')
-rw-r--r--src/mongo/db/s/balancer_stats_registry.cpp63
1 files changed, 9 insertions, 54 deletions
diff --git a/src/mongo/db/s/balancer_stats_registry.cpp b/src/mongo/db/s/balancer_stats_registry.cpp
index 0d262b2c299..0d664c0762c 100644
--- a/src/mongo/db/s/balancer_stats_registry.cpp
+++ b/src/mongo/db/s/balancer_stats_registry.cpp
@@ -31,7 +31,6 @@
#include "mongo/db/s/balancer_stats_registry.h"
-#include "mongo/db/catalog_raii.h"
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/pipeline/aggregate_command_gen.h"
#include "mongo/db/repl/replication_coordinator.h"
@@ -115,12 +114,9 @@ void BalancerStatsRegistry::initializeAsync(OperationContext* opCtx) {
LOGV2_DEBUG(6419601, 2, "Initializing BalancerStatsRegistry");
try {
- // Lock the range deleter to prevent concurrent modifications of orphans count
- ScopedRangeDeleterLock rangeDeleterLock(opCtx, LockMode::MODE_S);
- // The collection lock is needed to serialize with direct writes to
- // config.rangeDeletions
- AutoGetCollection rangeDeletionLock(
- opCtx, NamespaceString::kRangeDeletionNamespace, MODE_S);
+ // Lock the range deleter to prevent
+ // concurrent modifications of orphans count
+ ScopedRangeDeleterLock rangeDeleterLock(opCtx);
// Load current ophans count from disk
_loadOrphansCount(opCtx);
LOGV2_DEBUG(6419602, 2, "Completed BalancerStatsRegistry initialization");
@@ -180,41 +176,6 @@ long long BalancerStatsRegistry::getCollNumOrphanDocs(const UUID& collectionUUID
return 0;
}
-long long BalancerStatsRegistry::getCollNumOrphanDocsFromDiskIfNeeded(
- OperationContext* opCtx, const UUID& collectionUUID) const {
- try {
- return getCollNumOrphanDocs(collectionUUID);
- } catch (const ExceptionFor<ErrorCodes::NotYetInitialized>&) {
- // Since the registry is not initialized, run an aggregation to get the number of orphans
- DBDirectClient client(opCtx);
- std::vector<BSONObj> pipeline;
- pipeline.push_back(
- BSON("$match" << BSON(RangeDeletionTask::kCollectionUuidFieldName << collectionUUID)));
- pipeline.push_back(
- BSON("$group" << BSON("_id"
- << "numOrphans"
- << "count"
- << BSON("$sum"
- << "$" + RangeDeletionTask::kNumOrphanDocsFieldName))));
- 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();
- }
-}
-
-
void BalancerStatsRegistry::onRangeDeletionTaskInsertion(const UUID& collectionUUID,
long long numOrphanDocs) {
if (!_isInitialized())
@@ -234,8 +195,7 @@ void BalancerStatsRegistry::onRangeDeletionTaskDeletion(const UUID& collectionUU
stdx::lock_guard lk{_mutex};
auto collStatsIt = _collStatsMap.find(collectionUUID);
if (collStatsIt == _collStatsMap.end()) {
- LOGV2_DEBUG(6419612,
- 1,
+ LOGV2_ERROR(6419612,
"Couldn't find cached range deletion tasks count during decrese attempt",
"collectionUUID"_attr = collectionUUID,
"numOrphanDocs"_attr = numOrphanDocs);
@@ -248,8 +208,7 @@ void BalancerStatsRegistry::onRangeDeletionTaskDeletion(const UUID& collectionUU
if (stats.numRangeDeletionTasks <= 0) {
if (MONGO_unlikely(stats.numRangeDeletionTasks < 0)) {
- LOGV2_DEBUG(6419613,
- 1,
+ LOGV2_ERROR(6419613,
"Cached count of range deletion tasks became negative. Resetting it to 0",
"collectionUUID"_attr = collectionUUID,
"numRangeDeletionTasks"_attr = stats.numRangeDeletionTasks,
@@ -284,12 +243,9 @@ void BalancerStatsRegistry::updateOrphansCount(const UUID& collectionUUID, long
stats.numOrphanDocs += delta;
if (stats.numOrphanDocs < 0) {
- // This could happen in case of direct manipulation of range deletion tasks documents or
- // direct writes into orphaned ranges, but also in some other benign situations.
- // numOrphanDocs is a best-effort counter, miscounting or even being negative in some
- // scenarios is expected.
- LOGV2_DEBUG(6419611,
- 1,
+ // This should happen only in case of direct manipulation of range deletion tasks
+ // documents or direct writes into orphaned ranges
+ LOGV2_ERROR(6419611,
"Cached orphan documents count became negative, resetting it to 0",
"collectionUUID"_attr = collectionUUID,
"numOrphanDocs"_attr = stats.numOrphanDocs,
@@ -337,8 +293,7 @@ void BalancerStatsRegistry::_loadOrphansCount(OperationContext* opCtx) {
auto numRangeDeletionTasks = collObj[kNumRangeDeletionTasksLabel].exactNumberLong();
invariant(numRangeDeletionTasks > 0);
if (orphanCount < 0) {
- LOGV2_DEBUG(6419621,
- 1,
+ LOGV2_ERROR(6419621,
"Found negative orphan count in range deletion task documents",
"collectionUUID"_attr = collUUID,
"numOrphanDocs"_attr = orphanCount,