Skip to content

[Store] Fix snapshot restore deadlock for unready segments - #4022

Open
waizuichougou wants to merge 1 commit into
kvcache-ai:mainfrom
waizuichougou:fix/snapshot-restore-deadlock
Open

[Store] Fix snapshot restore deadlock for unready segments#4022
waizuichougou wants to merge 1 commit into
kvcache-ai:mainfrom
waizuichougou:fix/snapshot-restore-deadlock

Conversation

@waizuichougou

Copy link
Copy Markdown
Contributor

Description

MasterService::ApplySnapshotState() held a ScopedSegmentAccess while
calling UnmountSegment() for unready segments.

ScopedSegmentAccess owns the segment manager's non-recursive
std::shared_mutex, and UnmountSegment() acquires the same lock again.
When a snapshot contains a segment in a non-OK lifecycle state, snapshot
restore can deadlock permanently while cleaning up that segment.

This change copies unready segment records while holding the segment lock,
releases the accessor, and then unmounts the segments. Unexpected unmount
errors are also logged.

A regression test covers snapshot restore with a
GRACEFULLY_UNMOUNTING segment.

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • 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?

Test commands:

cmake --build build --target master_service_test_for_snapshot -j4
./build/mooncake-store/tests/master_service_test_for_snapshot \
  --gtest_filter=MasterServiceSnapshotTest.ApplySnapshotStateUnmountsUnreadySegmentsWithoutDeadlocking
./build/mooncake-store/tests/master_service_test_for_snapshot \
  --gtest_filter=MasterServiceSnapshotTest.*

Test results:

  • Unit tests pass
  • Integration tests pass (if applicable)
  • Manual testing done (not applicable; the restore path is covered by the unit test)

The focused regression test passed, and all 70
MasterServiceSnapshotTest tests passed.

Checklist

  • I have performed a self-review of my own code
  • I have formatted my code using clang-format
  • 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

AI Assistance Disclosure

  • No AI tools were used
  • AI tools were used

AI assistance was used for this contribution.

@waizuichougou
waizuichougou force-pushed the fix/snapshot-restore-deadlock branch from b27fabc to fc4521d Compare September 11, 2026 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant