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。

猜你喜欢

转载自oracle-api.iteye.com/blog/2359350