feat(raft): add snapshot and recovery mechanism#112
Merged
Conversation
Implement leader-initiated snapshots and follower snapshot application for Raft log compaction and state transfer. Key changes: - State machine: create_snapshot() serializes all user-data CFs (default, mvcc, meta, lease, lease_keys, key_lease) into a single blob. restore_snapshot() atomically clears + replays CF data in a single WriteBatch, then rebuilds in-memory indexes. - Raft store: save_snapshot_data() persists snapshot data and metadata. apply_snapshot() saves data, purges superseded log entries, and updates conf state. snapshot() now includes actual snapshot data. - Event loop: leader triggers snapshot every N applied entries (configurable via snapshot_trigger_log_entries). Follower applies received snapshots and stops the node on failure to prevent inconsistent state. - Safety: 512 MiB snapshot size limit on both create and restore, debug_assert on term() invariant, compact index covers all snapshot-covered entries.
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.
Summary
snapshot_trigger_log_entries)term()invariant assertion, compact index covers all snapshot-covered entriesChanges
create_snapshot()iterates CFs without lock and checks size limit;restore_snapshot()atomic WriteBatch clear+write+rebuild in-memory statesave_snapshot_data()persists snapshot data and metadata;apply_snapshot()saves data and purges old log entries;snapshot()includes actual snapshot data;term()adds invariant assertionsnapshot_trigger_log_entriesconfig field (default 10000)write_permtest helperTesting
cargo clippy -- -D warningscleancargo fmt -- --checkcleanRefs #83