In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
What is the election process of zookeeper? in view of this question, this article introduces in detail the corresponding analysis and answers, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
1 election steps
(1) first vote. Regardless of which leads to a Leader election, all machines in the cluster are in a state of trying to elect a Leader, that is, the LOOKING state, and the LOOKING machine sends a message called a vote to all other machines (each machine votes for itself for the first time). The voting contains SID (unique identification of the server) and ZXID (transaction ID), (SID, ZXID) to identify a vote information.
(2) change of vote. After each machine sends out a vote, it will also receive votes from other machines, and each machine will process the votes received by other machines according to certain rules to decide whether it needs to change its own votes. this rule is also the core of the entire Leader election algorithm, in which the terms are described as follows
Vote_sid: the SID of the Leader server elected in the vote received.
Vote_zxid: the ZXID of the Leader server elected in the vote received.
Self_sid: the current server's own SID.
Self_zxid: the current server's own ZXID.
Each time the votes received are processed, they are compared between (vote_sid, vote_zxid) and (self_sid, self_zxid).
Rule 1: if vote_zxid is greater than self_zxid, approve the vote currently received and send the vote again.
Rule 2: if vote_zxid is less than self_zxid, stick to your vote and don't make any changes.
Rule 3: if vote_zxid is equal to self_zxid, then compare the SID of the two. If vote_sid is greater than self_sid, then approve the vote currently received and send it again.
Rule 4: if vote_zxid is equal to self_zxid and vote_sid is less than self_sid, stick to your vote without making any changes.
The flow chart of the above steps is as follows:
(3) determine Leader. After the second round of voting, each machine in the cluster will again receive votes from other machines, and then start counting ballots. If a machine receives more than half of the same votes, then the corresponding SID machine for that vote is Leader.
2 give an example
Suppose that the Zookeeper consists of five machines, and the SID is 1, 2, 3, 4, 5, respectively, and the ZXID is 9, 9, 9, 8, 8, respectively, and the machine with the SID of 2 is a Leader machine. At some point, the machines 1 and 2 fail, so the cluster begins to conduct Leader elections. When voting for the first time, each machine will vote on itself, so the machines with SID of 3, 4 and 5 vote (3,9), (4,8) and (5,8), respectively.
The process is shown below:
The answers to the questions about the election process of zookeeper are shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.