Skip to content

[Store] Keep serving and moving data while a closing client's segments unmount - #5678

Open
sssqqeer wants to merge 3 commits into
kvcache-ai:mainfrom
sssqqeer:store/graceful-close-keeps-moving
Open

sssqqeer wants to merge 3 commits into
kvcache-ai:mainfrom
sssqqeer:store/graceful-close-keeps-moving

Conversation

@sssqqeer

@sssqqeer sssqqeer commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

Part of RFC #5681 (#1883 Milestone 11, "Migration on Store Exit"), Step 3.

Today, every graceful unmount ties up one of the client's four task workers until the grace period ends. Those same workers run the master's drain and move tasks, so once four segments are unmounting, the client can't move any data off itself until the grace period is over. This PR moves that wait to a separate timer thread. The timer checks with the master once a second. Once the master has removed the segment, the client keeps the memory registered for one more lease TTL, so readers that already looked up the objects can finish, and then releases it.

A client also has no graceful way to shut down. mooncake_client and the Python close() unmount everything at once, so in-flight reads fail and the data is gone before it can be moved. This PR adds --shutdown_grace_seconds to mooncake_client and grace_period_seconds to close(). Both default to 0, which keeps today's behavior. When set, the client gracefully unmounts all of its segments and keeps working as usual (heartbeating, serving reads, running tasks) until every segment is released, at most about 13 s after the grace period ends.

Before this change, four segments unmounting at once took every worker, so a move had to wait for the grace period plus 10 s. Now it runs at the client's next task poll, within about a second. With a 5 s grace period, close() waits about 15 s before it tears down: the 5 s grace period, up to 1 s to notice the removal, and the 10 s lease hold.

Suggested Merge Priority

  • P0 — Urgent: Critical security vulnerability, data loss/corruption, or widespread production outage requiring immediate action
  • P1 — High: Significant correctness or stability issue in existing functionality, or a regression blocking users without a practical workaround
  • P2 — Normal: Routine bug fix, validated performance/compatibility improvement, or new feature for a confirmed use case
  • P3 — Low: Experimental feature, optional enhancement, refactoring, or cleanup with no urgent user impact

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Mooncake Conductor (mooncake-conductor)
  • Reshard (mooncake-reshard)
  • Mooncake EP (mooncake-ep)
  • Mooncake PG (mooncake-pg)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • Common (mooncake-common)
  • Mooncake RL (mooncake-rl)
  • CI/CD
  • Docs
  • Other

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation update
  • Performance improvement
  • Other

How Has This Been Tested?

Tested on Linux (Debug build, TCP).

Test commands:

cd build/mooncake-store/tests
MC_STORE_MEMCPY=0 DEFAULT_KV_LEASE_TTL=1500 ./task_integration_test
./standalone_client_test
./client_integration_test
./pybind_client_test --gtest_filter='*Grace*:*TearDown*:*Teardown*:*Unmount*'

Test results:

  • Unit tests pass
  • Integration tests pass (if applicable)
  • Manual testing done (describe below)

task_integration_test: 10 passed, 2 of them new. standalone_client_test: 8 passed, 1 of them new. client_integration_test: 36 passed. The graceful unmount and teardown cases of pybind_client_test: 9 passed. In GracefulUnmountAllServesMovesAndReturnsOnRemoval, the move is created only after the master reports the source segment as GRACEFULLY_UNMOUNTING, and the client completes it about a second later.

Checklist

  • Every commit I contribute includes my Signed-off-by trailer certifying the DCO
  • I have performed a self-review of my own code
  • I have formatted my code using ./scripts/code_format.sh
  • I have run pre-commit on the files changed in this PR and all hooks pass
  • I have updated the documentation (if applicable)
  • I have added tests to prove my changes are effective
  • For changes >500 LOC: I have filed an RFC issue ([RFC]: [Store] Migration on Store Exit #5681)

AI Assistance Disclosure

  • No AI tools were used
  • AI tools were used (specify below)

…s unmount

A client that gracefully unmounts a segment waits out the grace period on
one of the four task_thread_pool_ workers, which also run drain and move
tasks. With four or more segments unmounting, the client runs no tasks at
all. Graceful unmounts are now watched by a DeadlineScheduler with its own
thread.

The watcher asks the master once a second whether the segment is gone,
from the start of the grace period, so a segment the master removes early
is noticed early. The master drops a segment without waiting for read
leases, so the client still keeps the memory registered for the default
lease TTL (10 s) before it unregisters it and runs the cleanup callback.
For a segment the master removes when its grace period ends, the release
time stays what it was: about grace + 10 s.

Client::GracefulUnmountAllAndWait() gracefully unmounts every mounted
segment and waits until the watcher has released all of them, or until
grace + 10 s + 3 s. RealClient teardown runs this wait while Client is
still up, when a shutdown grace period is set. mooncake_client sets it from
the new --shutdown_grace_seconds flag, and the Python close() takes
grace_period_seconds. Both default to 0, which keeps today's behavior.

EGM segments released this way are skipped by the teardown unmount, so
their memory is freed instead of being retained as unconfirmed.

Signed-off-by: shibin <306219114@qq.com>
A mount that runs during the graceful close lands outside the unmount
snapshot. Teardown now stops new mounts and waits for running ones first.
The local memory check also covers gracefully unmounting segments, which
still hold the objects their drain moves.

Signed-off-by: shibin <306219114@qq.com>
@sssqqeer
sssqqeer force-pushed the store/graceful-close-keeps-moving branch from b0d6d78 to 859db9e Compare November 24, 2026 08:01

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation Integration run-ci size/M 100-1000 changed lines (additions + deletions) Store

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant