Skip to content

fix(raft): repair snapshot compaction#3

Merged
windsornguyen merged 1 commit into
mainfrom
fix/raft-snapshot-compaction
May 9, 2026
Merged

fix(raft): repair snapshot compaction#3
windsornguyen merged 1 commit into
mainfrom
fix/raft-snapshot-compaction

Conversation

@windsornguyen

Copy link
Copy Markdown
Owner

Pull Request

Summary

What: Repair snapshot compaction metadata, suffix retention, snapshot responses, and post-snapshot AppendEntries boundaries.

Why: Raft snapshot installation is not just "clear the log"; the snapshot carries the configuration at its boundary, and a snapshot that describes a log prefix must preserve the valid suffix.

Lines added: +221

Thesis Cross-Reference

  • Snapshot metadata includes configuration:
    compaction/memsnapshot.tex#L48-L60
    Key phrase: "latest configuration at that point".
    Context: InstallSnapshot must carry last included index, last included term, and the configuration at that index.

  • Snapshot prefix retention:
    compaction/memsnapshot.tex#L69-L78
    Key phrase: "must be retained".
    Context: conflicting/new snapshots supersede the log, but snapshots describing a prefix delete only covered entries.

  • Compaction invalidates contiguous-log assumptions:
    compaction/memsnapshot.tex#L244-L260
    Key phrase: "might have been discarded".
    Context: every log lookup around prev_log_index must handle compacted prefixes.

  • AppendEntries consistency boundary:
    basicraft/consensus.tex#L320-L334
    Key phrase: "same index and term".
    Context: the snapshot boundary term is needed so followers can satisfy AppendEntries matching at lastIncludedIndex.

Test Plan

  • cargo test -p cloud9-raft

Tests Added

  • Snapshot boundary returns snapshot_term for AppendEntries matching.
  • Snapshot truncation preserves the latest configuration.
  • Installing a matching-prefix snapshot retains the suffix.
  • Installing a conflicting snapshot discards the suffix.
  • Followers reject snapshots that would discard committed suffix state.
  • Leaders advance follower progress from InstallSnapshotResponse.

Notes for Reviewers

The important invariant is that compaction turns snapshot_index into the synthetic log entry immediately before first_index. Treating its term as unavailable breaks replication after compaction.

@windsornguyen windsornguyen force-pushed the fix/raft-snapshot-compaction branch from 0fdecd0 to 5871e0d Compare May 9, 2026 03:42
@windsornguyen windsornguyen force-pushed the fix/rename-cloud9-raft branch from 3a9a6bf to b2fb2de Compare May 9, 2026 03:45
@windsornguyen windsornguyen force-pushed the fix/raft-snapshot-compaction branch 2 times, most recently from 56c5b04 to bb11867 Compare May 9, 2026 07:02
@windsornguyen windsornguyen force-pushed the fix/raft-snapshot-compaction branch from bb11867 to 941e903 Compare May 9, 2026 07:03
@windsornguyen windsornguyen changed the base branch from fix/rename-cloud9-raft to main May 9, 2026 07:05
@windsornguyen windsornguyen merged commit 484b1f2 into main May 9, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant