ZooKeeper 选举过程

 

https://www.tutorialspoint.com/zookeeper/zookeeper_leader_election.htm

 

1 .All the nodes create a sequential, ephemeral znode with the same path, /app/leader_election/guid_.

 

2. ZooKeeper ensemble will append the 10-digit sequence number to the path and the znode created will be /app/leader_election/guid_0000000001, /app/leader_election/guid_0000000002, etc.

 

3. For a given instance, the node which creates the smallest number in the znode becomes the leader and all the other nodes are followers.

 

4. Each follower node watches the znode having the next smallest number. For example, the node which creates znode /app/leader_election/guid_0000000008 will watch the znode /app/leader_election/guid_0000000007 and the node which creates the znode /app/leader_election/guid_0000000007 will watch the znode /app/leader_election/guid_0000000006.

 

5. If the leader goes down, then its corresponding znode /app/leader_electionN gets deleted.

 

6. The next in line follower node will get the notification through watcher about the leader removal.

 

7. The next in line follower node will check if there are other znodes with the smallest number. If none, then it will assume the role of the leader. Otherwise, it finds the node which created the znode with the smallest number as leader.

 

Similarly, all other follower nodes elect the node which created the znode with the smallest number as leader.

 

 

1. 所有节点在相同path下创建各自的临时序列化节点。每个zk都有自己对应的znode。

2. 拥有最小编号的zk是leader,其它的zk是follower。

3. 每个follower观察仅比自己小的那个node。

4. 如果leader下线了,则它对应的节点会删除。

5. 观察这会发现leader被删除了。

6. 观察者会观察是否还有最小的节点,如果有,最小值节点成为leader,否则,观察者成为leader。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值