Motivation
Snapshot is not part of the core master data path. Conceptually, it is a persistence and recovery capability that observes, captures, and restores master state, and should be modeled as a separate subsystem rather than intrinsic master request-processing logic.
Keeping snapshot orchestration and serialization inside MasterService blurs this abstraction boundary. It also makes snapshot format evolution difficult, since part of the snapshot serialization logic is implemented as a private nested component of MasterService.
This RFC proposes splitting snapshot orchestration and snapshot state serialization into dedicated components while preserving the current snapshot behavior and runtime semantics.
Proposed Changes
1. Move snapshot orchestration out of MasterService
Introduce a dedicated snapshot manager module, for example:
ha/snapshot/master_snapshot_manager.h
ha/snapshot/master_snapshot_manager.cpp
This component will own snapshot-specific orchestration:
- periodic snapshot scheduling
- snapshot ID generation
- snapshot descriptor construction
- child process lifecycle management
- timeout handling
- snapshot payload upload
- catalog publish
- retention cleanup
- snapshot metrics updates
MasterService should only provide the state capture/restore hooks needed by the snapshot manager.
2. Extract snapshot state serialization from MasterService
Move master snapshot state serialization into standalone modules instead of keeping part of the snapshot format inside MasterService.
The current snapshot payload is composed of multiple state files:
metadata: object metadata shards, discarded replicas, and replica ID state
segments: mounted memory segments, client-to-segment mappings, allocator ordering, and local disk segment/offloading state
task_manager: persisted client task manager state
manifest.txt: snapshot serializer type, version, and snapshot ID
The refactor should model these as one master snapshot state bundle, with dedicated serializers for each sub-state. MasterService should remain responsible for owning live runtime state, while the snapshot serialization layer should own the persisted representation and format compatibility.
3. Define explicit snapshot data structures
Introduce explicit snapshot DTOs for the full master snapshot state, such as:
- metadata snapshot state
- segment manager snapshot state
- task manager snapshot state
- snapshot manifest metadata
These structures should represent the persisted snapshot format independently from the internal layout of MasterService, SegmentManager, and ClientTaskManager.
This will make future snapshot format evolution easier and reduce accidental coupling to private master internals.
4. Keep restore behavior unchanged
Restore should continue to support the current snapshot storage layout and manifest validation behavior.
The proposed refactor should only move restore selection, download, decoding, and application logic into clearer components. The externally visible behavior should remain unchanged.
A possible split is:
- snapshot repository: list, download, upload, publish, cleanup
- snapshot codec: encode/decode snapshot payloads
- master state restorer: apply decoded snapshot data to
MasterService
5. Preserve existing configuration and compatibility
Existing snapshot flags and environment variables should continue to work:
--enable_snapshot
--snapshot_interval_seconds
--snapshot_child_timeout_seconds
--snapshot_retention_count
--snapshot_object_store_type
--snapshot_catalog_store_type
--snapshot_catalog_store_connstring
--snapshot_backup_dir
--enable_snapshot_restore
MOONCAKE_SNAPSHOT_LOCAL_PATH
Existing snapshots should remain restorable unless a later RFC explicitly proposes a format migration.
Expected Benefits
- Clearer abstraction boundary between core master request-processing logic and snapshot persistence/recovery logic
- Smaller and easier-to-review
MasterService
- Clear ownership boundary for snapshot code
- Easier snapshot format testing across metadata, segment, and task-manager payloads
- Easier restore testing without constructing a full master lifecycle
- Reduced reliance on private nested classes and test-only friendships
- Lower risk when adding new fields to snapshot format
Non-goals
This RFC does not propose changing the snapshot consistency model.
This RFC does not propose changing the current HA design.
This RFC does not propose changing snapshot storage backends or catalog semantics.
This RFC does not propose changing user-facing configuration.
Testing Plan
Add or update unit tests for:
- full snapshot state encode/decode round trip
- metadata snapshot encode/decode compatibility
- segment snapshot encode/decode compatibility
- task manager snapshot encode/decode compatibility
- snapshot manager descriptor construction
- snapshot manager publish/cleanup behavior
- restore fallback across multiple candidate snapshots
- restore failure handling and state reset
Keep existing snapshot integration tests passing, including:
- master snapshot/restore tests
- SSD snapshot tests
- promotion snapshot tests
- catalog-backed snapshot provider tests
- snapshot child process tests
Migration Plan
- Introduce standalone snapshot manager and serializer modules.
- Move code from
MasterService into the new modules without behavior changes.
- Replace direct private serializer usage with explicit state capture/restore hooks.
- Keep existing tests passing after each step.
- Remove obsolete private nested serializer definitions and unnecessary test friendships once callers are migrated.
Motivation
Snapshot is not part of the core master data path. Conceptually, it is a persistence and recovery capability that observes, captures, and restores master state, and should be modeled as a separate subsystem rather than intrinsic master request-processing logic.
Keeping snapshot orchestration and serialization inside
MasterServiceblurs this abstraction boundary. It also makes snapshot format evolution difficult, since part of the snapshot serialization logic is implemented as a private nested component ofMasterService.This RFC proposes splitting snapshot orchestration and snapshot state serialization into dedicated components while preserving the current snapshot behavior and runtime semantics.
Proposed Changes
1. Move snapshot orchestration out of
MasterServiceIntroduce a dedicated snapshot manager module, for example:
ha/snapshot/master_snapshot_manager.hha/snapshot/master_snapshot_manager.cppThis component will own snapshot-specific orchestration:
MasterServiceshould only provide the state capture/restore hooks needed by the snapshot manager.2. Extract snapshot state serialization from
MasterServiceMove master snapshot state serialization into standalone modules instead of keeping part of the snapshot format inside
MasterService.The current snapshot payload is composed of multiple state files:
metadata: object metadata shards, discarded replicas, and replica ID statesegments: mounted memory segments, client-to-segment mappings, allocator ordering, and local disk segment/offloading statetask_manager: persisted client task manager statemanifest.txt: snapshot serializer type, version, and snapshot IDThe refactor should model these as one master snapshot state bundle, with dedicated serializers for each sub-state.
MasterServiceshould remain responsible for owning live runtime state, while the snapshot serialization layer should own the persisted representation and format compatibility.3. Define explicit snapshot data structures
Introduce explicit snapshot DTOs for the full master snapshot state, such as:
These structures should represent the persisted snapshot format independently from the internal layout of
MasterService,SegmentManager, andClientTaskManager.This will make future snapshot format evolution easier and reduce accidental coupling to private master internals.
4. Keep restore behavior unchanged
Restore should continue to support the current snapshot storage layout and manifest validation behavior.
The proposed refactor should only move restore selection, download, decoding, and application logic into clearer components. The externally visible behavior should remain unchanged.
A possible split is:
MasterService5. Preserve existing configuration and compatibility
Existing snapshot flags and environment variables should continue to work:
--enable_snapshot--snapshot_interval_seconds--snapshot_child_timeout_seconds--snapshot_retention_count--snapshot_object_store_type--snapshot_catalog_store_type--snapshot_catalog_store_connstring--snapshot_backup_dir--enable_snapshot_restoreMOONCAKE_SNAPSHOT_LOCAL_PATHExisting snapshots should remain restorable unless a later RFC explicitly proposes a format migration.
Expected Benefits
MasterServiceNon-goals
This RFC does not propose changing the snapshot consistency model.
This RFC does not propose changing the current HA design.
This RFC does not propose changing snapshot storage backends or catalog semantics.
This RFC does not propose changing user-facing configuration.
Testing Plan
Add or update unit tests for:
Keep existing snapshot integration tests passing, including:
Migration Plan
MasterServiceinto the new modules without behavior changes.