Repository navigation
Description
Changes proposed
Summary
Today, when a Mooncake Store node leaves a cluster during scale-down, rolling upgrade, pod eviction, or spot reclamation, graceful unmount keeps its objects readable until the grace period expires and then drops all of them. Later reads miss, and the inference engine has to recompute that KV cache.
This RFC covers Migration on Store Exit from Roadmap #1883 (Milestone 11). Building on the timed-drain and lease-safe move support already in main (#5462, #5485, #5597), we want a leaving node to automatically move its hottest KV blocks to peer nodes during the shutdown grace window, and unmount early once the segment is empty and no longer being read.
The work is split into two phases:
- Phase 1 (Steps 1–4): Four focused PRs that connect the full exit path end to end—all four are already open (#5656, #5655, #5678, #5679).
- Phase 2 (Planned): Follow-up work for faster end-to-end exit throughput, bandwidth pacing and quota/metrics support, and moving drain/exit scheduling out of
MasterServiceinto its own component.
Phase 1 adds no RPC protocol changes, and every new exit behavior is off by default.
Why This Is Needed
In a KV cache, prefix matching stops at the first missing block—losing one block invalidates the rest of the prefix after it. Because of that, losing a single store node causes a much bigger drop in cache hits than its share of cluster memory, especially during rolling upgrades where nodes cycle one after another.
Most cluster schedulers already give a leaving pod a short grace window (for example, 30–60 seconds). Four gaps stop graceful unmount from using that window to save hot KV cache today:
- Graceful unmount does not move data: it only waits for the deadline and drops the segment.
- Drains move objects in arbitrary order: when a drain stops at its deadline, it has moved whichever keys the metadata walk reached first instead of the hot blocks clients are likely to read again.
- A closing client cannot run its own moves: waiting out a graceful unmount can tie up the client's task workers, and neither
mooncake_clientnor Pythonclose()has a grace window that keeps heartbeats, reads, and move execution running until the master removes its segments (#3551). - Full pools stall evacuation: real KV cache pools usually run close to full. When targets have no free space, moves fail allocation without triggering eviction, so hot blocks on the leaving node cannot displace cold blocks elsewhere in the cluster.
Once the basic exit path works, running it reliably at scale also needs faster end-to-end evacuation within short windows, rate limits so migration does not hurt foreground reads, tight-quota handling and metrics, and a cleaner home for drain/exit scheduling outside MasterService.
Scope and Boundaries
- In scope: the end-to-end Store Exit workflow (Phase 1), followed by exit-path throughput & placement, bandwidth pacing / quota / observability, and standalone drain/exit component extraction (Phase 2).
- Out of scope (tracked elsewhere):
- Drain candidate reuse, client task-fetch pacing, and source-client offline recovery (RFC #5621). Short exit windows depend on client fetch pacing, so Phase 2 measures it on the exit path.
- DrainJob recovery across HA failover,
LOCAL_DISKreplica migration during drains, and dynamic hot replication / load balancing (#3388).
Before vs. After
Before: wait out the grace period and drop everything
stateDiagram-v2
direction LR
state "Shutdown · SIGTERM / close()" as Close
state "No evacuation · Workers blocked by timer" as Wait
state "Deadline · Drop all remaining objects" as Drop
[*] --> Close
Close --> Wait: Graceful unmount
Close --> Drop: Immediate unmount
Wait --> Drop: Grace period ends
Drop --> [*]
classDef problem fill:#ffedd5,stroke:#b45309,color:#431407,stroke-width:2px
class Wait,Drop problem
After: evacuate hot blocks during the grace window (Phase 1)
stateDiagram-v2
direction LR
state "Graceful close · Step 3" as Close
state "Timed evacuation · Step 1" as Evac
state "Heat order & spread · Step 2 & 4" as Move
state "Evict cold peers · Step 4" as Evict
state "Unmount early · Empty & lease-safe" as Early
state "Deadline · Drop cold tail" as Timeout
[*] --> Close
Close --> Evac: Reads & heartbeats stay active
Evac --> Move
Move --> Evict: Targets full
Evict --> Move: Space freed
Move --> Early: All allocators empty
Move --> Timeout: Grace deadline
Early --> [*]
Timeout --> [*]
classDef added fill:#dcfce7,stroke:#15803d,color:#14532d,stroke-width:2px
classDef wait fill:#e0f2fe,stroke:#0369a1,color:#0c4a6e,stroke-width:2px
class Close,Evac,Move,Early added
class Evict wait
Phase 1 — Core Store Exit Path
Step 1: Auto-evacuate on graceful unmount (#5656, Open)
- Add a master flag
--evacuate_on_graceful_unmount(defaultfalse). - When it is on and a segment name has no
OKsegment left afterGracefulUnmountSegment, the master starts an internal timed drain whose deadline matches the unmount deadline. - Once every tracked segment under that name has an empty allocator—meaning all replicas have moved and read leases on the old copies have expired—the master unmounts the segment immediately instead of waiting out the full grace period. Anything left at the deadline is dropped, same as today.
Step 2: Move recently read objects first (#5655, Open)
- When a drain cannot finish before its deadline, moving the right blocks matters far more than moving random ones.
- Each scheduling round picks objects that were read after being written first (most recently read first), and unread objects after that (newest first). This reuses existing read-lease timestamps and needs no new metadata fields.
- The ordering logic is self-contained: it sorts the candidate queue that DrainJobs reuse across dispatch rounds (#5661).
To measure the impact, we replayed the Mooncake FAST'25 traces against a real MasterService (10 segments, 1 replica per object, 6,000 warmup requests, 1 segment leaving, then 6,000 evaluation requests). Without evacuation, losing the segment costs 11.3% of hits on conversation and 7.2% on tool-agent. The table shows what share of that loss is recovered:
| Share of leaving segment moved | 5% | 10% | 20% | 50% |
|---|---|---|---|---|
Conversation (main) |
1.2% | 3.4% | 8.0% | 22.3% |
| Conversation (#5655) | 30.4% | 43.2% | 46.9% | 82.6% |
Tool-agent (main) |
1.6% | 2.3% | 6.2% | 17.1% |
| Tool-agent (#5655) | 22.1% | 41.3% | 49.2% | 88.9% |
In this replay the memory pool never fills, so the leaving segment still holds every block written during the run, which covers about 59 minutes of the conversation trace and 31 minutes of the tool-agent trace. When memory holds only a few minutes of blocks, the gain is smaller. With the cache capped at 20–50% of the warmup's distinct blocks and least-recently-used eviction, moving 5% recovers 5.0–23.7% of the lost hits, against 0.7–1.6% for walk order (capped results).
Step 3: Graceful client close and non-blocking unmount wait (#5678, Open)
- Move the client-side graceful unmount wait off the task worker pool onto a separate timer thread, so unmounting multiple segments never starves the move tasks trying to drain them. Once the master removes the segment, the client keeps the memory registered for one more lease TTL so in-flight readers can finish before releasing it.
- Add
--shutdown_grace_seconds(default0) tomooncake_clientandclose(grace_period_seconds=0)(releasing the GIL while waiting) to the Python client. When set, the client gracefully unmounts its segments while keeping heartbeats, read serving, and task execution alive until all segments are released or the grace window plus lease hold elapses.
Step 4: Spread moves across targets and evict when full (#5679, Open)
- Only send an object to a target with enough remaining room, accounting for bytes already in flight to each target so concurrent moves spread across peers instead of piling onto one segment. Objects larger than every target fail right away instead of spending retries.
- If the drain can use any target segment (as in exit evacuation) and no target has room, it waits without spending a retry and triggers eviction the same way a failed write does—trading the coldest blocks in the pool for the hottest blocks on the leaving node. If explicit target segments were specified, or only the segments in the source's fabric can take the object, it does not evict across the whole pool; an object that finds no room there spends a retry each round, as a failed move does today, so the drain still fails instead of waiting forever.
Safety Guarantees (Phase 1)
- Reads do not break on early unmount: a segment is unmounted early only after every tracked allocator is empty, which guarantees all old-copy read leases have expired.
- Unmounting segments stay closed to writes: neither exit evacuation nor a concurrent operator drain can move a
GRACEFULLY_UNMOUNTINGsegment back toOK. - Clean behavior on remounts and existing drains: mounting a new segment under the same name stops the exit evacuation cleanly; if an operator drain is already running for that name, no duplicate job is started.
Phase 2 — Planned Follow-Ups
Once Phase 1 lands, we plan to follow up with benchmark-backed PRs in three areas:
- End-to-end exit throughput & placement: improve evacuation speed inside short shutdown windows across master dispatch responsiveness, client execution concurrency, control/data-path overhead, and target placement. The first PR, #5682, wakes the drain dispatcher as soon as a drain task finishes instead of after a fixed 500 ms sleep, which makes master-side drain dispatch about 40× faster.
- Production controls & observability: add configurable bandwidth pacing (revisiting closed #2875) so migration does not compete with foreground reads, support clean evacuation under tight tenant quotas, and add exit metrics plus Kubernetes / spot deployment guides.
- Standalone drain/exit scheduler component: extract drain and exit scheduling out of
MasterServiceinto a dedicated store sub-module as outlined in #4955 P4.
Validation
- Unit & scenario tests: master lifecycle cases (flag on/off, early unmount after lease expiry, multi-segment names, remount cancellation, coexistence with operator drains), heat-ordering tests under non-zero lease TTL, and full-pool eviction / target-spreading tests.
- Integration tests: multi-client TCP tests verifying that unmounting segments do not starve move workers, and that graceful close keeps running moves and exits early once segments are released.
- Benchmarks: FAST'25 trace replays comparing evacuation off vs. on for single-node exit and rolling upgrades, plus before/after throughput numbers for each Phase 2 PR.
Compatibility
| Option | Where | Default | Default behavior |
|---|---|---|---|
--evacuate_on_graceful_unmount |
mooncake_master |
false |
Graceful unmount does not start evacuation |
--shutdown_grace_seconds |
mooncake_client |
0 |
Unmount immediately on shutdown |
close(grace_period_seconds=0) |
Python MooncakeDistributedStore |
0 |
Close immediately |
Phase 1 requires no wire-protocol or RPC changes.
Open Questions
- Full-pool eviction default (#5679):
#5679currently triggers pool-wide eviction when draining without explicit target segments (including exit evacuation) and does not evict when explicit targets are given or only the source's fabric can take the object (the drain then fails after its retries, as today). Does that default match expectations, or should eviction during drain be gated separately? - Component extraction (Phase 2.3): Does extracting drain/exit scheduling into a dedicated sub-module after the metadata port lands align with
#4955's component-extraction plan?
Tracking Checklist
Phase 1 — Core Store Exit Path
- Step 1: Auto-evacuate on graceful unmount — #5656 (Open)
- Step 2: Move recently read objects first — #5655 (Open)
- Step 3: Graceful client close & non-blocking unmount wait — #5678 (Open)
- Step 4: Capacity-aware spreading & full-pool eviction — #5679 (Open)
Phase 2 — Planned Follow-Ups
- End-to-end exit throughput & placement optimizations — #5682 (Open, wake the drain dispatcher on task completion)
- Bandwidth pacing, tight-quota support, observability & deployment docs
- Standalone drain/exit scheduler component
Before submitting a new issue...
- Make sure you already searched for relevant issues and read the documentation
Activity
github-actions commentedon Nov 19, 2026
Thanks for opening this issue, @sssqqeer!
166484716A maintainer will triage this when possible. To help us respond faster, please include:
Useful links: Documentation · Contributing guide