Skip to content

[STORE] refactor HA runtime around standby replication and snapshot catalogs - #1776

Closed
YiXR wants to merge 41 commits into
kvcache-ai:mainfrom
openanolis:xinyi/ha
Closed

YiXR wants to merge 41 commits into
kvcache-ai:mainfrom
openanolis:xinyi/ha

Conversation

@YiXR

@YiXR YiXR commented Mar 31, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR refactors the Mooncake Store HA runtime so that master processes keep
their admin/metrics surfaces alive independently from leader-only serving, and
builds a capability-driven standby replication path on top of that runtime.

The series also hardens snapshot bootstrap / restore behavior, introduces
catalog-backed snapshot loading for HA standby recovery, adds Redis/embedded
snapshot catalog support in the common HA path, and updates the Store design and
deployment docs to match the refactored architecture.

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Mooncake EP (mooncake-ep)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • PyTorch Backend (mooncake-pg)
  • Mooncake RL (mooncake-rl)
  • CI/CD
  • Docs
  • Other

Type of Change

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

What Changed

1. Split master runtime into always-on admin and leader-only serving

  • Split the master process into:
    • an always-on admin/metrics runtime
    • a leader-only Store RPC serving runtime
  • Keep non-leader masters observable even when they are not serving client RPCs.
  • Tighten serve lifecycle transitions and failure handling around leadership
    acquire/loss.

2. Introduce a replication controller and explicit standby lifecycle

  • Wire standby replication into runtime states instead of keeping it as an
    ad-hoc side path.
  • Drive standby runtime through explicit replication callbacks.
  • Compose standby replication from two capabilities:
    • snapshot bootstrap
    • oplog following
  • Unify standby lifecycle entry points so the hot-standby path has a single
    integration surface.

3. Make snapshot bootstrap a first-class HA path

  • Add a catalog-backed snapshot provider for standby bootstrap / restore.
  • Persist full SnapshotDescriptors in HA catalogs instead of relying on a
    weaker latest-only view.
  • Support both embedded and Redis snapshot catalogs in the common HA snapshot
    path.
  • Guard Redis-specific helpers by build flags so non-Redis builds stay clean.

4. Harden snapshot capture and restore semantics

  • Freeze snapshot descriptor metadata at capture time.
  • Freeze the snapshot boundary before fork.
  • Fail closed when standby bootstrap is unavailable.
  • Fail on missing snapshot catalog descriptors instead of silently proceeding.
  • Reload snapshot-only standby state from catalog.
  • Preload promoted standby state to shorten hot failover.
  • Restore from the last healthy catalog entry instead of blindly trusting the
    latest one.
  • Make restore cleanup of expired objects configurable via:
    • --cleanup_expired_on_restore
    • MC_CLEANUP_EXPIRED_ON_RESTORE

5. Expand coverage and align docs

  • Reorganize HA tests under tests/ha.
  • Add bootstrap / standby / catalog / restore coverage for the new runtime.
  • Update Store design and deployment docs to document:
    • the split between Store HA and Transfer Engine metadata
    • the HA backend abstraction
    • snapshot catalog vs snapshot object store
    • single-master and HA deployment flows for both etcd and Redis

Why

Before this series, HA runtime state, standby bootstrap, and snapshot recovery
were still spread across multiple partially-coupled paths:

  • non-leader masters did not have a clean always-on admin/metrics runtime model
  • snapshot-backed standby recovery was not integrated as a first-class runtime
    flow
  • snapshot catalog handling was not explicit enough as an HA abstraction layer
  • restore/bootstrapping semantics around missing or unhealthy catalog entries
    were too permissive

This series makes the runtime model explicit, gives standby bootstrap a proper
place in the HA state machine, and moves snapshot-based recovery toward a
backend-neutral design.

Resulting Semantics

After this PR:

  • all masters remain observable through admin/metrics endpoints
  • only the elected leader starts serving Store RPCs
  • standby recovery is driven by explicit replication capabilities
  • snapshot bootstrap is usable in the common HA runtime
  • embedded and Redis catalogs can both provide snapshot descriptors for standby
    recovery
  • snapshot-only standby can reload prebuilt state from catalog and promote from
    preloaded state
  • restore prefers the last healthy catalog entry
  • expired object cleanup on restore becomes configurable instead of hard-coded

How Has This Been Tested?

Added or expanded coverage in the following areas:

  • master_metrics_test
  • hot_standby_service_test
  • hot_standby_snapshot_bootstrap_test
  • replication_controller_test
  • catalog_backed_snapshot_provider_test
  • embedded snapshot catalog tests
  • Redis snapshot catalog tests
  • snapshot child process tests
  • master snapshot restore tests
  • snapshot-only standby edge cases

Checklist

  • I have performed a self-review of my own code.
  • I have formatted my own code using ./scripts/code_format.sh before submitting.
  • I have updated the documentation.
  • I have added tests to prove my changes are effective.

Xingrui Yi added 21 commits March 30, 2026 10:52
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the Mooncake Store high availability (HA) architecture into a backend-driven runtime that decouples leadership coordination, standby recovery, and metadata management, supporting both etcd and Redis backends. Key additions include a ReplicationController for managing standby states, a MasterAdminServer for independent health monitoring, and updated state persistence logic in MasterService. Feedback includes addressing a potential null pointer dereference when initializing the OpLogApplier, improving error log readability by converting error codes to strings, and optimizing heartbeat traffic during state restoration to avoid excessive network load. The PR also includes extensive updates to the deployment and design documentation.

Comment on lines +225 to +227
if (err != ErrorCode::OK) {
standby_service_->Stop();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The logic here re-initializes the OpLogApplier when !config_.enable_oplog_following is true, but it does not check if metadata_store_ was successfully initialized or if it's null, which could lead to a null pointer dereference if metadata_store_ is not properly set up.

Comment on lines +2892 to 2896
return fail_restore(
fmt::format("failed to deserialize segments: {} - {}",
static_cast<int>(segments_result.error().code),
segments_result.error().message));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The error message uses static_cast<int>(segments_result.error().code), which might not be the most descriptive way to log the error. Consider using a helper function to convert the error code to a string for better debugging.

int64_t total_size = 0;
for (const auto& [segment, client_id] : all_segments) {
Ping(client_id); // Add to heartbeat monitoring
Ping(client_id);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The Ping(client_id) call is inside a loop over all_segments. If all_segments is large, this could result in excessive heartbeat traffic. Consider if this is necessary for every segment or if it can be optimized.

@YiXR
YiXR marked this pull request as draft March 31, 2026 04:31
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Xingrui Yi added 19 commits April 1, 2026 12:18
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
Signed-off-by: Xingrui Yi <yixingrui@linux.alibaba.com>
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Please update the PR or comment to keep it open.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

This PR was closed because it has been inactive for 104 days. Feel free to reopen if you'd like to continue the work.

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