Raft: Consensus for Rubyists

Raft: Consensus for Rubyists

B6a8f005f39d23ffc930508ac9da68b9?s=128

Patrick Van Stee

November 09, 2013
Tweet

Transcript

  1. 18.
  2. 24.
  3. 35.
  4. 42.

    Follower Candidate Leader Times out, Starts election Times out, Restarts

    election Wins election Discovers current or new leader, Steps down
  5. 43.

    Follower Candidate Leader Times out, Starts election Times out, Restarts

    election Wins election Discovers new leader, Steps down Discovers current or new leader, Steps down
  6. 44.

    RequestVote Used by candidates to ask for votes during an

    election. Log information included for comparison. ! AppendEntries Used by leaders to tell followers which entries to replicate and commit. Also used as a heartbeat to remain leader. Follower Candidate Vote for me please. Follower Here are some entries for your log. Oh, and btw I’m still the leader. Leader
  7. 45.

    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. Term 1 Term 2 Term 3 Election Normal Operation Split vote
  8. 54.

    SET X = 1 SET Y = 2 SET Z

    = 3 SET X = 4 SET X = 5 1 1 1 2 2 SET X = 1 SET Y = 2 SET Z = 3 SET X = 4 1 1 1 2 Leader Follower 1 2 3 4 5 6
  9. 55.

    { :entries => [{ 4 => 'SET X = 4'

    }], :term => 1, :prev_log_term => 1, :prev_log_index => 3, :leader_commit => 3, :leader_id => '192.168.1.101/7238' } APPEND ENTRIES EXAMPLE
  10. 56.

    SET X = 1 SET Y = 2 SET Z

    = 3 1 1 1 Before 1 1 1 1 After SET X = 1 SET Y = 2 SET Z = 3 SET X = 4 1 2 3 4 5 6 1 2 3 4 5 6
  11. 85.

    Only cast votes for nodes with logs that contain at

    least as many entries as your own. 1
  12. 86.

    New leaders must commit a log entry form their new

    term before committing old entries. 2
  13. 89.
  14. 90.