-->

什么是在Paxos一致性算法“视图”?(What is a “view” in the Paxos

2019-10-16 16:38发布

我已经贴伪代码低于Paxos演算法,并想知道如果有人能在正确的方向指向我。 我想实现下面的算法,但我是一个困惑究竟“意见”的代表。 我知道评论说,这是一个“过去的观点号码值的地图”,但如果有人可以给我究竟这些“价值观”是什么解释“视图号”是。

  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

Answer 1:

该图对应于轮的算法。 他们被称为意见,因为在算法中每个节点是异步的,因此全球系统状态的每一个节点的理解可能会过时。 该节点使用意见算法的执行进行同步。 看,上面写着意见=几轮评论。



Answer 2:

视图是在论文中定义提出了切实可行的Paxos 。 A“观点”是集群的特定状态,即与指定的领导沿着套机。

我们关心的观点的原因是,由于机器出现在你集群的状态可能改变,去(例如,因为要重新配置群集,或者因为一个或多个机器出现故障)。

每个视图还与视图数(也被称为视图-ID)相关联,并且每一次的视图的改变,新的视图被分配一个新的视图数。 与特定视图相关联的数的值是简单地视图本身(机的集群中的列表)。 因此,“意见”可能是这个样子:

{ 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 } }

您可以在纸张的更多细节。



文章来源: What is a “view” in the Paxos consensus algorithm?