How msterx-1/raft-algorithm works
This is a teaching implementation of Raft consensus, using a simulated RPC network to elect leaders and replicate and apply log entries. The main workflow is an application submitting a command to the leader, replication to peers, commitment by a majority, and delivery to the application. Election, heartbeat, and conflict-repair behavior are also represented. The excerpts show the protocol and transport calls; the application is represented as an external actor. The tester support in raft/config.go is omitted as peripheral; unsampled behavior is not inferred.
Main entry points: raft.go Log replication · labrpc.go RPC network
Components 12
Raft protocol
- Leader election
raft/raft.go - Vote handler
raft/raft.go - Heartbeat scheduler
raft/raft.go - Log replication
raft/raft.go - Append handler
raft/raft.go - Commit tracking
raft/raft.go - Peer Raft
raft/raft.go
RPC transport
- RPC network
labrpc/labrpc.go
Application interface
- Submit command
raft/raft.go - Apply committed
raft/raft.go
Other components
- Application
- Apply consumer
Connections 14
- Application → Submit command: submits
raft/raft.go - Submit command → Log replication: schedules
raft/raft.go - Leader election → Vote handler: requests votes
raft/raft.go - Leader election → Peer Raft: sends vote RPC
raft/raft.go - Heartbeat scheduler → Log replication: schedules
raft/raft.go - Heartbeat scheduler → Peer Raft: sends heartbeat
raft/raft.go - Log replication → Peer Raft: sends entries
raft/raft.go - Peer Raft → RPC network: calls RPC
raft/raft.go - RPC network → Vote handler: dispatches vote
- RPC network → Append handler: dispatches entries
- Append handler → Commit tracking: advances commit
raft/raft.go - Log replication → Commit tracking: advances commit
raft/raft.go - Commit tracking → Apply committed: signals
raft/raft.go - Apply committed → Apply consumer: sends apply message
raft/raft.go