Consistency Algorithm Quest (Extended Version) 4

Source: Internet
Author: User

5.2 Leader Election

Raft uses a heartbeat mechanism to trigger leader election. When servers start up, they begin as followers. A server remains in follower state as long as it receives valid RPCs from a leader or candidate. Leaders Send periodic heartbeats (appendentries RPCs that carry no log entries) to all followers in order to maintain thei R authority. If a follower receives no communication over a period of time called the election timeout, then it assumes there is no via BLE leader and begins an election to choose a new leader.

to begin an election, a follower increments its current term and transitions to candidate state. It then votes for itself and issues requestvote RPCs on parallel to all of the other servers in the cluster. A candidate continues In this state until one of three things happens: (a) It wins the election, (b) Another ser Ver establishes itself as leader, or  (c) a period of time goes by with no winner. These outcomes is discussed separately in the paragraphs below.

a candidate wins an election if it receives votes from a Majority of the servers in the full cluster for the same term. Each server would vote for at the most one candidate in A given term, on a first-come-first-served basis (note:section 5. 4 adds an additional restriction on votes). The majority rule ensures, at most one candidate can win the election for a particular term (the election Safety Property in Figure 3). Once a candidate wins an election, it becomes leader. It then sends heartbeat messages-of the other servers-establish its authority and prevent new election S.

While waiting for votes, a candidate could receive an appendentries RPC from another server claiming to be leader. If The leader ' s term (included in it RPC) is at least as large as the candidate's current term and then the candidate Recogn Izes the leader as legitimate and returns to follower state. If the term in the RPC is smaller than the candidate's current term, then the candidate rejects the RPC and continues in C Andidate state.

The third possible outcome is, a candidate neither wins nor loses the Election:if many followers become candidates at The same time, votes could is split so that no candidate obtains a majority. When this happens, each candidate would time out and start a new election by incrementing it term and initiating another R Ound of Requestvote RPCs. However, without extra measures split votes could repeat indefinitely.

raft uses randomized election timeouts to ensure that split Votes is rare and that they is resolved quickly. To prevent split votes in the first place, election timeouts Are chosen randomly from a fixed interval (e.g., 150–300 MS). This spreads out of the servers so, most cases only A single server would time out; It wins the election and sends heartbeats before any other servers time out. The same mechanism is used to handle split votes. Each candidate restarts their randomized election timeout at the start of an election, and it waits for that timeout to Elapse before starting the next election; This reduces the likelihood Of another split vote in the new election. Section 9.3 Shows, this approach elects a leader rapidly.

elections is an example of how understandability guided Our choice between design alternatives. Initially we planned to use a ranking System:each candidate was assigned a unique rank, which is used to Selec T between competing candidates. If a candidate discovered another candidate with higher rank, it would "return to Follower state so" the high Er ranking candidate could more easily win the next election. We found that this approach created subtle issues around availability (a lower-ranked server might need to time Out and become a candidate again if a higher-ranked server fails, but if it does so too soon, it can reset Progr ESS towards electing a leader). We made adjustments to the algorithm several times, but After each adjustment new corner cases appeared. Eventually we concluded that the randomized retry approach is more obvious and understandable.

5.2 Leader Elections

Raft uses a heartbeat mechanism to trigger leader elections. When the server starts, they will be in the follower state. The server is in a follower state until it receives a valid RPC of leader or candidate. Leader periodically sends a heartbeat (appendentries RPC without log entries) to follower to maintain permissions. If a follower for a period of time does not get a communication called an election timeout, then it assumes that there is no valid leader, initiating a new election to elect a leader.

To start the election, follower has increased its current term and switched the status to candidate. Then it will vote for itself and send requestvote RPC to other servers in the cluster in a parallel manner. Candidate has remained in this state until one of the following three cases occurred: (a) It won the election, (b) Another server had become leader, and (c) had not produced leader for a period of time. These results are discussed separately below.

A candidate in the same term the majority of the servers in the cluster vote for it and win the election. In a given term, each server casts a maximum of one vote, on a first-come-first-served basis (Note: Section 5.4 Adds additional restrictions on voting). Most of the principles guarantee that in a given term, only one candidate can win the election (Election Safety property in Figure 3). Once the candidate election succeeds, it becomes leader. It then sends a heartbeat to other servers to maintain permissions and prevent new elections from being generated.

While awaiting the polls, candidate may receive appendentries RPC from other servers that are also running for the election. If the term of leader (including its RPC) is equivalent to the term of candidate, then candidate acknowledges the legitimacy of the leader and reverts to follower state. If the term of RPC is smaller than the term of candidate, then candidate will reject the RPC and continue to maintain candidate status.

The third possible result is that a candidate has neither won nor lost: if many follower at the same time become candidate, the ballot will be divided and there will be no candidate to win the majority of votes. When this happens, each candidate will time out, increase their term and start a new round of requestvote RPC to start a new election. However, without any other measures, the ballot papers will be reproduced indefinitely.

Raft with random election timeouts to ensure that the ballot is scattered is a small probability event and can be quickly resolved. To prevent the beginning of the spread of the ballot, the election timeout is randomly selected within a reasonable time interval (e.g. 150-300ms). This makes the server so that in most cases only one server wins the election; It wins the election and sends the heartbeat before the other server times out. The same processing mechanism is also used in the case of voting dispersion. Each candidate to restart its election timeout at the start of the election, and its overtime will continue to increase before the start of a new round of elections, which reduces the likelihood of a new round of electoral polls scattered. Section 9.3 Shows how this strategy can quickly elect a leader.

Elections are an example of how we can easily understand the design options. Initially, we were going to use a ranking system: each candidate assigned a unique ranking to select the candidate candidate. If a candidate finds another candidate ranked higher, it returns to the follower state so that the high-ranked candidate can easily win the next round of elections. We find that this strategy creates a subtle problem with usability (if a high-level server hangs up, the low-ranked servers will time out and re-candidate, but if this happens too quickly, the leader election progress will be reset). We have made several algorithmic adjustments, but each time we adjust we will find a new extreme condition. Finally, we conclude that the random retry method is more obvious and understandable.

Consistency Algorithm Quest (Extended Version) 4

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.