Repository navigation
[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
Open
Juhyun-Kim-Memphis wants to merge 2 commits into
Juhyun-Kim-Memphis wants to merge 2 commits into
Conversation
Juhyun-Kim-Memphis
requested review from
00fish0,
Aionw,
Icedcoco,
Libotry,
XucSh,
YiXR,
stmatengss and
ykwd
as code owners
October 20, 2026 09:21
Juhyun-Kim-Memphis
force-pushed
the
store-ha-restore-parallel-identity
branch
from
October 21, 2026 07:00
f4051c3 to
7a1b195
Compare
1 task done
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.
Juhyun-Kim-Memphis
force-pushed
the
store-ha-restore-parallel-identity
branch
from
October 22, 2026 13:22
7a1b195 to
e8048f9
Compare
1 task
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Series. This PR is one of three that implement the shutdown handoff RFC #4666. It does not depend on the others.
LOCAL_DISK) replicas (#4686), needed by the L4 part of the handoffBoth commits help HA promotion on their own, with or without the handoff.
1. Restore batch OpLog promotions in parallel
RestoreFromBatchOpLogPromotionbuilds 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 asPublishRestoredObjects(#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 astd::mapper segment.restore_workersdefaults tomin(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;
BatchPromotionRejectsCrossChunkOverlappinned 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
StandbyMetadataStorewith the same deterministic input for both builds (96 B keys, one memory replica each, 12 segments of 675 GiB, one tenant) and times oneRestoreFromBatchOpLogPromotioncall; peak RSS isVmHWMreset just before the call. Each configuration ran 3 times as a separate process, interleaved; the table shows the median restore time in seconds.mainmain, 17.4–17.5 GiB with this change; 25M 42.0 GiB onmain, 42.5–43.2 GiB. One worker runs as fast asmain.mainand 1, 8 and 32 workers at 10M, and formainand 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.gdbstack 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.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 restoredLOCAL_DISKreplica indisk_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.
ValidateStandbyRemountSegmentmatches 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_MOUNTOpLog records andStandbySegmentInfonow carry them asstruct_pack::compatiblefields, 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
restore_workersbe a master config option, and is 8 the right default? Should the default count CPUs withsched_getaffinityinstead ofhardware_concurrency()?StandbySegmentInfothe right place forowner_client_id? Does this touch the roadmap's V-series ([RoadMap]: Mooncake Store HA and OpLog Roadmap #3808)?Suggested Merge Priority
Module
mooncake-transfer-engine)mooncake-store)mooncake-conductor)mooncake-reshard)mooncake-ep)mooncake-pg)mooncake-integration)mooncake-p2p-store)mooncake-wheel)mooncake-common)mooncake-rl)Type of Change
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, onmain5872ee87). The branch was rebased onto5872ee87after #4844 moved the standby restore onto the per-key accessors. The parallel install now publishes each object throughMetadataAccessorRWasPublishRestoredObjectsdoes, records each publication by itsObjectRef, and the rollback erases byObjectRefthrough the accessor, which also drops a tenant left empty (the rule from #4796). Like #4844's serial path, it also counts a restoredLOCAL_DISKreplica in its shard'sdisk_object_count; the new testBatchPromotionCountsRestoredDiskObjectschecks that count after a parallel restore and after a failed one. The 16 binaries below andmaster_service_tenant_iteration_testpass ate8048f9c.Test commands:
Test results:
ninja allbuilds. 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_countafter a parallel restore, and 0 after a failed one),RemountRejectsStandbySegmentOfAnotherMount,OpLogApplierTest.TestApplySegmentMountKeepsIdentity, andSegmentIdentityCodecTest.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 makesRemountRejectsStandbySegmentOfAnotherMountfail. One8048f9c: without thedisk_object_countincrement in the parallel install,BatchPromotionCountsRestoredDiskObjectsfails (the count is 0 after a successful restore and −6 after a failed one).Not verified:
main.mooncake_masterbinaries and etcd; the tests driveMasterServiceand the standby in process.main.Checklist
./scripts/code_format.shNotes on the checklist: pre-commit is not installed where I ran this, so I did not run it;
./scripts/code_format.sh --changed-lines --checkpasses (clang-format 20.1) andgit diff --checkis 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
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.