RaftEx.Server.RpcHandler
(raft_ex v0.1.0)
View Source
RPC handler for Raft consensus protocol messages.
This module handles:
- AppendEntries RPC and replies (log replication and heartbeats)
- InstallSnapshot RPC and replies (snapshot transfer)
- Heartbeat RPC and replies (consistent query support)
- Log consistency checks and conflict resolution
AppendEntries Flow
- Leader sends AppendEntries with prev_log_index, prev_log_term, and entries
- Follower checks log consistency at prev_log_index
- If consistent, follower appends entries and replies with success
- If inconsistent, follower replies with failure and next_index hint
- Leader updates match_index and next_index for the peer
InstallSnapshot Flow
- Leader sends snapshot chunks when follower is too far behind
- Follower receives chunks and writes snapshot
- On completion, follower installs snapshot and truncates log
- Follower replies with last_index and last_term from snapshot
Heartbeat Flow
- Leader sends lightweight heartbeats for consistent queries
- Follower acknowledges with query_index
- Leader collects acknowledgements from majority
- Once majority acknowledges, query is safe to execute
Summary
Functions
Handle an AppendEntries reply from a follower.
Handle an incoming AppendEntries RPC from the leader.
Handle a Heartbeat reply from a follower.
Handle an incoming Heartbeat RPC from the leader.
Handle an InstallSnapshot reply from a follower.
Handle an incoming InstallSnapshot RPC from the leader.
Functions
Handle an AppendEntries reply from a follower.
Returns {updated_state, effects}.
@spec handle_append_entries_rpc(RaftEx.Types.AppendEntriesRpc.t(), map()) :: {atom(), map(), [term()]}
Handle an incoming AppendEntries RPC from the leader.
Returns {next_state, updated_state, effects}.
Handle a Heartbeat reply from a follower.
Returns {updated_state, effects}.
Handle an incoming Heartbeat RPC from the leader.
Returns {updated_state, effects}.
@spec handle_install_snapshot_reply(RaftEx.Types.InstallSnapshotResult.t(), map()) :: {map(), [term()]}
Handle an InstallSnapshot reply from a follower.
Returns {updated_state, effects}.
@spec handle_install_snapshot_rpc(RaftEx.Types.InstallSnapshotRpc.t(), map()) :: {atom(), map(), [term()]}
Handle an incoming InstallSnapshot RPC from the leader.
Returns {next_state, updated_state, effects}.