Skip to content

[Store] HA: restore promotions in parallel and check a segment's identity on remount - #4802

Open
Juhyun-Kim-Memphis wants to merge 2 commits into
kvcache-ai:mainfrom
Juhyun-Kim-Memphis:store-ha-restore-parallel-identity
Open

Juhyun-Kim-Memphis wants to merge 2 commits into
kvcache-ai:mainfrom
Juhyun-Kim-Memphis:store-ha-restore-parallel-identity

Conversation

@Juhyun-Kim-Memphis

@Juhyun-Kim-Memphis Juhyun-Kim-Memphis commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Description

Series. This PR is one of three that implement the shutdown handoff RFC #4666. It does not depend on the others.

Item Role Depends on Commits to review
RFC #4666 Design of the shutdown handoff for a standalone master – –
#4687 Fix for wrong reads from L4 (LOCAL_DISK) replicas (#4686), needed by the L4 part of the handoff – its 12 commits (commits)
This PR HA promotion restore: parallel restore and a segment identity check on remount – 2 commits (compare)
#4804 The shutdown handoff itself, including its L4 state this PR, #4687 its last 7 commits

Both commits help HA promotion on their own, with or without the handoff.

1. Restore batch OpLog promotions in parallel

RestoreFromBatchOpLogPromotion builds and installs every object on one thread. Workers now copy slices of the metadata store out under one lock (the store has a single traversal cursor; the slices of one round add up to one chunk, so the copy footprint is unchanged), then validate, build and publish them concurrently, each under its own key as PublishRestoredObjects (#4844) does. The checks that need the whole index (overlapping memory ranges, segment capacity) run after every chunk is installed, per segment in parallel, on sorted range lists instead of a std::map per segment. restore_workers defaults to min(hardware threads, 8). Validation rules and error codes are those of the serial path.

Behavior change: because overlaps are now found after the install, a failed bounded restore erases what it installed before it returns. It used to return with the chunks before the failing one still installed; BatchPromotionRejectsCrossChunkOverlap pinned that state (1 object installed) and now expects 0, which is what the legacy path already did.

Measurement. Native Linux, Intel Xeon Platinum 8462Y+, a container with 34 logical CPUs pinned (17 physical cores with SMT, one NUMA node), Release, g++ 13.3. A small tool fills a StandbyMetadataStore with the same deterministic input for both builds (96 B keys, one memory replica each, 12 segments of 675 GiB, one tenant) and times one RestoreFromBatchOpLogPromotion call; peak RSS is VmHWM reset just before the call. Each configuration ran 3 times as a separate process, interleaved; the table shows the median restore time in seconds.

Keys (object size) main 1 worker 2 4 8 (default) 16 32
10M (470 KB) 63.76 63.90 34.95 22.39 16.55 (3.85×) 15.64 15.49
25M (300 KB) 178.03 174.97 95.08 59.63 45.91 (3.88×) 44.00 43.38
  • Peak RSS: 10M 17.2 GiB on main, 17.4–17.5 GiB with this change; 25M 42.0 GiB on main, 42.5–43.2 GiB. One worker runs as fast as main.
  • Correctness: every run restored all keys, and every run gave the same allocated bytes per segment. For main and 1, 8 and 32 workers at 10M, and for main and 8 workers at 25M, every key was looked up after the owners remounted and compared with the generator (address, size, endpoint, status, replica id): 0 missing, 0 wrong, and the order-independent digests were equal across builds.
  • The worker count was checked, not assumed: the thread count observed during the restore was always the worker count.
  • Above 8 workers the time flattens because the copy under the single cursor lock is serial: in two gdb stack samples at 16 workers, 11 and 12 workers were waiting on that lock. Going further needs a cursor per shard, which this PR does not attempt.
  • Limits: the input is synthetic (no codec decode, no OpLog apply, no conflicting or stale replicas). The 25M run uses 300 KB objects because 470 KB objects do not fit the 12 segments. Only this machine was measured; containers with fewer than 8 CPUs were not. The numbers were measured on this commit as it was before its rebases onto current main. Since then the install step gained the generation argument from [Store] Reach object metadata through a per-key accessor contract #4717 and the session id from [Store] Add session IDs to KV events for Dynamo session prefix indexer #4683, and with [Store] Move reads, offboarding and standby restore onto per-key accessors and tenant cursors #4844 it publishes each object under its own key (one shard lock per object instead of one per shard and slice) and counts a restored LOCAL_DISK replica in disk_object_count. I have not rerun the benchmark after that.
  • std::thread::hardware_concurrency() returned the host's 128 CPUs inside the 34-CPU container, so the default is 8 there. See the question below.

2. Record a segment's mount identity and check it on remount

A promoted master takes over the replicas it restored when their owner remounts the segment. ValidateStandbyRemountSegment matches the remount to the standby record by name, endpoint and capacity only. A store that restarted during the failover comes back with the same name, endpoint and size (the usual case for a pod restart). Once it remounts, for example after its liveness lapsed, it passes that check and the restored replicas are bound to memory the new process never wrote, so reads return other bytes without an error.

A mount has an identity a restarted store cannot reproduce: the segment id it draws for every mount and its client id (both random per process) and the registered base address. SEGMENT_MOUNT OpLog records and StandbySegmentInfo now carry them as struct_pack::compatible fields, the applier keeps them in the standby's segment registry, and a remount whose segment id, base or client differs from a record that has them is refused like any other mismatch (INVALID_PARAMS) and logged. Records without identity are checked as before, and readers that do not know the fields skip them; both directions are tested.

Questions for reviewers

  1. Is it acceptable that a failed bounded restore now erases what it installed? Should restore_workers be a master config option, and is 8 the right default? Should the default count CPUs with sched_getaffinity instead of hardware_concurrency()?
  2. On an identity mismatch, should the remount be refused (as here; a restarted store then keeps failing to remount until its standby record goes away), or should the standby record's replicas be dropped and the new mount accepted?
  3. Is StandbySegmentInfo the right place for owner_client_id? Does this touch the roadmap's V-series ([RoadMap]: Mooncake Store HA and OpLog Roadmap #3808)?
  4. Should the parallel restore be part of N07, or stay a separate change?

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?

Native Linux x86_64 (a container on a server node, kernel 6.8, no emulation), gcc 13.3, Release, on the last commit (e8048f9c, on main 5872ee87). The branch was rebased onto 5872ee87 after #4844 moved the standby restore onto the per-key accessors. The parallel install now publishes each object through MetadataAccessorRW as PublishRestoredObjects does, records each publication by its ObjectRef, and the rollback erases by ObjectRef through the accessor, which also drops a tenant left empty (the rule from #4796). Like #4844's serial path, it also counts a restored LOCAL_DISK replica in its shard's disk_object_count; the new test BatchPromotionCountsRestoredDiskObjects checks that count after a parallel restore and after a failed one. The 16 binaries below and master_service_tenant_iteration_test pass at e8048f9c.

Test commands:

cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_UNIT_TESTS=ON \
  -DWITH_STORE_RUST=OFF -DWITH_RUST_EXAMPLE=OFF -DWITH_P2P_STORE=OFF -DWITH_EP=OFF \
  -DUSE_ETCD=OFF -DUSE_CUDA=OFF ..
ninja all
ctest -R '<the 16 binaries below and master_service_tenant_iteration_test>' --output-on-failure -j8

Test results:

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

ninja all builds. All 16 test binaries around HA promotion, the standby and segments pass: master_service_ha_test, batch_oplog_snapshot_promotion_test, batch_oplog_snapshot_rebootstrap_test, batch_oplog_snapshot_codec_test, batch_oplog_snapshot_writer_test, batch_oplog_snapshot_provider_test, oplog_applier_test, oplog_types_test, oplog_batch_standby_reader_test, hot_standby_service_test, standby_controller_test, standby_metadata_store_test, standby_state_machine_test, master_service_test, master_service_segment_scenario_test, segment_test.

New tests: MasterServiceHATest.BatchPromotionRestoresInParallel (1 and 4 workers give the same index), BatchPromotionFailureInParallelInstallsNothing, BatchPromotionRejectsRangesBeyondCapacity (capacity exceeded across chunks), BatchPromotionCountsRestoredDiskObjects (disk_object_count after a parallel restore, and 0 after a failed one), RemountRejectsStandbySegmentOfAnotherMount, OpLogApplierTest.TestApplySegmentMountKeepsIdentity, and SegmentIdentityCodecTest.RecordsWithoutIdentityStillDecode / ReadersWithoutIdentitySkipIt (old and new record layouts in both directions).

Mutation check (on these commits before their rebase onto current main): removing the identity comparison from the standby remount check makes RemountRejectsStandbySegmentOfAnotherMount fail. On e8048f9c: without the disk_object_count increment in the parallel install, BatchPromotionCountsRestoredDiskObjects fails (the count is 0 after a successful restore and −6 after a failed one).

Not verified:

  • The first commit was built and tested on its own before the rebase, not after it; only the last commit was verified on current main.
  • No failover with real mooncake_master binaries and etcd; the tests drive MasterService and the standby in process.
  • The benchmark above ran on these commits before the rebase onto current main.

Checklist

  • 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

Notes on the checklist: pre-commit is not installed where I ran this, so I did not run it; ./scripts/code_format.sh --changed-lines --check passes (clang-format 20.1) and git diff --check is clean. Non-test code is +527 / −244 (tests +319 / −4); most of the first commit moves the serial restore into the parallel functions. These commits are part of the work proposed in RFC #4666; I can split them into two PRs if you prefer.

AI Assistance Disclosure

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

Claude Code helped write the change and its tests, run the builds, tests and benchmarks, and draft this description. The submitter is responsible for understanding and defending every changed line.

The bounded promotion restore (RestoreFromBatchOpLogPromotion) builds and
installs every object on one thread: about 64 s for 10M keys on main,
and it scales linearly with the index. The work per object is
independent apart from three pieces of shared state, so it can run on
several threads.

Workers now copy slices of the metadata store out under one lock (the
store has a single traversal cursor; the slices together stay within
chunk_object_count, so the copy footprint is unchanged), then validate,
build and publish them concurrently, each under its own key as
PublishRestoredObjects does (a restored LOCAL_DISK replica counts as a
disk object, and the rollback erases each publication by its ObjectRef).
Owner records and NoF allocators are created under a small mutex. The
checks that need the whole index (overlapping memory ranges, segment
capacity) run once every chunk is in, per segment in parallel, on sorted
range lists instead of a std::map per segment.

Because overlap is now found after the install, a failed bounded restore
erases what it installed before it returns. It used to return with the
chunks before the failing one still installed (the cross-chunk overlap
test pinned that); a failed restore now leaves the index as it found it,
as the legacy path already did.

restore_workers defaults to min(hardware threads, 8). The validation,
error codes and installed state are those of the serial path.
A promoted master takes the replicas it restored over when the owner
remounts their segment. ValidateStandbyRemountSegment matches the
remount to the standby record by name, endpoint and capacity only. A
store that restarted during the fail-over comes back under the same
name, endpoint and size (the usual case for a pod restart); once it
remounts, for example after its liveness lapsed, it passes that check
and the restored replicas are bound to memory the new process never
wrote. Reads then return other bytes without an error.

A segment's mount has an identity the store cannot reproduce after a
restart: the segment id it generates for every mount and its client id,
both random per process, and the registered base address. SEGMENT_MOUNT
OpLog records and StandbySegmentInfo now carry them as compatible
fields (absent in records written before), the applier keeps them in
the standby's segment registry, and a remount whose segment id, base or
client differs from a record that has them is refused like any other
mismatch (INVALID_PARAMS) and logged.

Records without identity are checked as before, and readers that do not
know the fields skip them (both directions are tested), so mixed
versions during an upgrade keep today's behavior.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant