[SERVER-74842] `collStats` must never return a negative number of orphans Created: 14/Mar/23  Updated: 29/Oct/23  Resolved: 17/Mar/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.0.0-rc0

Type: Bug Priority: Major - P3
Reporter: Pierlauro Sciarelli Assignee: Silvia Surroca
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Assigned Teams:
Sharding EMEA
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Sharding EMEA 2023-03-20
Participants:
Linked BF Score: 135

 Description   

The BalancerStatsRegistry is a ReplicaSetAwareService so it is only up on primaries; when asking to a secondary the number of orphans, they're retrieved by executing a local query bypassing the checks for non-negativity that are in place when the service is up on primary nodes.

Purpose of this ticket is to return 0 orphaned documents also from secondaries when the tracked number is negative.

Why can the counter be negative?

When a migration is aborted, the counter of orphans tracked in the range deletion task document is missing the number of documents cloned in the last batch because the update (to perform here or here) is skipped due to the error triggering the abort.

Since the range deletion is processed as follows, it may transiently happen to track on disk a negative number of orphaned docs:

while (there are docs in the orphaned range)
-- Delete a batch
-- Decrement the counter on disk (num orphans tracked on disk - num orphaned documents deleted)

This is a self-recovering error that can happen on at most ONE range deletion document at a time. The error is automatically corrected once the range deleter finishes processing potential ranges with wrong counters. And it's quite a rare condition (hopefully there should never be so many aborts).



 Comments   
Comment by Githook User [ 17/Mar/23 ]

Author:

{'name': 'Silvia Surroca', 'email': 'silvia.surroca@mongodb.com', 'username': 'silviasuhu'}

Message: SERVER-74842 collStats must never return a negative number of orphans
Branch: master
https://github.com/mongodb/mongo/commit/31ac033632994d23b081fd40691f9854150c871c

Generated at Thu Feb 08 06:28:40 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.