diff options
Diffstat (limited to 'src/mongo/db/s/balancer_stats_registry.h')
| -rw-r--r-- | src/mongo/db/s/balancer_stats_registry.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/mongo/db/s/balancer_stats_registry.h b/src/mongo/db/s/balancer_stats_registry.h index 6dcfae68609..e35ae419539 100644 --- a/src/mongo/db/s/balancer_stats_registry.h +++ b/src/mongo/db/s/balancer_stats_registry.h @@ -29,6 +29,7 @@ #pragma once +#include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/operation_context.h" #include "mongo/db/repl/replica_set_aware_service.h" #include "mongo/util/concurrency/thread_pool.h" @@ -37,6 +38,22 @@ namespace mongo { /** + * Scoped lock to synchronize with the execution of range deletions. + * The range-deleter acquires a scoped lock in IX mode while orphans are being deleted. + * Acquiring the scoped lock in MODE_X ensures that no orphan counter in `config.rangeDeletions` + * entries is going to be updated concurrently. + */ +class ScopedRangeDeleterLock { +public: + ScopedRangeDeleterLock(OperationContext* opCtx, LockMode mode) + : _resourceLock(opCtx, opCtx->lockState(), _mutex.getRid(), mode) {} + +private: + const Lock::ResourceLock _resourceLock; + static inline const Lock::ResourceMutex _mutex{"ScopedRangeDeleterLock"}; +}; + +/** * The BalancerStatsRegistry is used to cache metadata on shards, such as the orphan documents * count. The blancer (on the config sever) periodically fetches this metadata through the * _shardsvrGetStatsForBalancing command and uses it to evaluate balancing status of collections. @@ -78,6 +95,13 @@ public: long long getCollNumOrphanDocs(const UUID& collectionUUID) const; + /** + * Retrieves the numOrphanDocs from the balancer stats registry if initialized or runs an + * aggregation on disk if not. + */ + long long getCollNumOrphanDocsFromDiskIfNeeded(OperationContext* opCtx, + const UUID& collectionUUID) const; + private: void onInitialDataAvailable(OperationContext* opCtx, bool isMajorityDataAvailable) override final {} |
