Skip to content

feat: Raft Snapshotting and Log Compaction#200

Merged
Migorithm merged 14 commits into
mainfrom
feat/180
Jul 21, 2026
Merged

feat: Raft Snapshotting and Log Compaction#200
Migorithm merged 14 commits into
mainfrom
feat/180

Conversation

@Migorithm

@Migorithm Migorithm commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

closes #180

Changes

Prior to this branch, the Raft log would grow infinitely. This branch adds the ability to periodically take a full snapshot of the state machine, save it to disk, and delete the old log entries to save space, as well as transfer those snapshots over the network to lagging nodes.

1. Configuration & Triggers (config.rs, multi_raft.rs)

  • Introduced raft_snapshot_entry_threshold (default 10,000) with proper clap bounds validation.
  • Added logic in the MultiRaftActor to periodically check if a shard group has applied enough
    entries to cross this threshold, triggering a snapshot creation.

2. Storage Layer & Compaction (impls/metadata_storage.rs, storage.rs)

  • Reserved new RocksDB keys (0x03 for Snapshot Metadata, 0x04 for Snapshot Data, 0x05 for Applied
    Index).
  • Implemented atomic snapshot persistence: A single WriteBatch now saves the new snapshot while
    issuing a Range Tombstone to delete the covered LogEntry prefix.
  • Added the fail-fast assert_eq! check on startup to guarantee the surviving uncompacted log suffix
    is strictly contiguous.

3. Network Transfer & Validation (transient_state.rs, messages/rpc.rs)

  • Added the InstallSnapshot and InstallSnapshotResponse RPC messages.
  • Added chunk buffering logic in TransientState.
  • Implemented strict bounds checking (the accepts() method we looked at) to ensure incoming network
    chunks are strictly sequential, don't exceed SNAPSHOT_CHUNK_BYTES, and match the declared
    size_bytes header.

4. The Staging State Machine (raft/state.rs, log_state.rs)

  • Implemented a safe lifecycle for received snapshots: None -> Staged -> Active.
  • handle_install_snapshot_request: Buffers chunks and stages them.
  • publish_persisted_snapshot: The final step that flips the snapshot from Staged to Active
    (overwriting the live MetadataState and self.peers) after the actor confirms it was safely written
    to disk.

5. Integration Tests (it/raft/snapshot.rs)

  • Added a robust new test suite specifically dedicated to testing snapshot creation, the chunked
    network installation process, and node recovery from disk snapshots.

@Migorithm Migorithm self-assigned this Jul 21, 2026
@Migorithm Migorithm added documentation Improvements or additions to documentation enhancement New feature or request feat labels Jul 21, 2026
@Migorithm
Migorithm merged commit 52c95bf into main Jul 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request feat

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add metadata snapshots, installation, and Raft log compaction

1 participant