In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly talks about "what is the Raft consensus algorithm". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what the Raft consensus algorithm is.
Raft algorithm is mainly used in distributed cluster systems. If high availability and data consistency are guaranteed, it mainly defines two specifications: Leader Election and Log Replication.
1. Select the main mechanism
Raft defines three states of cluster nodes: Leader (master), Follower (slave), and Candidate (candidate).
Master: responsible for docking external input and maintaining the heartbeat with followers
Slave: back up the data and carry the heavy burden when the master is dead.
Candidate: change to this state when no master heartbeat is received during the timeout time (150ms to 300ms, each node is different)
Analyze how the elector works in the following situations
a. Normal initial condition
At first, all nodes are in Follower state, and when one of the nodes is in timeout, it changes to Candidate, sends a vote request to the other nodes, and starts a new timeout.
After more than half of the Follower nodes receive the request and reply to the acknowledgement, the Candidate node is transformed into a Leader node and sends a heartbeat to the Follower node.
c. Multiple Follower converted to Candidate at the same time
When there are multiple Candidate, an election request will be sent to the remaining nodes, and the Candidate node will reject the request from other nodes. After receiving the request from one of the Candidate nodes, the Follower node will reject other requests for the same election cycle. If one of the nodes has the consent of half of the nodes, it will automatically become a Leader. If the two Candidate nodes do not distinguish between the winners and losers, the timeout node will initiate the second round election request. At this point, it depends on who ends the timeout first and gets the consent of half of the nodes, then it becomes Leader.
two。 Copy log
Data replication is mainly to ensure the reliability and consistency of the data. When the data changes, Leader synchronizes the data to Follower.
How to perform data replication from the following scenarios
a. Normal situation
It can be divided into eight steps.
Publish data externally to Leader
1.Leader saves the data with a status of uncommit
2.Leader sends data to Follower via appendEntries
3.Follower saves the data with a status of uncommit
4.Follower returns confirmation to Leader
After receiving confirmation from more than half of the Follower, 5.Leader changes the data state to commit
6.Leader returns confirmation
7.Leader sends the data to Follower again through appendEntries
8.Follower changes the data state to commit
B.Network Partition situation
That is, when some nodes are unable to communicate with each other due to network problems
The party without Leader gets the leader through election, and the election round of this Leader is + 1.
At this point, there are two Leader that can provide services to others.
If external data comes in at this time and is passed to L1 and L2 respectively, less than half of the parties have not reached half of the confirmed quantity, so the data are all in uncommit status, and the return is also a failure.
And more than half of the party's data is commit.
At this time, if the network is restored, through the election rules, the Leader with the highest round will continue to be Leader, and the other side will be downgraded to Follower.
At this point, the uncommite data will be deleted and the unsynchronized data will be replenished.
At this point, I believe you have a deeper understanding of "what is the Raft consensus algorithm?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.