Once a leader is elected, it takes charge of managing log replication. In this chapter, we outline log formats, follower inconsistencies, and the strict safety invariants of log commits.
Log Structure
The replicated state log consists of sequential entries. Each entry contains:
- The client command to be executed by the state machine.
- The leader’s term when the entry was created.
- An integer index indicating its position in the log.
Log Commit Safety Invariant
A leader commits an entry by updating its internal commitIndex. Committed entries are guaranteed to be durable across restarts and failures.
Raft guarantees that if a log entry is committed in a given term, that entry will be present in the logs of the leaders for all higher-numbered terms. This is called the Leader Completeness Property.
type AppendEntriesArgs struct {
Term Term
LeaderId NodeId
PrevLogIndex int
PrevLogTerm Term
Entries []LogEntry
LeaderCommit int
}