In the past, Paxos has been the standard of distributed protocols, but Paxos difficult to understand, more difficult to achieve, Google's distributed lock system Chubby as a Paxos implementation has encountered a lot of pits. The new distributed Protocol research from Stanford, called Raft, is a protocol for real-world applications that focuses on the landing and understanding of protocols. Before we understand raft, we first understand the concept of consensus consistency, which means that multiple servers are in a state of agreement, but in a distributed system, because of various contingencies, some servers may crash or become unreliable, and it cannot reach a consistent state with other servers. This requires a consensus protocol, which is designed to ensure fault tolerance, even if there are one or two servers in the system that do not affect their processing. To be consistent in a fault-tolerant manner, it is not possible to require all server 100% to agree, as long as more than half of the servers agree on the assumption that there are N servers, N/2 +1 is more than half, representing the majority. Paxos and raft are both trying to achieve the goal of consensus consistency, a process that, like an election, needs to convince most voters to vote for him, and then follow it once selected. The difference between Paxos and raft is that the specific process of the election is different. In raft, a server can play one of the following roles at any time: The raft stage is divided into two, first the electoral process, and then the elected leaders lead the normal operations, such as log copying. The following diagram shows the process: 1. Any server can be a candidate candidate, it sends requests to other servers follower to elect its own request: 2. The other server agreed and issued OK. Note If in this process, there is a follower, no request for election, so the candidate can choose their own, as long as the N/2 + 1 of the majority of votes, the candidate can still be leader. 3. This candidate became the leader of the leader, which could send instructions to voters, the follower, for example, to make log copies. 4. Notification of subsequent log replication via Heartbeat 5. If once this leader crashes, then one of the follower becomes a candidate, issuing an invitation to vote. 6. Follower agreed to become a leader, continue to assume the responsibility of log replication, such as: It is noteworthy that the entire electoral process has a time limit, the following figure: Splite vote because if there are two candidates to invite votes, then through similar overtime to solve, Two candidates in a timeout for example300ms after waiting for each other's anger, since the two sides get the same number of votes, half of the half, then after 300ms, and then by the two candidates issued invitations, then the probability is greatly reduced, then the first issue of the invitation to the candidate received the majority of the agreement to become leader leader, When the other candidate later issued an invitation, those follower voters had voted for the first candidate, could not vote for it, it became the loser, and finally the loser became a regular follower. The following is a log copy to illustrate the raft algorithm, assuming that the leader leader has been elected, then the client issued a request to add a log, such as the log is "Sally": 2. Leader asked Followe to follow his instructions and append the new log to their respective logs: 3. Most follower servers write the log to the disk file, confirming the append success and issuing commited Ok:4. In the next heartbeat Heartbeat, Leader notifies all follwer to update the commited project. Repeat the above procedure for each new log record. If a network partition or network communication failure occurs during this process, making leader inaccessible to most follwers, leader can only update the follower servers it can access, and most servers follower because there is no leader , they re elect a candidate as leader, and then this leader as a representative of the outside world, if the outside world required to add a new log, the new leader on the above steps to notify most followers, if the network failure to repair, Then the original leader becomes follower, and any updates to the old leader in the phase of the failure are not a commit, and are rolled back, accepting new updates for the new leader. Summary: At present, almost all languages already have the support Raft algorithm library package, the specific can refer to: Raftconsensus.github.io
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