Question

I have pasted pseudocode for a paxos algorithm below and was wondering if someone could point me in the right direction. I am trying to implement the algorithm below, but I'm a confused what exactly "views" represents below. I know the comment says it is a "map of past view numbers to values", but if someone could explain to me what exactly these "values" are and what "view numbers" are.

  state:
  num_h: highest proposal # seen in a prepare
  num_a, val_a: highest value and proposal # which node has accepted
  my_num: the last proposal # the node has used in this round of Paxos
  inst_h: highest view number we have accepted (round number)
  views: map of past view numbers to values
  done: leader says agreement was reached, we can start new view

on each view change, initialize state:
  num_a = 0
  num_h = 0
  my_num = 0
  val_a = () // empty list

Paxos Phase 1
  a node (maybe more than one...) decides to be leader (need not be in current view):
    my_num = max(num_h, my_num)+1, append node ID  // unique proposal number
    done = false
    sends prepare(inst_h+1, my_num) to all nodes in {views[inst_h], initial contact         node, itself}

  if node receives prepare(vid, n):
    if vid <= inst_h:
      return OLD_VIEW(vid, views[vid])  // views[vid] is the winner for vid
    else if n > num_h:
      num_h = n
      done = false
      return PROMISE(num_a, val_a)
    else:
      return REJECT()

Paxos Phase 2
  if leader gets OLD_VIEW(vid, v):
    views[vid] = v
    inst_h = vid
    view change
    restart paxos

  else if leader gets REJECT():
    delay and restart paxos

  else if leader gets PROMISE from majority of nodes in views[inst_h]:
    if any PROMISE(n_i, v_i) exists such that v_i is not empty:
      v = non-empty value v_i corresponding to highest n_i received
    else leader gets to choose a value:
      v = set of pingable nodes (including self)
    send ACCEPT(inst_h+1, my_num, v) to all responders

  else:
    delay and restart paxos

  if node gets ACCEPT(vid, n, v):
    if vid <= inst_h:
      return OLD_VIEW(vid, views[vid])
    else if n >= num_h:
      num_a = n
      val_a = v
      return ACCEPTED()
    else
      return REJECT()

Paxos Phase 3
  if leader gets OLD_VIEW(vid, v):
    views[vid] = v
    inst_h = vid
    view change
    restart paxos
  else if leader gets ACCEPTED from a majority of nodes in views[inst_h]:
    send DECIDE(inst_h+1, val_a) to all (including self)
  else:
    delay and restart paxos
  if node gets decide(vid, v):
    if vid <= inst_h:
      return OLD_VIEW(vid, views[vid])
    else:
      done = true
      primary is lowest-numbered node in v
      views[vid] = v
      inst_h = vid
      view change
Was it helpful?

Solution

The views correspond to rounds of the algorithm. They are called views because every node in the algorithm is asynchronous and thus every node's understanding of the global system state can be outdated. The nodes use views to synchronize the execution of the algorithm. Look at the comment that says views = rounds.

OTHER TIPS

Views are defined in the paper Paxos Made Practical. A "view" is a particular state of your cluster, i.e. the set of machines along with the designated leader.

The reason we care about views is that the state of your cluster could change as machines come and go (e.g. because you want to reconfigure your cluster, or because one or more machines have failed).

Each view is also associated with a view-number (also known as a view-id), and each time the view changes, the new view is assigned a new view-number. The value associated with a particular view-number is simply the view itself (the list of machines in the cluster). So "views" might look something like this:

{ view-number = 1 : value = { machine-01, machine-02, machine-03 },
  view-number = 2 : value = { machine-02, machine-03, machine-04 },
  view-number = 3 : value = { machine-01, machine-02, machine-04 } }

You can find more details in the paper.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top