feat(raft): implement ReadIndex-based linearizable reads#113
Merged
Conversation
Replace the simplified leader-check-only linearizable read with the full Raft ReadIndex protocol. The leader now sends a heartbeat to confirm its authority before allowing reads, preventing stale reads during network partitions where a leader has been isolated but hasn't yet discovered a new leader. Key changes: - Add ReadIndex channel and request type to the raft event loop - Process MsgReadIndex via raft-rs read_index() with pending tracking - Add read_index() and wait_for_apply() to RaftHandle trait - Replace 5ms polling with Notify-based waiting for applied_index - Add serializable field to RangeRequest proto (matching GetRequest) - Add 12 unit tests covering read_index, ensure_linearizable, and redirects
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
Replace the simplified leader-check-only linearizable read with the full Raft ReadIndex protocol. The leader now sends a heartbeat to confirm its authority before allowing reads, preventing stale reads during network partitions where a leader has been isolated but hasn't yet discovered a new leader.
Changes
ReadIndexRequesttype, read-index channel inEventLoopChannels, pending tracking in event loop, andNotifyonRaftSharedStatefor efficient wait signaling.read_index()andwait_for_apply()toRaftHandletrait. Makeensure_linearizable()async to use the real ReadIndex protocol. AddClonederive toRaftError. Add 12 unit tests.read_index()andwait_for_apply()via channel and sharedNotify.linearizable_read()to use asyncensure_linearizable()andNotify-based waiting instead of 5ms polling. Gaterange()onserializablefield.read_index_txfromRaftNodeHandleintoRaftRsHandle.bool serializable = 7toRangeRequest, matchingGetRequest.Testing
read_index(),wait_for_apply(),ensure_linearizable()with leader/no-leader/not-leader/channel-closed/redirect scenarioscargo clippy -- -D warningsandcargo fmt -- --checkcleanRelated issues
Refs #84