A method for adding empty data nodes based on Raft

By creating a comparison log length node in the Raft consensus algorithm, the log replication process of new nodes is optimized, solving the problems of long synchronization time and high Leader load when new nodes are added, achieving efficient log replication and cluster performance improvement.

CN114666206BActive Publication Date: 2024-09-17CHONGQING FUN CHAIN DIGITAL TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210185546.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-28
Publication Date
2024-09-17
Estimated Expiration
2042-02-28

AI Technical Summary

Technical Problem

In the Raft consensus algorithm, when a new node joins, it needs to copy all the data from the Leader, which results in long synchronization time and affects cluster performance. Especially when the amount of data is large and the cluster load is high, the Leader node is overloaded.

Method used

By creating a comparison log length node, the new node compares with its log length. If it is less than the comparison log length, it matches the log replication node. Otherwise, the log is copied according to the original Raft algorithm, reducing unnecessary replication steps and reducing the load on the Leader.

Benefits of technology

It realizes log replication without downtime, reduces the load on the Leader, improves the efficiency of adding new nodes, and solves the problems of long synchronization time and high Leader load.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114666206B
    Figure CN114666206B
Patent Text Reader

Abstract

The invention relates to the field of Raft application technology, and specifically discloses a method for adding an empty data node based on Raft, comprising the following steps: step S001: a user independently creates a comparison log length of a lagging log node; step S002: adding a new node, comparing the log length of the new node with the created comparison log length, if it is less than the comparison log length, matching a log replication node for the new node, if it is not less than the comparison log length, directly replicating the log according to the original Raft algorithm; step S003: when the new node obtains information of the log replication node from the Leader, it starts to request data from the log replication node and replicates the full amount of data, and when the log length of the new node is copied to be consistent with the log length of the log replication node, it is added to the cluster as a normal consensus node. The method solves the problem that the traditional synchronization time of new node addition is very long and the load on the Leader node is high.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of Raft application, and specifically discloses a method for adding a null data node based on Raft. Background Art

[0002] In 2013, 0ngaro et al. proposed the Raft consensus algorithm, which solved the problems of the (multi-)Paxos algorithm protocol that has been complex, difficult to understand, and cannot be directly implemented in engineering for many years. It is also more efficient and energy-saving than the simple proof-of-work or proof-of-stake protocols used in blockchain. In 2019, EBay officially released the open-source implementation of the Raft algorithm NuRaft. Raft has been favored by large companies for its fast and efficient consensus capabilities for large internal servers.

[0003] Raft has the following four advantages over Paxos:

[0004] 1. A complete replication state machine protocol. The Raft protocol is more of a complete replication state machine protocol than a consistency protocol.

[0005] 2. Protocol splitting: Raft protocol divides the entire protocol into four processes: election, log replication, cluster status change, and log compression. It is concise and clear.

[0006] 3. Reduced states. The Raft protocol reduces the states in the entire cluster by adding some strong restrictions to the Paxos protocol. Fewer states means fewer state transitions, which reduces the difficulty of implementation. The biggest improvement is that the status of the leader is greatly strengthened. All logs can only flow from the leader.

[0007] 4. The algorithm is simple and easy to understand. The Raft protocol has made a lot of efforts to ensure the simplicity of the entire protocol. For example, the disjoint consensus algorithm for processing cluster state changes and the random timer algorithm used for re-election when election fails are both very simple and effective.

[0008] In the Raft consensus protocol, there will be a need to add new nodes. At this time, the new node has no data, so this node will copy the full data from the Leader (cluster leader). When the amount of data is large, the synchronization time will be very slow. When the entire cluster load is very high, because there is too much synchronized data, it may even affect the overall performance of the cluster, because the cluster throughput depends on the Leader node. This patent solves the problem of the impact of empty data nodes joining the Raft cluster on the Leader node.

[0009] Therefore, in view of this, the inventor provides a method for adding an empty data node based on Raft to solve the above problem. Summary of the invention

[0010] The purpose of the present invention is to solve the problem that the traditional synchronization time of a new node is very long and the load on the Leader node is high.

[0011] In order to achieve the above object, the basic scheme of the present invention provides a method for adding an empty data node based on Raft;

[0012] Step S001: The user independently creates a comparison log length of a backward log node;

[0013] Step S002: Add a new node, compare the log length of the new node with the created comparison log length, if it is less than the comparison log length, match the log replication node for the new node, if it is not less than the comparison log length, directly replicate the log according to the original Raft algorithm;

[0014] Step S003: When the new node obtains the information of the log replication node from the Leader, it starts to request data from the log replication node and copy the full amount of data. When the log length of the new node is copied to the same as the log length of the log replication node, it joins the cluster as a normal consensus node.

[0015] Furthermore, when multiple new nodes join the cluster at the same time, the Leader will uniformly designate a log replication node to replicate the logs;

[0016] When there are multiple replication log nodes, the Leader selects the nodes whose logs are not behind the cluster for replication.

[0017] Furthermore, when the Leader crashes, the following steps are followed:

[0018] Step A001: All nodes enter the candidate state and participate in the leader election;

[0019] Step A002: After the Leader is reselected, repeat step S002.

[0020] Furthermore, when executing step A002, if a node fails to complete log replication, the new leader will reassign a log replication node to perform subsequent log replication.

[0021] Furthermore, when a log replication node goes down, the Leader will select a node to replicate the log based on the Raft algorithm rules and prioritize system security.

[0022] Furthermore, when a newly created node goes down, the log replication node that matches it will become a normal consensus node;

[0023] When the newly created node is restored, the Leader will designate a node to continue copying the log.

[0024] Furthermore, when a normal node goes down, it is processed according to the original Raft algorithm.

[0025] Compared with the prior art, the present invention has the following beneficial effects:

[0026] 1. The present invention can complete log replication without stopping the system.

[0027] 2. The present invention compares the logs of new nodes by creating an auxiliary node for comparing log lengths. This method can reduce unnecessary replication progress, and the log service does not rely on the bandwidth of the Leader, greatly reducing the load on the Leader.

[0028] 3. Compared with the prior art, the log service of the present invention does not rely on the bandwidth of the Leader, which greatly reduces the load on the Leader. By increasing the log comparison log length node, some unnecessary replication steps can be reduced, solving the problem that the traditional new node joining synchronization time is very long and the load on the Leader node is high. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0030] Figure 1 A flowchart of a method for adding an empty data node based on Raft proposed in an embodiment of the present application is shown;

[0031] Figure 2 A flowchart of a Raft-based empty data node joining method proposed in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0032] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0033] The following is a further detailed description through specific implementation methods:

[0034] A method for adding an empty data node based on Raft is a method for replicating Raft node logs. The method is based on the Raft consensus algorithm. The basic components of the Raft consensus algorithm include a Raft state machine unit, a Raft kernel unit, and a log storage unit. The Raft state machine unit is used to manage the running state of the Raft consensus algorithm in the application node. The Raft kernel unit is used to execute the Raft consensus algorithm to complete the consensus content, construct and process interactive messages, and test the security and correctness of the execution of the Raft consensus algorithm. The log storage unit is used to store the logs generated by the work of all basic components.

[0035] When the Raft kernel unit executes the Raft consensus algorithm, each application node has three states: follower, candidate, and leader.

[0036] At the beginning, all application nodes are in the follower state. Each follower starts a timer and enters the candidate state if it has not received a heartbeat (append message) response from the leader after the timeout.

[0037] The candidate initiates a new election and sends a voting request message containing the current term to the surrounding application nodes. Each follower compares the term contained in the request message (i.e., the priority in the message) with the currently saved target term. If the term in the message is higher, the candidate is supported in the election. The candidate becomes the leader after receiving votes from more than half of the followers. Otherwise, the candidate withdraws from the leader election.

[0038] The leader sends heartbeats to all other application nodes at regular intervals and interacts with application clients to complete corresponding tasks, that is, to process control requests for the replicable state machine for clients. Clients interact with the leader through instructions. The leader adds the current term and an index value to the received client request message. The index value is used to uniquely determine the location of the instruction in the application node log.

[0039] The leader then tries to replicate this instruction to a strict majority of other application nodes. If the replication is successful, the instruction is submitted for execution, executed on the leader's Raft kernel unit, and the result is returned to the client;

[0040] However, application nodes with incomplete logs cannot participate in the election of leaders, so the present invention is mainly implemented for log storage units, which can assist application nodes with complete log information, and ensure that the corresponding nodes can participate in the election while achieving the purpose of the present invention;

[0041] The overall implementation steps can be summarized as follows: If a node's log lags behind the leader by too much, for example, K logs behind, it is considered a new node and is treated as a new node. The leader node will assign a node whose log is not behind the cluster to perform point-to-point log replication. After the replication is completed, the new node will join the cluster.

[0042] The specific implementation steps are as follows:

[0043] Step 1: The user independently creates a node K for comparing log lengths;

[0044] Step 2: When a new node U joins, the leader receives the heartbeat of the new node and finds that the new node lags behind the leader node by K logs. It then starts to match logs to the new node and replicates the logs to node J. If the number is not less than K, the original Raft algorithm is used to replicate the logs.

[0045] Step 3: Node J is designated as the log replica. The leader will not actively send the request of AppendEntries. J will get new logs from another node F regularly. F is designated by the leader, which is usually a node that does not lag behind the cluster log. Then, the information of J will be broadcasted, and F will still participate in the consensus.

[0046] Step 4: When the new node U obtains J's information from the Leader, it starts to request data from J and copy the full amount of data. When the length of the copied data is consistent with J's log, it joins the cluster as a normal consensus node, and the subsequent process is synchronized according to the normal Raft algorithm.

[0047] For the above steps, if the following situations exist, execute them in sequence according to the following rules:

[0048] When multiple new nodes U join the cluster at the same time, the leader will still specify J to replicate the log. If the user sets multiple replication log nodes, the leader will continue to select a node whose log does not lag behind the cluster for replication;

[0049] If the leader goes down, all nodes (including U and J) enter the candidate state and participate in the leader election. After the leader is re-elected, according to the process of step 2, if U has not copied K logs behind, the new leader will again designate the new or old J to perform subsequent log replication;

[0050] If J crashes, the new leader will decide whether to select a new J to replicate the logs based on the Raft algorithm process. System security is still the priority. Otherwise, a new J will continue to be selected for log replication.

[0051] If U goes down, J will become a normal consensus node. When U recovers, the Leader will specify the new or old J to copy the logs.

[0052] If a normal node goes down, it will be processed according to the original Raft algorithm without any special processing;

[0053] U and J complete the point-to-point copy. Since the log interval is less than K at this time, they will recover quickly when they join the cluster again and provide services for cluster redundancy normally.

[0054] Compared with the prior art, the log service of the present invention does not rely on the bandwidth of the Leader, which greatly reduces the load on the Leader. By increasing the log comparison log length node, some unnecessary replication steps can be reduced, solving the problem that the traditional new node joining synchronization time is very long and the load on the Leader node is high.

[0055] Although the above methods are illustrated and described as a series of actions for simplicity of explanation, it should be understood and appreciated that these methods are not limited by the order of actions. According to one or more embodiments, some actions may occur in different orders and / or concurrently with other actions from the illustrations and descriptions herein or not illustrated and described herein but understandable to those skilled in the art. In order to further appreciate that the various illustrative logic blocks, modules, circuits, and algorithm steps described in conjunction with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or a combination of the two. In order to clearly explain this interchangeability of hardware and software, various illustrative components, frames, modules, circuits, and steps are generally described in the form of their functionality above. Whether such functionality is implemented as hardware or software depends on the specific application and the design constraints imposed on the overall system. The technical staff can implement the described functionality in different ways for each specific application, but such implementation decisions should not be interpreted as resulting in a departure from the scope of the present invention. The various illustrative logic blocks, modules, and circuits described in conjunction with the embodiments disclosed herein may be implemented or executed with a general purpose processor, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination thereof designed to perform the functions described herein. A general purpose processor may be a microprocessor, but in an alternative, the processor may be any conventional processor, controller, microcontroller, or state machine. The processor may also be implemented as a combination of computing devices, such as a combination of a DSP and a microprocessor, multiple microprocessors, one or more microprocessors cooperating with a DSP core, or any other such configuration. The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. The software module may reside in RAM memory, flash memory, ROM memory, EPROM memory, EEPROM memory, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor so that the processor can read and write information from / to the storage medium. In an alternative, the storage medium may be integrated into the processor. The processor and the storage medium may reside in an ASIC. The ASIC may reside in a user terminal. In an alternative, the processor and the storage medium may reside in a user terminal as discrete components. In one or more exemplary embodiments, the functions described may be implemented in hardware, software, firmware, or any combination thereof. If implemented as a computer program product in software, the functions may be stored on or transmitted by a computer-readable medium as one or more instructions or codes. Computer-readable media include both computer storage media and communication media, including any media that facilitates the transfer of a computer program from one place to another.Storage media can be any available media that can be accessed by a computer. As an example and not limitation, such computer-readable media may include RAM, ROM, EEPROM, CD-ROM or other optical disk storage, disk storage or other magnetic storage devices, or any other media that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer. Any connection is also properly referred to as a computer-readable medium. For example, if the software is transmitted from a website, server or other remote source using a coaxial cable, fiber optic cable, twisted pair, digital subscriber line (DSL), or wireless technologies such as infrared, radio, and microwaves, the coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwaves are included in the definition of the medium. As used herein, disks and discs include compact discs (CDs), laser discs, optical discs, digital versatile discs (DVDs), floppy disks, and blue-ray discs, wherein disks often reproduce data magnetically, and discs reproduce data optically with lasers. The above combination should also be included in the scope of computer-readable media.

Claims

1. A method for adding an empty data node based on Raft, characterized in that: The steps include: Step S001: The user independently creates a comparison log length of a backward log node; Step S002: Add a new node, which is a node that lags behind the Leader by K logs. Compare the log length of the new node with the created comparison log length. If it is less than the comparison log length, the new node is matched with a log replication node. If it is not less than the comparison log length, the log is directly replicated according to the original Raft algorithm. Step S003: When the new node obtains the information of the log replication node from the Leader, it starts to request data from the log replication node and copy the full amount of data. When the log length of the new node is copied to the same as the log length of the log replication node, it joins the cluster as a normal consensus node.

2. A method for adding an empty data node based on Raft according to claim 1, characterized in that: When multiple new nodes join the cluster at the same time, the Leader will uniformly designate a log replication node to replicate the logs; When there are multiple replication log nodes, the Leader selects the nodes whose logs are not behind the cluster for replication.

3. A method for adding an empty data node based on Raft according to claim 2, characterized in that: When the Leader crashes, proceed as follows: Step A001: All nodes enter the candidate state and participate in the leader election; Step A002: After the Leader is reselected, repeat step S002.

4. A method for adding an empty data node based on Raft according to claim 3, characterized in that: When executing step A002, if a node fails to complete log replication, the new leader will reassign the log replication node to perform subsequent log replication.

5. A method for adding an empty data node based on Raft according to claim 1, characterized in that: When a log replication node goes down, the Leader will select a node to replicate the log based on the Raft algorithm rules and prioritize system security.

6. A method for adding an empty data node based on Raft according to claim 5, characterized in that: When a newly created node goes down, the log replication node that matches it will become a normal consensus node; When the newly created node is restored, the Leader will designate a node to continue copying the log.

7. A method for adding an empty data node based on Raft according to claim 5, characterized in that: When a normal node goes down, it is processed according to the original Raft algorithm.