ZooKeeper election process

 

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. All nodes create their own temporary serialized nodes under the same path. Each zk has its own corresponding znode.

2. The zk with the smallest number is the leader, and the other zk are followers.

3. Each follower observes the node that is only smaller than itself.

4. If the leader goes offline, its corresponding node will be deleted.

5. Observe that the leader is deleted.

6. The observer will observe whether there is still the smallest node, if so, the smallest node becomes the leader, otherwise, the observer becomes the leader.

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326483669&siteId=291194637