Repository navigation
perf(consensus): skip fsync for unsigned internal messages (block parts) (backport #5695) - #5828
Merged
Merged
Conversation
…ts) (#5695) ## Summary - Skip `fsync` (`WriteSync`) for `BlockPartMessage` in the consensus WAL's `receiveRoutine`, using buffered `Write` instead - Only signed messages (`VoteMessage`, `ProposalMessage`) retain `WriteSync` for double-signing prevention - Adds explicit type-switch with `default: panic` to prevent future signed message types from silently bypassing fsync - Replaces stale TODO in `replay_test.go` with documentation of the selective-fsync approach ## Safety analysis **Why signed messages MUST keep `WriteSync`:** - Pre-sign `FlushAndSync` ensures WAL replay reaches the same deterministic state - Post-sign `WriteSync` ensures the signed message is durable before `handleMsg` processes/broadcasts it - Without this, crash-replay could re-sign a different vote → equivocation **Why `BlockPartMessage` can safely use `Write`:** 1. Block parts are unsigned data chunks derived from the proposal block 2. On crash: proposal exists (fsynced), some block parts may be missing → round times out → consensus proceeds 3. The periodic 2-second WAL flush (`processFlushTicks`) eventually flushes them 4. Any subsequent `WriteSync` (vote) or `FlushAndSync` (pre-sign) also flushes buffered block parts 5. `EndHeightMessage` uses `WriteSync`, which flushes ALL buffered writes before the end marker **Defensive measures:** - Explicit `case *BlockPartMessage` (not `default`) ensures new message types panic rather than silently bypassing fsync - `default: panic("unexpected internal message type")` with SAFETY comment for future maintainers - WAL `Write` failure panics (matches `WriteSync` behavior) since write errors indicate disk failure ## Benchmark results (Apple M1 Max SSD) ``` BenchmarkWALWrite-10 ~1μs/op 1680 B/op 13 allocs/op BenchmarkWALWriteSync-10 ~4.4ms/op 1680 B/op 13 allocs/op BenchmarkWALRoundSimulation/AllWriteSync-10 ~233ms/round BenchmarkWALRoundSimulation/SelectiveFsync-10 ~9.3ms/round (~25x faster) ``` --- #### PR checklist - [x] Tests written/updated - [x] Changelog entry added in `CHANGELOG.md` - [x] Updated relevant documentation (`docs/` or `spec/`) and code comments --------- Co-authored-by: Claude Opus 4.6 <[email protected]> Co-authored-by: Dmitry S <[email protected]> (cherry picked from commit 62a15e7)
Contributor
|
PR author is not in the allowed authors list. |
|
🔒 WARNING: unsigned commits detected This pull request contains 1 commit(s) without a verified signature. How to fix:
Unsigned commits:
|
3 tasks done
|
🔒 WARNING: unsigned commits detected This pull request contains 1 commit(s) without a verified signature. How to fix:
Unsigned commits:
|
mattac21
approved these changes
May 4, 2026
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
fsync(WriteSync) forBlockPartMessagein the consensus WAL'sreceiveRoutine, using bufferedWriteinsteadVoteMessage,ProposalMessage) retainWriteSyncfor double-signing preventiondefault: panicto prevent future signed message types from silently bypassing fsyncreplay_test.gowith documentation of the selective-fsync approachSafety analysis
Why signed messages MUST keep
WriteSync:FlushAndSyncensures WAL replay reaches the same deterministic stateWriteSyncensures the signed message is durable beforehandleMsgprocesses/broadcasts itWhy
BlockPartMessagecan safely useWrite:processFlushTicks) eventually flushes themWriteSync(vote) orFlushAndSync(pre-sign) also flushes buffered block partsEndHeightMessageusesWriteSync, which flushes ALL buffered writes before the end markerDefensive measures:
case *BlockPartMessage(notdefault) ensures new message types panic rather than silently bypassing fsyncdefault: panic("unexpected internal message type")with SAFETY comment for future maintainersWritefailure panics (matchesWriteSyncbehavior) since write errors indicate disk failureBenchmark results (Apple M1 Max SSD)
PR checklist
CHANGELOG.mddocs/orspec/) and code commentsThis is an automatic backport of pull request perf(consensus): skip fsync for unsigned internal messages (block parts) #5695 done by Mergify.