src/mongo/db/s/README_range_deleter.md
The config.rangeDeletions collection is a shard-local internal collection containing a document for each range needing to be eventually cleared up; documents in config.rangeDeletions are usually referred as "range deletion tasks" or "range deleter documents".
The complete format of range deletion tasks is defined in range_deletion_tasks.idl, with the relevant fields being the following:
collectioUUID: the UUID of the collection the range belongs torange: the [min, max) shard key range to be deletedpending: boolean flag present if the range is not yet ready for deletionWhen a migration starts, a pending range deletion task is created both on donor and recipient side and such documents are later modified depending on the migration outcome:
pending flag) AND recipient range deletion document deleted.pending flag).The range deleter service is a primary only service living on shards that is driven by the state persisted on config.rangeDeletions: for each collection with at least one range deletion task, the service keeps track in memory of the mapping <collection uuid, [list of ranges containing orphaned documents]>.
Its main functions are:
INITIALIZING state)When a shard node steps up, a thread to asynchronously recover range deletions is spawned (being asynchronous, it does not block step-up); recovery happens in the following steps:
UP state)The range deleter service observer is taking care of keeping in sync the in-memory state with the persistent state by reacting to documents modifications on config.rangeDeletions in the following ways:
DOWN state)When a shard primary steps down, the whole service is destroyed:
The shutdown of the service is structured in the following way in order not to block step-down: