Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

[distributed] Leader Election for Zookeeper-introduction to the Election process

Shulou Source: shulou.com Published: 2022-06-03 05:54:13 10月03日 Update

[distributed] Leader Election in Zookeeper-the election process introduces the beginning of the election, where each server has a vote and will vote for itself to be elected Leader. After the poll is completed, the voting information is sent to all servers in the cluster (the observer server does not participate in the election).

The ballot consists of two parts: the server uniquely identifies the myid and the transaction number zxid, namely (myid,xzid).

The larger the zxid, the newer the data and the greater the weight in the selection algorithm.

The larger the myid, the greater the weight in the selection algorithm.

When comparing the votes, it will first compare the zxid,zxid big winner, when the zxid is the same, the bigger myid,myid will win, the winner's vote will remain the same, the loser's vote will become the same as the winner's, and the vote will be sent out again.

When more than half of the machines receive the same voting information, Leader is selected and the election is over.

For example:

There are three servers in the campaign, myid: 1, 2, 3, Zxid: 9, 9, 8, respectively.

The election process is as follows:

A received ballots (2jue 9), (3jue 8). Compared with his own (1rem 9), the ballots were changed to (2jue 9) and cast.

The votes received by B are (1) and (3), respectively. Compared with his (2), the result remains the same.

The votes received by C are (1) and (2) respectively. Compared with their own (3), the votes are changed to (2) and cast.

At this time, Machine B has more than half of the votes and is elected Leader.

As you can see from the above rules, the newer the data on that server (the larger the ZXID will be), the more likely it is to become a Leader, and the more guaranteed the data can be recovered. If the ZXID is the same, the larger the myid, the greater the chance.

Reference:

Http://www.cnblogs.com/leesf456/p/6107600.html

Https://www.cnblogs.com/yuyijq/p/4116365.html

Http://www.cnblogs.com/ASPNET2008/p/6421571.html

Tags: Ballot election server service voting same data process information machine weight algorithm interest party not for selection distributed transaction its success again references Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Redmi MariaDB Docker Microsoft