Distributed raft algorithm

Source: Internet
Author: User

Reference article:
"In Search of an understandable Consensus algorithm"
https://raft.github.io/
http://thesecretlivesofdata.com/raft/
Here is a small animation that is well suited to understanding the raft protocol.

1.1.1 Introduction
Concept:
Raft is a consistency protocol for managing log replication, and it has the same functionality as Paxos, but is easier to understand than it is.
Function:
Leader elections, log duplication and security issues. And it provides strong consistency.

1.1.2 Principle
Here, take 3 nodes as an example
Each node has three states: leader, candidate, follower
There are three kinds of behaviors for each group: Leader election, log replication, safety.
1) leader election
When three nodes are started, they are in the candidate state (raft has a time mechanism and then send vote information to other nodes), and when more than half of them become candidate, the status of the other two nodes becomes follower.
All client data is exchanged with leader.
2) Log Replication
Log replication guarantees the consistency of the data in the group. Log entry is the core of this.
is the process

In the third step, the raft protocol uses the append entries message heartbeat detection, if the followers log appends a key value of more than half of the follower, then the fourth step will be leader log commit

In the raft protocol, there are two time-out settings (it controls the election)
Election timeout: It is follower becomes candicate time. Generally set to 150ms to 300ms
If the election times out, then follower becomes candicate and a new round of elections. First of all, candicate a will vote for himself and send me information to the other nodes, and if the node has not yet voted, it will select a, and the node will reset election timeout. Once a gets more than half of the votes, it becomes leader, and leader starts sending append Entries messages to followers, which is sent within heartbeat timeout.
Followers will then respond to append Entries message. The elections will continue to guide a followers to stop receiving heartbeats and become candidate.

Note: If a network partition or network communication failure occurs during log replication, so that leader cannot access most follwers, leader can only update properly the follower servers it can access. And most of the 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 requires it to add new logs, This new leader in accordance with the above steps to notify most followers, if the network failure to repair, then the original leader becomes follower, in the phase of the loss of the old leader any update can not be counted as commit, all rolled back, Accept new updates for the new leader.

Distributed raft algorithm

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.