Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Consensus: An Introduction to Raft

Consensus: An Introduction to Raft

Patrick Van Stee

July 23, 2013
Tweet

More Decks by Patrick Van Stee

Other Decks in Programming

Transcript

  1. Consensus Module • Roles: Leader, Follower, and Candidate • Time

    is divided into Terms • Commands: RequestVote and AppendEntries
  2. Leader Accept commands from clients, commit entries, and send heartbeats

    Follower Replicate state from leaders and vote for candidates Candidate Start and handle leader elections
  3. Follower Candidate Leader Times out, Starts election Times out, Restarts

    election Wins election Discovers new leader, Steps down Discovers current leader or new leader, Steps down
  4. Term Higher numbers are used to determine leaders and check

    log entries. The term is incremented each time an election is started. Any command with an old term is ignored.
  5. A B C Role: Leader Term: 1 Commit Index: 0

    Log: [] Role: Follower Term: 1 Commit Index: 0 Log: [] Role: Follower Term: 1 Commit Index: 0 Log: []
  6. A B C Role: Leader Term: 1 Commit Index: 0

    Log: [˒] Role: Follower Term: 1 Commit Index: 0 Log: [] Role: Follower Term: 1 Commit Index: 0 Log: [] Leader receives command ˒
  7. A B C Role: Leader Term: 1 Commit Index: 0

    Log: [˒] Role: Follower Term: 1 Commit Index: 0 Log: [˒] Role: Follower Term: 1 Commit Index: 0 Log: [˒] Leader sends log entries to followers
  8. A B C Role: Leader Term: 1 Commit Index: 1

    Log: [˒] Role: Follower Term: 1 Commit Index: 0 Log: [˒] Role: Follower Term: 1 Commit Index: 0 Log: [˒] Majority of followers respond with success
  9. A B C Role: Leader Term: 1 Commit Index: 1

    Log: [˒] Role: Follower Term: 1 Commit Index: 1 Log: [˒] Role: Follower Term: 1 Commit Index: 1 Log: [˒] Leader sends commit index to followers and responds to client
  10. A B C Role: Leader Term: 1 Commit Index: 0

    Log: [] Role: Follower Term: 1 Commit Index: 0 Log: [] Role: Follower Term: 1 Commit Index: 0 Log: []
  11. A B C Role: Leader Term: 1 Commit Index: 0

    Log: [˒] Role: Follower Term: 1 Commit Index: 0 Log: [] Role: Follower Term: 1 Commit Index: 0 Log: [] Leader receives command ˒
  12. A B C Role: Leader Term: 1 Commit Index: 0

    Log: [˒] Role: Follower Term: 1 Commit Index: 0 Log: [˒] Role: Follower Term: 1 Commit Index: 0 Log: [] Leader sends log entries to followers
  13. A B C Role: Leader Term: 1 Commit Index: 0

    Log: [˒] Role: Follower Term: 1 Commit Index: 0 Log: [˒] Role: Follower Term: 1 Commit Index: 0 Log: [] Majority of followers do not respond
  14. A B C Role: Leader Term: 1 Commit Index: 0

    Log: [˒] Role: Follower Term: 1 Commit Index: 0 Log: [˒] Role: Follower Term: 1 Commit Index: 0 Log: [˒] Leader continues to retry log entry
  15. A B C Role: Leader Term: 1 Commit Index: 0

    Log: [] Role: Follower Term: 1 Commit Index: 0 Log: [] Role: Follower Term: 1 Commit Index: 0 Log: [] D Role: Follower Term: 1 Commit Index: 0 Log: []
  16. A B C Role: Leader Term: 1 Commit Index: 0

    Log: [] Role: Follower Term: 1 Commit Index: 0 Log: [] Role: Follower Term: 1 Commit Index: 0 Log: [] Followers do not receive heartbeat D Role: Follower Term: 1 Commit Index: 0 Log: []
  17. A B C Role: Leader Term: 1 Commit Index: 0

    Log: [] Role: Candidate Term: 2 Commit Index: 0 Log: [] Role: Follower Term: 1 Commit Index: 0 Log: [] First follower to timeout becomes candidate D Role: Follower Term: 1 Commit Index: 0 Log: []
  18. A B C Role: Leader Term: 1 Commit Index: 0

    Log: [] Role: Candidate Term: 2 Commit Index: 0 Log: [] Role: Follower Term: 2 Commit Index: 0 Log: [] Candidate starts election and requests votes D Role: Follower Term: 2 Commit Index: 0 Log: []
  19. A B C Role: Leader Term: 1 Commit Index: 0

    Log: [] Role: Leader Term: 2 Commit Index: 0 Log: [] Role: Follower Term: 2 Commit Index: 0 Log: [] Followers respond with votes D Role: Follower Term: 2 Commit Index: 0 Log: []
  20. Smart People • Raft Paper by Diego Ongaro and John

    Ousterhout • Raft Implementation • ThinkDistributed