<!-- llms-explorer concept facts · https://llms-explorer.com/tree/pinned-balancer-scheduler-cancellation-versus-shard-draining-intent/ · pack 2026-11-02 · ~1363 tokens -->

# Pinned balancer scheduler cancellation versus shard draining intent

> Source-anchored research for Pinned balancer scheduler cancellation versus shard draining intent. Run status: COMPLETED.

Parent: [Shard draining cancellation, status and commit protocol](https://llms-explorer.com/tree/shard-draining-cancellation-status-and-commit-protocol/) · 3 facets · 8 facts · page: https://llms-explorer.com/tree/pinned-balancer-scheduler-cancellation-versus-shard-draining-intent/

## How it works

- When the worker processes _unsubmittedRequestIds in Stopping, it resolves each request with ErrorCodes::BalancerInterrupted and "Request cancelled - balancer scheduler is stopping", erases it from _requests, and clears the unsubmitted list. CommandCanceledIfUnsubmittedBeforeBalancerStops enables pauseSubmissionsFailPoint, queues requestMoveRange, calls stop(), and asserts that exact cancellation result. (medium confidence) — [source](https://raw.githubusercontent.com/mongodb/mongo/603d1d985b3e38b968a9c71753af223440a3565f/src/mongo/db/s/balancer/balancer_commands_scheduler_impl.cpp) · [also](https://raw.githubusercontent.com/mongodb/mongo/603d1d985b3e38b968a9c71753af223440a3565f/src/mongo/db/s/balancer/balancer_commands_scheduler_test.cpp)
- Source-level control-flow inference: The worker can finish submitting the commands it already selected for the current iteration before it observes Stopping on the next iteration. After its loop, it calls executor shutdown() and join(), then clears request bookkeeping and resets the executor. Its block-exit handler sets Stopped and notifies waiters. These are local scheduler and executor lifecycle observations; they do not establish the remote migration outcome. (low confidence) — [source](https://raw.githubusercontent.com/mongodb/mongo/603d1d985b3e38b968a9c71753af223440a3565f/src/mongo/db/s/balancer/balancer_commands_scheduler_impl.cpp)

## Comparisons and alternatives

- requestMoveRange routes through _buildAndEnqueueNewRequest. That helper creates RequestData with a new request UUID, waits under _mutex until _state differs from SchedulerState::Recovering, obtains its outcome future, calls _enqueueRequest, and returns the future. This describes the local incoming-request future path. (low confidence) — [source](https://raw.githubusercontent.com/mongodb/mongo/603d1d985b3e38b968a9c71753af223440a3565f/src/mongo/db/s/balancer/balancer_commands_scheduler_impl.cpp)
- CommandFailsWhenNetworkReturnsError supplies a mocked ErrorCodes::NetworkTimeout response and asserts that requestMoveRange returns that same status. The implementation returns a non-OK remoteResponse.status through processRemoteResponse. This fixture asserts error propagation rather than migration cancellation. (medium confidence) — [source](https://raw.githubusercontent.com/mongodb/mongo/603d1d985b3e38b968a9c71753af223440a3565f/src/mongo/db/s/balancer/balancer_commands_scheduler_test.cpp) · [also](https://raw.githubusercontent.com/mongodb/mongo/603d1d985b3e38b968a9c71753af223440a3565f/src/mongo/db/s/balancer/balancer_commands_scheduler_impl.cpp)

## Facts and statements

- The scheduler interface describes asynchronous submission of chunk-related commands and documents stop() as stopping processing of outstanding and incoming requests, resolving them as cancelled. This is a scheduler request contract. (low confidence) — [source](https://raw.githubusercontent.com/mongodb/mongo/603d1d985b3e38b968a9c71753af223440a3565f/src/mongo/db/s/balancer/balancer_commands_scheduler.h)
- In _enqueueRequest, only Recovering and Running accept requests; the other states reject them with ErrorCodes::BalancerInterrupted and the message "Request rejected - balancer scheduler is stopped". The CommandFailsWhenSchedulerIsStopped fixture asserts this result for requestMoveRange without starting the scheduler. Thus the rejection branch also covers Stopping even though its message says stopped. (medium confidence) — [source](https://raw.githubusercontent.com/mongodb/mongo/603d1d985b3e38b968a9c71753af223440a3565f/src/mongo/db/s/balancer/balancer_commands_scheduler_impl.cpp) · [also](https://raw.githubusercontent.com/mongodb/mongo/603d1d985b3e38b968a9c71753af223440a3565f/src/mongo/db/s/balancer/balancer_commands_scheduler_test.cpp)
- The cancellation fixture deliberately pauses submissions before issuing its move request and stops the scheduler before checking the returned future. Its helper defines mocked remote command responses. The stopShardDraining command reference describes telling the balancer to retain the shard and include it again in rebalancing. Scope inference: this fixture asserts cancellation of an unsubmitted request; that assertion does not establish that stopShardDraining interrupts an already-running shard migration before returning. (low confidence) — [source](https://raw.githubusercontent.com/mongodb/mongo/603d1d985b3e38b968a9c71753af223440a3565f/src/mongo/db/s/balancer/balancer_commands_scheduler_test.cpp) · [also](https://www.mongodb.com/docs/manual/reference/command/stopShardDraining.md)
- stop() returns immediately if the scheduler is already Stopped. Otherwise it requires a joinable worker, sets Stopping under _mutex, notifies _stateUpdatedCV, releases the lock, and joins _workerThreadHandle. (low confidence) — [source](https://raw.githubusercontent.com/mongodb/mongo/603d1d985b3e38b968a9c71753af223440a3565f/src/mongo/db/s/balancer/balancer_commands_scheduler_impl.cpp)
