V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
JasonLaw
V2EX  ›  程序员

关于 Raft Consensus Algorithm 的疑问

  •  
  •   JasonLaw · 2021-09-18 17:37:47 +08:00 · 1048 次点击
    这是一个创建于 942 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近在看 Raft Consensus Algorithm 相关资料,在Distributed Consensus with Raft - CodeConf 2016 - YouTube中,他说“At most one winner per term”。但是怎么避免下面的情况发生呢?

    假设一共有 3 台机器,一开始大家都是 Follower,m1 得到大多数投票成为 term 1 的 Leader,但是其它机器还处于 term 0 。接下来{m1}和{m2, m3}隔离了,m2 得到大多数投票又成为 term 1 的 Leader 。会发生这种情况吗?如果不会的话。Raft Consensus Algorithm 是怎么避免的?

    相关资料

    第 1 条附言  ·  2021-10-28 13:41:51 +08:00
    3 条回复    2021-09-20 17:14:05 +08:00
    ZingLix
        1
    ZingLix  
       2021-09-18 17:51:20 +08:00   ❤️ 1
    对于任何节点,收到 term 比自己大的请求或回复,都需要将 term 更新并转为 Follower

    m1 能成为 term 1 的 leader 那么说明他发出过 RequestVote 请求(term=1)。

    另两台能够回复同意说明收到该请求,那么这两台收到请求时发现 term 比自己大,那么 term 也会更新为 1,所以其他机器不会 term 仍未 0
    JasonLaw
        2
    JasonLaw  
    OP
       2021-09-18 18:04:06 +08:00
    @ZingLix #1 谢谢

    怪不得视频中其它机器收到 S2 的 RequestVote 请求(term=2)后,term 也会变成 2 。

    &t=669s
    JasonLaw
        3
    JasonLaw  
    OP
       2021-09-20 17:14:05 +08:00
    @JasonLaw #2
    &t=655s 也解答了我的疑问
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4635 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 01:05 · PVG 09:05 · LAX 18:05 · JFK 21:05
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.