2 - 一致性算法Raft
2018-05-16 01:55 乱月灵猫 阅读(269) 评论(0) 编辑 收藏 举报Raft要比Paxos更加简单易懂
这是一个Raft的flash演示
下面这篇文章讲解了Raft的leader选举的基本思想
raft论文中文版:
先总结一个大致的内容:
Leader Election
- Rule
- Follower
- Candidate
- Leader
- Timer
- Election Timeout - random time waiting until becomming a candidate 150 - 300ms
- One has reached the election timeout,it becomes a candidate and will ask for vote from other nodes and himself
- Other nodes receive the vote request, and reset the Election Timeout, and send to the Candidate note
- Heartbeat Timeout
- send Append Entries to other followers,
- followers wil reset the Election Timeout
- if the followers does not receive the Append Entriy,and the follow may become a candidate
Log Replication
- leader recevie
- leader send to followers
- follower ack to leader
- lead confirm and set data
- lead ack to followers
- follower confirm and set data
不会出现脑裂的问题,因为如果出现部分网络不通,会选择新的节点作为leader,这样有两个leader,但是由于log replication这个机制,使得没有超过半数的ack,那么数据是不能更新的,所以会导致操作失败,只有在一个集群里的操作是成功的,一旦网络恢复,那么假的leader以及它下面的节点的会回滚自己未提交的操作,然后同步真的leader
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步