Skip to content

Instantly share code, notes, and snippets.

@SamvitJ
Created October 23, 2016 17:36
Show Gist options
  • Save SamvitJ/00e84cec539e19419ec3fe503341d746 to your computer and use it in GitHub Desktop.
Save SamvitJ/00e84cec539e19419ec3fe503341d746 to your computer and use it in GitHub Desktop.
Paxos Pseudocode
--- Paxos Proposer ---
proposer(v):
choose n > n_p
send prepare(n) to all servers including self
if prepare_ok(n, n_a, v_a) from majority:
v’ = v_a with highest n_a; choose own v otherwise
send accept(n, v’) to all
if accept_ok(n) from majority:
send decided(v’) to all
--- Paxos Acceptor ---
acceptor state on each node (persistent):
n_p --- highest prepare seen
n_a, v_a --- highest accept seen
acceptor’s prepare(n) handler:
if n > n_p
n_p = n
reply prepare_ok(n, n_a, v_a)
acceptor’s accept(n, v) handler:
if n >= n_p
n_p = n
n_a = n
v_a = v
reply accept_ok(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment