gpt4 book ai didi

algorithm - Paxos共识算法中的 "view"是什么?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:10:25 24 4
gpt4 key购买 nike

我在下面粘贴了一个 paxos 算法的伪代码,想知道是否有人可以指出正确的方向。我正在尝试实现下面的算法,但我对下面的“ View ”究竟代表什么感到困惑。我知道评论说它是“过去的 View 数字到值的映射”,但如果有人能向我解释这些“值”到底是什么以及“ View 数字”是什么。

  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

最佳答案

View 对应于算法的轮次。它们被称为 View 是因为算法中的每个节点都是异步的,因此每个节点对全局系统状态的理解可能会过时。节点使用 View 来同步算法的执行。看看评论说 views = rounds。

关于algorithm - Paxos共识算法中的 "view"是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10490902/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com