Raft algorithm Distributed Consistency Algorithms

In practical applications, for distributed systems, consistency problems encountered, the industry has produced many classic distributed consensus algorithm, previously distributed consensus algorithm projects often are 2PC and Paxos, only know algorithm for Raft name, careful never understood before, until today, and colleagues to chat, suddenly asked, Paxos and Raft difference in what? Why use our project in Paxos produce so many problems, had considered whether the use of Raft algorithm? This question, I do not answer it, because I never thought about how Raft should be applied in distributed database storage system.
Raft algorithm, although only published in 2013, but is widely used, and even become one of the mainstream distributed consensus algorithm.
The basic principle under Raft recorded the following algorithm:
It Paxos similar, there are three roles, namely Leader (leader), Follower (followers), Candidate (candidate). Which Leader role is responsible for receiving client requests, copy the log to inform the other nodes and other nodes when to apply these logs are safe; the role of a Candidate Election Leader's role; the role is to respond Leader or Follower of Candidate request.
Raft algorithms exist three relatively independent sub-problems: leadership election; log replication; security mechanism.
Leadership election
election main strategies: Leader will periodically send a heartbeat packet Follower. Each Follower have set up a random campaign timeout, if the Leader of the heartbeat (assuming that the node where the Leader is down) Follower not received within this time, then the Follower will become Candidate, enter the campaign period.
If a node after the Follower becomes a Candidate, it will create a poll request to other nodes, and the node receiving the request to vote will be the response for the entire cluster, if more than half of the node responds, then this roles node will be transformed by the Candidate for the Leader. Since then, Leader will continue to periodically send a heartbeat packet Follower.
Based on the above policy, for a scene including a plurality of Candidate, only you need to obtain the largest number of votes and the same situation will be re-selected master. In general, each node timeout inconsistent, there is more probability node re-election is not the Lord's.

Log Replication
Consistency Raft algorithm is ensured by log replication, the process is:
(1) client-initiated modification operations are recorded in the cluster Leader. For uncommitted changes recorded in the log.
(2) Leader Replication log Follower all nodes. After Leader received more than half of the Follower node response, the changes are committed.
(3) All this time Leader Follower will notice them also commit changes, the value of all nodes agree.
For the abnormal scenario, the replication process will produce a log log conflict.
Security:
refer to the following articles, to be summarized.
https://github.com/maemual/raft-zh_cn/blob/master/raft-zh_cn.md

Guess you like

Origin www.cnblogs.com/zhaozg/p/11403331.html