Principle of leader election

Next, we will analyze the entire implementation process of leader election based on the source code. 

There are two stages of leader election, one is the leader election when the server starts. The other is leader election caused by leader node downtime during operation;

Before starting to analyze the principles of elections, first understand several important parameters

Server ID (myid)

For example, there are three servers, the numbers are 1, 2, and 3. 

The greater the number, the greater the weight in the selection algorithm.

zxid transaction id

The larger the value, the newer the data and the greater the weight in the election algorithm

Logic clock (epoch-logicalclock)

Or called the number of votes, the logical clock value in the same round of voting is the same. This data will increase every time a vote is cast, and then compared with the value in the received voting information returned by other servers, different judgments are made based on different values.

Election status

LOOKING, campaign status.

FOLLOWING, follower status, synchronize leader status, participate in voting.

OBSERVING, observe status, synchronize leader status, and do not participate in voting.

LEADING, leader status.

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/Leon_Jinhai_Sun/article/details/112912801