Node election method, system, device and equipment based on consistency protocol
By implementing the node election mechanism within the consistent group of distributed systems, the problem of uneven load between node clusters is solved, and the stability and throughput of the system are improved.
Patent Information
- Application Number
- CN202011136140.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-22
- Publication Date
- 2025-03-28
- Estimated Expiration
- 2040-10-22
AI Technical Summary
In distributed systems, uneven load between node clusters leads to stability and throughput problems.
By introducing a node election mechanism within the consistency group, the current node sends a first voting request to other nodes and maintains the leadership status based on the voting results; if there is a node with a high weight value and the log is latest, the node will be triggered to send a second voting request to other nodes to balance the load.
It realizes load balancing between node clusters, improves system stability and throughput, and improves node utilization efficiency.
Smart Images

Figure CN112261135B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of consistency protocol computing, and specifically, to a node election method based on a consistency protocol, a node election system based on a consistency protocol, a node election device based on a consistency protocol, a computer-readable storage medium, and an electronic device. Background Art
[0002] Distributed consistency usually exists in distributed systems such as distributed memory sharing and distributed storage. Generally speaking, consistency algorithms include paxos, gossip, and Raft. Among them, Raft is an algorithm used to ensure strong consistency, which can specifically include the following steps: electing the node with the latest log in the cluster as the leader node, which can be responsible for receiving client requests and copying requests to other nodes in the cluster, and notifying other nodes to submit logs to ensure that all nodes in the cluster maintain consistency.
[0003] In actual applications, there are usually scenarios where nodes overlap between multiple clusters. For example, cluster 1 includes nodes A, B, and C, and cluster 2 includes nodes A, B, and D. If the leader node election is carried out in the above manner, node A can be elected as the leader node of cluster 1 and cluster 2 through a shorter random time and a newer log. In this case, node A needs to be solely responsible for receiving requests for cluster 1 and cluster 2, which is prone to uneven load between node clusters, and thus easily has a negative impact on the stability and throughput of the node clusters.
[0004] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present application, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0005] The purpose of the present application is to provide a node election method based on a consistency protocol, a node election system based on a consistency protocol, a node election device based on a consistency protocol, a computer-readable storage medium and an electronic device, which can solve the problem of uneven load between node clusters, that is, balance the load between node clusters to ensure the stability and throughput of the node clusters.
[0006] Other features and advantages of the present application will become apparent from the following detailed description, or may be learned in part by the practice of the present application.
[0007] According to one aspect of the present application, a node election method based on a consistency protocol is provided, comprising:
[0008] The current node sends a first voting request to other nodes in the consistency group to which it belongs, so that other nodes generate and feedback voting results according to the log information in the first voting request and the target weight value corresponding to the current node;
[0009] If the voting result meets the preset conditions, the current node sends a heartbeat report to other nodes to maintain the leadership status;
[0010] If there is a specific node among other nodes whose weight value is greater than the target weight value, and the specific node corresponds to the latest log information, the current node triggers the specific node to send a second voting request to the remaining nodes in the consistency group to which it belongs.
[0011] According to one aspect of the present application, a node election system based on a consistency protocol is provided, the system comprising a plurality of consistency groups, each consistency group comprising a current node and other nodes, wherein:
[0012] The current node is used to send a first voting request to other nodes in the consistency group to which it belongs;
[0013] Other nodes are used to generate and feedback voting results according to the log information in the first voting request and the target weight value corresponding to the current node;
[0014] The current node is also used to send heartbeat reports to other nodes to maintain the leadership status when the voting results meet the preset conditions;
[0015] The current node is also used to trigger a specific node to send a second voting request to the remaining nodes in the consistency group to which it belongs when there is a specific node whose weight value is greater than the target weight value among other nodes and the specific node corresponds to the latest log information.
[0016] According to one aspect of the present application, a node election device based on a consistency protocol is provided, comprising: an election initiating unit, a heartbeat report sending unit, and an election triggering unit, wherein:
[0017] An election initiating unit, used to send a first voting request to other nodes in the consistency group to which it belongs, so that other nodes generate and feedback voting results according to the log information in the first voting request and the target weight value corresponding to the current node;
[0018] A heartbeat report sending unit, used to send heartbeat reports to other nodes to maintain the leadership state when the voting result meets the preset conditions;
[0019] The election trigger unit is used to trigger a specific node to send a second voting request to other nodes in the consistency group to which it belongs when there is a specific node whose weight value is greater than the target weight value among other nodes and the specific node corresponds to the latest log information.
[0020] In an exemplary embodiment of the present application, before the election initiating unit sends the first voting request to other nodes in the consistency group to which it belongs, it also includes:
[0021] Each node in the node cluster receives the group creation request sent by the client and responds to the group creation request;
[0022] The group building request is used to build at least one consistency group composed of multiple nodes in the node cluster, and the at least one consistency group includes the consistency group to which the current node belongs.
[0023] In an exemplary embodiment of the present application, after the request receiving unit responds to the group establishment request, the method further includes:
[0024] Each node in the node cluster determines a leader node corresponding to each consistency group in at least one consistency group according to multiple weight sequences in the group creation request;
[0025] Among them, the multiple weight sequences correspond one-to-one to at least one consistency group, and the leader node is used to send heartbeat reports to other nodes in the consistency group to which it belongs to maintain the leadership state.
[0026] In an exemplary embodiment of the present application, the election initiating unit sends a first voting request to other nodes in the consistency group to which it belongs, including:
[0027] If the current node does not receive a heartbeat report from the target leader node within a random time period, the current node sends a first voting request to other nodes in the consistency group to which it belongs;
[0028] Among them, the target leader node belongs to the consistency group to which the current node belongs.
[0029] In an exemplary embodiment of the present application, the above-mentioned device further includes:
[0030] A term update unit, used to update the target term value before the election initiating unit sends the first voting request to other nodes in the consistency group to which it belongs, and generate the first voting request according to the target log identifier and the updated target term value;
[0031] The log information in the first voting request at least includes a target log identifier and an updated target term value; the target log identifier is used to record the number of log entries.
[0032] In an exemplary embodiment of the present application, the voting result includes a favorable result and a unfavorable result. Other nodes generate and feedback the voting result according to the log information in the first voting request and the target weight value corresponding to the current node, including:
[0033] Other nodes compare the target term value with their own term value, and compare the target log identifier with their own log identifier;
[0034] If the target term value is greater than its own term value, and the target log identifier is greater than its own log identifier, other nodes generate a favorable result and feed it back to the current node;
[0035] If the target term value is greater than its own term value, and the target log identifier is equal to its own log identifier, other nodes will compare the target weight value with their own weight value. If the target weight value is greater than or equal to its own weight value, other nodes will generate a favorable result and feedback to the current node.
[0036] If the target term value is greater than its own term value, and the target log identifier is less than its own log identifier, other nodes generate objection results and feed them back to the current node;
[0037] If the target term value is greater than its own term value, the target log identifier is equal to its own log identifier, and the target weight value is less than its own weight value, other nodes generate objection results and feed them back to the current node.
[0038] In an exemplary embodiment of the present application, the preset conditions include: the voting results fed back by the specific node are all affirmative results, and more than half of all the voting results are affirmative results.
[0039] In an exemplary embodiment of the present application, after the current node sends a heartbeat report to other nodes to maintain the leadership state, the process further includes:
[0040] Other nodes receive the heartbeat report and convert the current state of the non-following state to the following state; wherein the other nodes include the target leader node.
[0041] In an exemplary embodiment of the present application, the above-mentioned device further includes a state conversion unit, wherein:
[0042] The state conversion unit is used to convert the current state into the leading state, and the current node after the state conversion is the new target leading node.
[0043] In an exemplary embodiment of the present application, the election triggering unit triggers a specific node to send a second voting request to other nodes in the consistency group to which it belongs, including:
[0044] A timeout request is sent to the specific node, so that the timeout request triggers the specific node to send a second voting request to the remaining nodes.
[0045] In an exemplary embodiment of the present application, the above-mentioned device further includes a determination unit, wherein:
[0046] The determination unit is used to determine that the specific node corresponds to the latest log information before the election trigger unit triggers the specific node to send a second voting request to the remaining nodes in the consistency group to which it belongs, and when it is detected that the log information of the specific node is consistent with the log information of the current node.
[0047] According to one aspect of the present application, an electronic device is provided, comprising: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to execute any one of the above-mentioned methods by executing the executable instructions.
[0048] According to one aspect of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, any one of the methods described above is implemented.
[0049] According to one aspect of the present application, a computer program product or a computer program is provided, the computer program product or the computer program comprising computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the methods provided in the above-mentioned various optional implementations.
[0050] The exemplary embodiments of the present application may have some or all of the following beneficial effects:
[0051] In a node election method based on a consistency protocol provided in an example implementation of the present application, the current node sends a first voting request to other nodes in the consistency group to which it belongs, so that other nodes generate and feedback voting results based on the log information in the first voting request and the target weight value corresponding to the current node; if the voting result meets the preset conditions, a heartbeat report is sent to other nodes to maintain the leadership state; if there is a specific node with a weight value greater than the target weight value among other nodes, and the specific node corresponds to the latest log information, the specific node is triggered to send a second voting request to the remaining nodes in the consistency group to which it belongs. According to the above scheme description, on the one hand, the present application can balance the load between node clusters to ensure the stability and throughput of the node cluster. On the other hand, the present application can improve the utilization efficiency of nodes in the node cluster.
[0052] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] The drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present application, and together with the specification are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0054] Figure 1 A schematic diagram showing an exemplary system architecture of a node election method based on a consistency protocol and a node election device based on a consistency protocol to which an embodiment of the present application can be applied;
[0055] Figure 2 A schematic diagram showing the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown;
[0056] Figure 3 A flowchart of a node election method based on a consistency protocol according to an embodiment of the present application is schematically shown;
[0057] Figure 4 A schematic diagram of a node cluster according to an embodiment of the present application is shown schematically;
[0058] Figure 5 A schematic diagram of a node cluster according to an embodiment of the present application is shown schematically;
[0059] Figure 6 A schematic diagram of a consistency group in an embodiment of the present application is schematically shown;
[0060] Figure 7 A flowchart of a node election method based on a consistency protocol according to an embodiment of the present application is schematically shown;
[0061] Figure 8 The structure diagram of a node election system based on a consistency protocol according to an embodiment of the present application is schematically shown;
[0062] Fig. 9 The structural block diagram of a node election device based on a consistency protocol in one embodiment of the present application is schematically shown. DETAILED DESCRIPTION
[0063] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein; on the contrary, these embodiments are provided so that the present application will be more comprehensive and complete, and the concept of the example embodiments will be fully conveyed to those skilled in the art. The described features, structures, or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present application. However, those skilled in the art will appreciate that the technical solutions of the present application may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present application.
[0064] In addition, the accompanying drawings are only schematic illustrations of the present application and are not necessarily drawn to scale. The same reference numerals in the figures represent the same or similar parts, and thus their repeated description will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or implemented in one or more hardware modules or integrated circuits, or implemented in different networks and / or processor devices and / or microcontroller devices.
[0065] Figure 1 A schematic diagram of the system architecture of an exemplary application environment of a node election method based on a consistency protocol and a node election device based on a consistency protocol to which the embodiments of the present application can be applied is shown.
[0066] like Figure 1 As shown, the system architecture 100 may include one or more of terminal devices 101, 102, 103, a network 104, and a server cluster 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server cluster 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc. The terminal devices 101, 102, 103 may be various electronic devices with display screens, including but not limited to desktop computers, portable computers, smart phones, tablet computers, etc. It should be understood that Figure 1The number of terminal devices, networks and servers in is only illustrative. Depending on the implementation needs, there can be any number of terminal devices, networks and servers. In addition, the server cluster 105 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited to this. The terminal and the server can be directly or indirectly connected via wired or wireless communication, and this application is not limited here.
[0067] It should be noted that the above-mentioned cloud server can provide basic cloud computing services using cloud technology. Cloud technology refers to a hosting technology that unifies a series of resources such as hardware, software, and network in a wide area network or local area network to achieve data calculation, storage, processing, and sharing.
[0068] Cloud storage included in basic cloud computing services is a new concept that extends and develops from the concept of cloud computing. Distributed cloud storage system (hereinafter referred to as storage system) refers to a storage system that uses cluster applications, grid technology, and distributed storage file systems to bring together a large number of storage devices of various types (storage devices are also called storage nodes) in the network to work together through application software or application interfaces to provide data storage and business access functions. At present, the storage method of the storage system is to create a logical volume. When creating a logical volume, a physical storage space is allocated to each logical volume. The physical storage space may be composed of disks of a storage device or several storage devices. The client stores data on a logical volume, that is, the data is stored on the file system. The file system divides the data into many parts, each of which is an object. The object not only contains data but also contains additional information such as data identification (ID, ID entity). The file system writes each object into the physical storage space of the logical volume, and the file system records the storage location information of each object. Therefore, when the client requests to access the data, the file system can allow the client to access the data according to the storage location information of each object. The process of the storage system allocating physical storage space to a logical volume is as follows: based on the estimated capacity of the objects stored in the logical volume (this estimate often has a large margin relative to the actual capacity of the objects to be stored) and the grouping of independent redundant disk arrays (RAID, Redundant Array of Independent Disk), the physical storage space is divided into stripes in advance. A logical volume can be understood as a stripe, thereby allocating physical storage space to the logical volume.
[0069] The node election method based on the consistency protocol provided in the embodiment of the present application is generally executed by the server cluster 105. Accordingly, the node election device based on the consistency protocol is generally set in each server of the server cluster 105. It should be noted that each server in the server cluster 105 is used to deploy the node defined by the consistency protocol; the server cluster 105 may include one or more consistency groups, each consistency group includes multiple nodes (such as 3 nodes), and different consistency groups correspond to the same number of nodes, but their corresponding node numbers may be the same or different.
[0070] For example, in an exemplary embodiment, each node in the server cluster 105 (also referred to as a node cluster) receives a grouping request sent by the terminal device 101, 102 and / or 103 through the network 104 and responds to the grouping request. The grouping request is used to build at least one consistency group consisting of multiple nodes in the node cluster.
[0071] Furthermore, the current node in the server cluster 105 can send a first voting request to other nodes in the consistency group to which it belongs, so that other nodes generate and feedback the voting results based on the log information in the first voting request and the target weight value corresponding to the current node; if the voting result meets the preset conditions, a heartbeat report is sent to other nodes to maintain the leadership status; if there is a specific node among the other nodes whose weight value is greater than the target weight value, and the specific node corresponds to the latest log information, the specific node is triggered to send a second voting request to the remaining nodes in the consistency group to which it belongs.
[0072] Figure 2 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown.
[0073] It should be noted that Figure 2 The computer system 200 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0074] like Figure 2 As shown, the computer system 200 includes a central processing unit (CPU) 201, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 202 or a program loaded from a storage part 208 into a random access memory (RAM) 203. Various programs and data required for system operation are also stored in the RAM 203. The CPU 201, the ROM 202, and the RAM 203 are connected to each other via a bus 204. An input / output (I / O) interface 205 is also connected to the bus 204.
[0075] The following components are connected to the I / O interface 205: an input section 206 including a keyboard, a mouse, etc.; an output section 207 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 208 including a hard disk, etc.; and a communication section 209 including a network interface card such as a LAN card, a modem, etc. The communication section 209 performs communication processing via a network such as the Internet. A drive 210 is also connected to the I / O interface 205 as needed. A removable medium 211, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 210 as needed, so that a computer program read therefrom is installed into the storage section 208 as needed.
[0076] In particular, according to an embodiment of the present application, the process described below with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication part 209, and / or installed from a removable medium 211. When the computer program is executed by the central processing unit (CPU) 201, various functions defined in the method and apparatus of the present application are executed.
[0077] The consensus protocol is generally used in scenarios that require strong consistency. Generally speaking, the nodes defined by the Raft protocol include leader nodes and follower nodes. The leader node not only receives client requests, but also needs to synchronize data with the follower nodes, while the follower nodes only need to receive synchronization data requests from the leader node. It can be seen that the pressure on the leader node is significantly greater than that on the follower node.
[0078] In the prior art, leader nodes are usually randomly distributed in a node cluster. Assuming that each node participates in N RaftGroups, the probability that the node is a K leader node is (1 / 3)^K*(2 / 3)^(NK). If the leader nodes are evenly distributed, the node should be N / 3 leader nodes. However, in a random situation, there is a high probability that the node has more than N / 3 leader nodes, which can easily cause the problem of unbalanced node load, thereby affecting the stability and throughput of the node cluster.
[0079] Based on the above problems, this example implementation provides a node election method based on a consistency protocol. Figure 3 , Figure 3 The flowchart of the node election method based on the consistency protocol according to an embodiment of the present application is schematically shown. Figure 3 As shown, the node election method based on the consistency protocol may include the following steps S310 to S330:
[0080] Step S310: the current node sends a first voting request to other nodes in the consistency group to which it belongs, so that other nodes generate and feed back voting results according to the log information in the first voting request and the target weight value corresponding to the current node.
[0081] Step S320: If the voting result meets the preset conditions, the current node sends a heartbeat report to other nodes to maintain the leadership status.
[0082] Step S330: If there is a specific node among other nodes whose weight value is greater than the target weight value, and the specific node corresponds to the latest log information, the current node triggers the specific node to send a second voting request to the remaining nodes in the consistency group to which it belongs.
[0083] Implementation Figure 3 The method shown can balance the load among the node clusters to ensure the stability and throughput of the node clusters. In addition, the utilization efficiency of the nodes in the node clusters can be improved.
[0084] Next, the above steps of this exemplary embodiment are described in more detail.
[0085] In step S310, the current node sends a first voting request to other nodes in the consistency group to which it belongs, so that the other nodes generate and feed back voting results according to the log information in the first voting request and the target weight value corresponding to the current node.
[0086] Among them, the first voting request is used to request other nodes to feedback the approval result or disapproval result to the current node. The approval result is used to indicate approval of the current node being elected as the leader node, and the disapproval result is used to indicate disapproval of the current node being elected as the leader node. If the current node is elected as the leader node, other nodes automatically become follower nodes. After the current node sends the first voting request and before it is elected as the leader node, the current node is in a candidate state, that is, the current node temporarily becomes a candidate node. In addition, the log information in the first voting request is used to characterize the log storage and term of office of the current node, and the target weight value corresponding to the current node is a preset value.
[0087] Specifically, the embodiments of the present application can be applied to a server cluster, and each server in the server cluster is used to deploy nodes defined by a consistency protocol; wherein the consistency protocol can be a Raft protocol, in which a plurality of consistency groups (Group) can be included, each consistency group can be composed of a plurality of nodes, and a consistency group includes a leader node (Leader) and a plurality of follower nodes (Follower).
[0088] See also Figure 4 , Figure 4 A schematic diagram of a node cluster according to an embodiment of the present application is shown schematically. Figure 4As shown, the node cluster 400 may include multiple consistency groups, namely, consistency group A401, consistency group B402 and consistency group C403. Each consistency group is composed of multiple nodes, and different consistency groups may contain one or more identical nodes, or may not contain the same nodes. It should be noted that each node in the node cluster 400 is deployed in a different server, so the node cluster 400 can also be called a server cluster. Each node in the consistency group A401, consistency group B402 and consistency group C403 can execute the node election method based on the consistency protocol in the embodiment of the present application.
[0089] See also Figure 5 , Figure 5 The schematic diagram of a node cluster according to an embodiment of the present application is shown schematically. In particular, Figure 5 As shown, multiple consistency groups included in node cluster 500 may be composed of the same nodes, that is, consistency group A 501, consistency group B 502, and consistency group C 503 are all composed of nodes 510, 520, and 530. Different consistency groups may be used to perform different types of storage tasks.
[0090] For example, the weight sequence corresponding to consistency group A501 is (1,0,0), node 510 in consistency group A501 corresponds to weight 1, and nodes 520 and 530 in consistency group A501 correspond to weight 0; the weight sequence corresponding to consistency group B502 is (0,1,0), node 520 in consistency group B502 corresponds to weight 1, and nodes 510 and 530 in consistency group B502 correspond to weight 0; the weight sequence corresponding to consistency group C501 is (0,0,1), node 520 in consistency group C501 corresponds to weight 1, and nodes 510 and 530 in consistency group C501 correspond to weight 0.
[0091] As an optional embodiment, before the current node sends a first voting request to other nodes in the consistency group to which it belongs, the above method also includes: each node in the node cluster receives a group building request sent by the client and responds to the group building request; wherein the group building request is used to build at least one consistency group composed of multiple nodes in the node cluster, and the at least one consistency group includes the consistency group to which the current node belongs.
[0092] In combination with the above examples and this embodiment, each node in the node cluster 500 can receive a group building request sent by the client; wherein the group building request may include weight sequences corresponding to consistency group A501, consistency group B502 and consistency group C503 respectively, and the group building request is used to request the construction of consistency group A501, consistency group B502 and consistency group C503.
[0093] It can be seen that implementing this optional embodiment can build one or more required consistency groups according to the group building request sent by the client, so as to balance the load of each node according to the weight sequence in the group building request and avoid different consistency groups corresponding to the same leader node.
[0094] As an optional embodiment, after responding to the group creation request, the above method also includes: each node in the node cluster determines the leader node corresponding to each consistency group in at least one consistency group based on multiple weight sequences in the group creation request; wherein, the multiple weight sequences correspond one-to-one to at least one consistency group, and the leader node is used to send heartbeat reports to other nodes in the consistency group to which it belongs to maintain the leadership status.
[0095] Among them, the weight sequence is used to represent the possibility of different nodes in a consistency group being selected as the leader node. The higher the weight value of the node participating in the election, the higher the possibility of being selected as the leader node.
[0096] In combination with the above example and this embodiment, the node 510 in the node cluster 500 can determine itself as the leader node in the consistency group A 501, the follower node in the consistency group B 502, and the follower node in the consistency group C 503 according to the weight sequence (1, 0, 0), (0, 1, 0), and (0, 0, 1). Similarly, the node 520 can determine itself as the leader node in the consistency group B 502 according to the above weight sequence, and the node 530 can determine itself as the leader node in the consistency group C 503 according to the above weight sequence.
[0097] Among them, nodes 510, 520 and 530 can all be the above-mentioned current nodes. Consistency group A501, consistency group B502 and consistency group C503 perform the same node election method based on the consistency protocol in the embodiment of the present application. Taking consistency group A501 as an example, please refer to Figure 6 , Figure 6 A schematic diagram of a consistency group in an embodiment of the present application is shown schematically.
[0098] like Figure 6 As shown, consistency group A600 includes: node 611 deployed on server 610, node 621 deployed on server 620, and node 631 deployed on server 630; wherein, node 611, node 621, and node 631 can be analogous to node 510, node 520, and node 530.
[0099] Specifically, after receiving the request sent by the client to request the establishment of a group consisting of nodes 611, 621 and 631, nodes 611, 621 and 631 can respond to the request to establish a consistency group A600. Since the request to establish a group includes the weight sequence (1, 0, 0) corresponding to the consistency group A600, node 611 can determine itself as the target leader node according to the weight sequence (1, 0, 0), and nodes 621 and 631 can determine themselves as follower nodes according to the weight sequence (1, 0, 0); the target leader node corresponds to the consistency group A600.
[0100] Furthermore, node 611 can send a heartbeat report to nodes 621 and 631 as follower nodes as a target leader node according to a preset duration (e.g., 5ms); wherein the heartbeat report can be a data packet used to maintain the leadership state. However, when the server 610 on which node 611 is deployed is down, node 611 cannot send a heartbeat report, and node 621 and node 631 cannot receive a heartbeat report at the end of their respective corresponding random durations. At this time, the node with the earliest end of the random duration among nodes 621 and 631 can serve as the leader node for the next term of the above-mentioned current node election.
[0101] It can be seen that the implementation of this optional embodiment can balance the load of each node according to the weight sequence in the group creation request, avoiding different consistency groups corresponding to the same leader node.
[0102] As an optional embodiment, the current node sends a first voting request to other nodes in the consistency group to which it belongs, including: if the current node does not receive a heartbeat report sent by the target leader node within a random time period, the current node sends a first voting request to other nodes in the consistency group to which it belongs; wherein, the target leader node belongs to the consistency group to which the current node belongs.
[0103] Combination Figure 6 In this embodiment, if the random duration corresponding to node 621 is 6ms and the random duration corresponding to node 631 is 10ms, after node 611 crashes, node 621 ends the random duration earlier than node 631. Therefore, node 621 can send the first voting request to other nodes in the consistency group to which it belongs as the current node; wherein the first voting request is used to request other nodes to generate voting results and feedback.
[0104] In addition, it should be noted that in the node cluster 500, different nodes can generate their own corresponding random durations, which are used to limit the maximum reception time of the heartbeat report. If the heartbeat report is not received within the random duration, the node can participate in the leadership node election for the next term.
[0105] In addition, it should be noted that the random durations of nodes in different terms can be the same or different. For example, during the term of node 611 as the leader node, the term values corresponding to nodes 611, 621, and 631 are all 1, and the random durations corresponding to nodes 621 and 631 are 6ms and 10ms, respectively. Node 611 sends heartbeat reports to nodes 621 and 631 at 5ms.
[0106] When node 611 goes down and node 621 does not receive a node heartbeat report after 6ms, the target term value is updated from 1 to 2, and a first voting request containing the target term value is sent to node 611 and node 631 to request node 611 and node 631 to elect node 621 as the leader node; wherein the target term value is the term value corresponding to node 621.
[0107] Node 611 and node 631 can compare the target term value with their own term value, and can compare the target log identifier in the first voting request with their own log identifier. If the target term value is greater than their own term value, and the target log identifier is greater than or equal to their own log identifier, they can feedback the approval result to node 621; if the target log identifier is equal to their own log identifier, they compare the target weight value with their own weight value. If the target weight value is greater than or equal to their own weight value, they can feedback the approval result to node 621. At the same time, both node 611 and node 631 update their own term values from 1 to 2. In other cases except the above, node 611 and node 631 can feedback the opposition result to node 621.
[0108] If node 621 receives the approval result fed back by node 611 and / or node 631 , the target leader node (ie, node 611 ) is replaced to become the new leader node (ie, node 621 ).
[0109] It can be seen that by implementing this optional embodiment, when the heartbeat report of the leader node is not received, a new leader node can be elected to ensure that data can be read and written normally.
[0110] As an optional embodiment, before the current node sends the first voting request to other nodes in the consistency group to which it belongs, the method also includes: the current node updates the target term value, and generates a first voting request based on the target log identifier and the updated target term value; wherein the log information in the first voting request includes at least the target log identifier and the updated target term value; the target log identifier is used to record the number of log entries.
[0111] The target term value and the target log identifier both correspond to the current node. The log information in the first voting request may also include log content, which is used to record in detail the read / write operation corresponding to each log. For example, if node 621 stores 5 log contents, then the target log identifier corresponding to node 621 is 5.
[0112] It can be seen that the implementation of this optional embodiment can timely elect a new leader node when the target leader node cannot send a heartbeat report in time (such as when it crashes), so as to avoid the situation where read and write operations cannot be recorded in time.
[0113] As an optional embodiment, the voting result includes a approval result and a disapproval result. Other nodes generate and feedback the voting result according to the log information in the first voting request and the target weight value corresponding to the current node, including:
[0114] Other nodes compare the target term value with their own term value, and compare the target log identifier with their own log identifier;
[0115] If the target term value is greater than its own term value, and the target log identifier is greater than its own log identifier, other nodes generate a favorable result and feed it back to the current node;
[0116] If the target term value is greater than its own term value, and the target log identifier is equal to its own log identifier, other nodes will compare the target weight value with their own weight value. If the target weight value is greater than or equal to its own weight value, other nodes will generate a favorable result and feedback to the current node.
[0117] If the target term value is greater than its own term value, and the target log identifier is less than its own log identifier, other nodes generate objection results and feed them back to the current node;
[0118] If the target term value is greater than its own term value, the target log identifier is equal to its own log identifier, and the target weight value is less than its own weight value, other nodes generate objection results and feed them back to the current node.
[0119] Combination Figure 6 In this embodiment, when node 621 is running for a new leader node and the term value is 2, node 611 and node 631 are other nodes. Both node 611 and node 631 can execute the steps of the above embodiment, taking node 611 as an example.
[0120] Node 611 may compare the target term value (ie, the term value of node 621) with its own term value (ie, the term value of node 611). If the target term value is less than or equal to its own term value, an objection result is generated and fed back to the current node.
[0121] If the target term value is greater than its own term value, node 611 can compare the target log identifier (i.e., the log identifier of node 621) with its own log identifier (i.e., the log identifier of node 611). If the target log identifier is smaller than its own log identifier, an objection result is generated and fed back to the current node.
[0122] If the target log identifier is equal to its own log identifier, node 611 can compare the target weight value (i.e., the weight value of node 621) with its own weight value (i.e., the weight value of node 611). If the target weight value is less than its own weight value, an opposing result is generated and fed back to the current node.
[0123] If the target weight value is greater than or equal to its own weight value, node 611 can generate a favorable result and feed it back to the current node. If the target weight value is less than its own weight value, node 611 can generate a negative result and feed it back to the current node.
[0124] If the target log identifier is greater than the own log identifier, node 611 may generate a consent result and feed it back to the current node.
[0125] If the target log identifier is smaller than the own log identifier, node 611 may generate an objection result and feed it back to the current node.
[0126] It can be seen that the implementation of this optional embodiment can elect a new leader node by using the log identifier, term value and weight value, wherein the weight value is used as an election reference condition to adjust the node load and avoid a node serving as the leader node of multiple consistency groups at the same time, so as to ensure the stability and throughput of the node cluster.
[0127] In step S320, if the voting result meets the preset conditions, the current node sends a heartbeat report to other nodes to maintain the leadership status.
[0128] Based on the above embodiment, the above preset conditions may include: the voting results fed back by the specific node (i.e., the node with a weight value higher than the target weight value) are all affirmative results, and more than half of all voting results are affirmative results. Among them, more than half of all voting results are affirmative results can be expressed as: (number of affirmative results / number of all voting results)>(1 / 2).
[0129] In addition, the current node in the leadership state is the leader node.
[0130] As an optional embodiment, after the current node sends a heartbeat report to other nodes to maintain the leadership state, the method further includes: the other nodes receive the heartbeat report and convert the current state of the non-following state to the following state; wherein the other nodes include the target leader node.
[0131] Specifically, after the current node is elected as the leader node, it can send heartbeat reports to other nodes according to a preset duration.
[0132] The manner in which other nodes receive the heartbeat report and convert the current state of the non-following state to the following state may be: other nodes receive the heartbeat report and detect whether the current state is the following state; if not, convert the current state of the non-following state to the following state; if yes, maintain the following state. Among other nodes, there is a leader node of the previous term (i.e., the target leader node mentioned above). For example, if the current node is node 621 and the leader node of the previous term is node 611, then node 611 may convert the current state from the leader state to the following state, and node 631 maintains the following state.
[0133] It can be seen that by implementing this optional embodiment, the election of the leader node can be completed with reference to the weight value, which is beneficial to node load balancing and thus helps to ensure the stability and throughput of the node cluster.
[0134] As an optional embodiment, the method further includes: the current node converts the current state into a leading state, and the current node after the state conversion becomes the new target leading node.
[0135] Specifically, when the current node becomes the new target leader node, the old target leader node can receive the heartbeat report sent by the current node after recovery, and then change the current state to the follower state, that is, become a follower node.
[0136] It can be seen that by implementing this optional embodiment, the leader node can be elected with reference to the weight value, which can be beneficial to node load balancing.
[0137] In step S330, if there is a specific node among other nodes whose weight value is greater than the target weight value, and the specific node corresponds to the latest log information, the current node triggers the specific node to send a second voting request to the remaining nodes in the consistency group to which it belongs.
[0138] Among them, the number of specific nodes in the consistency group can be 0, 1, 2,..., and the embodiment of the present application is not limited. That is to say, in the consistency group, the number of nodes with higher weight values than the current node can be zero, one or more.
[0139] In addition, the second voting request is used to request to become the leader node of the next term. For example, if the specific node is node 611, the remaining nodes include node 631 and node 621. When node 611 receives a timeout request sent by the leader node of the current term (such as node 621), it can update the term value from 2 to 3 and send a second voting request to the remaining nodes.
[0140] As an optional embodiment, before the current node triggers the specific node to send a second voting request to the remaining nodes in the consistency group to which it belongs, the above method also includes: if it is detected that the log information of the specific node is consistent with the log information of the current node, the current node determines that the specific node corresponds to the latest log information.
[0141] Specifically, the above method also includes: detecting whether the log identifier in the log information of the specific node is the same as the log identifier in the log information of the current node. If they are the same, it means that the specific node has been synchronized to the latest log, and then, it can be determined that the log information of the detected specific node is consistent with the log information of the current node.
[0142] It can be seen that the implementation of this optional embodiment can ensure load balancing of each node, thereby ensuring the stability and throughput of the node cluster.
[0143] As an optional embodiment, the current node triggers the specific node to send a second voting request to the remaining nodes in the consistency group to which it belongs, including: the current node sends a timeout request to the specific node, so that the timeout request triggers the specific node to send a second voting request to the remaining nodes.
[0144] Specifically, the timeout request is used to trigger a specific node to run for the leader node of the next term.
[0145] Before the current node triggers the specific node to send a second voting request to the remaining nodes in the consistency group to which it belongs, it may also include: detecting whether the specific node has the latest log information according to a preset time length. If not, the current node will send the current log content of the current node to the specific node for log synchronization; further detecting whether the specific node has the latest log information. If so, the above-mentioned current node can trigger the specific node to send a second voting request to the remaining nodes in the consistency group to which it belongs.
[0146] It can be seen that by implementing this optional embodiment, if the current leading node in the consistency group is not the node with the highest weight, the node with the highest weight can be triggered in time to run for the leading node for the next term when it synchronizes to the latest log. Since the election refers to the weight factor, the node with a higher weight is more likely to be elected as the leading node if other conditions are not lagging behind. In this way, the node with the highest weight in each consistency group can be elected as the leading node as much as possible, so as to ensure the load balance of each node, and then ensure the stability and throughput of the node cluster.
[0147] See also Figure 7 , Figure 7 The flowchart of the node election method based on the consistency protocol according to an embodiment of the present application is schematically shown. Figure 7As shown, the node election method based on the consistency protocol may include: steps S700 to S722.
[0148] Step S700: Each node in the node cluster receives a group building request sent by the client and responds to the group building request; wherein the group building request is used to build at least one consistency group composed of multiple nodes in the node cluster, and the at least one consistency group includes the consistency group to which the current node belongs.
[0149] Step S702: Each node in the node cluster determines the leader node corresponding to each consistency group in at least one consistency group based on multiple weight sequences in the group creation request; wherein, the multiple weight sequences correspond one-to-one to at least one consistency group, and the leader node is used to send heartbeat reports to other nodes in the consistency group to which it belongs to maintain the leadership status.
[0150] Step S704: The current node updates the target term value and generates a first voting request based on the target log identifier and the updated target term value; wherein the log information in the first voting request includes at least the target log identifier and the updated target term value; the target log identifier is used to record the number of log entries.
[0151] Step S706: If the current node does not receive a heartbeat report sent by the target leader node within a random time period, the current node sends a first voting request to other nodes in the consistency group to which it belongs, so that other nodes generate and feedback voting results based on the log information in the first voting request and the target weight value corresponding to the current node; wherein, the target leader node belongs to the consistency group to which the current node belongs.
[0152] Step S708: If the current node does not receive a heartbeat report sent by the target leader node within a random time period, the current node sends a first voting request to other nodes in the consistency group to which it belongs; wherein the target leader node belongs to the consistency group to which the current node belongs.
[0153] Step S710: Other nodes compare the target term value with their own term value, and compare the target log identifier with their own log identifier. If the target term value is greater than their own term value, and the target log identifier is greater than their own log identifier, execute step S712; if the target term value is greater than their own term value, and the target log identifier is equal to their own log identifier, execute step S714; if the target term value is greater than their own term value, and the target log identifier is less than their own log identifier, execute step S716.
[0154] Step S712: Other nodes generate approval results and feed back to the current node. Then, step S718 is executed.
[0155] Step S714: Other nodes compare the target weight value with their own weight value. If the target weight value is greater than or equal to their own weight value, execute step S712; if the target weight value is less than their own weight value, execute step S716.
[0156] Step S716: Other nodes generate opposition results and feed them back to the current node. Then, step S718 is executed.
[0157] Step S718: If the fed-back voting results are all affirmative results, and more than half of all voting results are affirmative results, the current node sends a heartbeat report to other nodes to maintain the leadership status.
[0158] Step S720: the current node converts the current state to the leading state. The current node after the state conversion becomes the new target leading node. Other nodes receive the heartbeat report and convert the current state from the non-following state to the following state. Among them, the other nodes include the target leading node.
[0159] Step S722: If there is a specific node among other nodes whose weight value is greater than the target weight value, and the specific node corresponds to the latest log information, the current node sends a timeout request to the specific node, so that the timeout request triggers the specific node to send a second voting request to the remaining nodes.
[0160] It should be noted that steps S700 to S722 are Figure 3 The steps and their embodiments shown correspond to each other. For steps S700 to S722, please refer to Figure 3 The steps and embodiments shown are not described in detail here.
[0161] See also Figure 8 , Figure 8 The structure diagram of a node election system based on a consistency protocol according to an embodiment of the present application is schematically shown. Figure 8 As shown, the node election system 800 based on the consistency protocol includes multiple consistency groups (i.e., consistency group 810, consistency group 820 and consistency group 830), each consistency group includes the current node and other nodes, wherein consistency group 810 includes the current node 811 and other nodes 812, consistency group 820 includes the current node 821 and other nodes 822, and consistency group 830 includes the current node 831 and other nodes 832.
[0162] Take the current node 811 and other nodes 812 as examples, specifically:
[0163] The current node 811 is used to send a first voting request to other nodes 812 in the consistency group 810 to which it belongs;
[0164] Other nodes 812 are used to generate and feedback voting results according to the log information in the first voting request and the target weight value corresponding to the current node 811;
[0165] The current node 811 is also used to send a heartbeat report to other nodes 812 to maintain the leadership state when the voting result meets the preset conditions;
[0166] The current node 811 is also used to trigger a specific node to send a second voting request to the remaining nodes in the consistency group 810 to which it belongs when there is a specific node whose weight value is greater than the target weight value in other nodes 812 and the specific node corresponds to the latest log information.
[0167] It can be seen that implementation Figure 8 The system shown can balance the load among the node clusters to ensure the stability and throughput of the node clusters. In addition, the utilization efficiency of the nodes in the node clusters can be improved.
[0168] Furthermore, in this exemplary embodiment, a node election device based on a consistency protocol is also provided. Fig. 9 As shown, the node election device 900 based on the consistency protocol may include: an election initiating unit 901, a heartbeat report sending unit 902 and an election triggering unit 903, wherein:
[0169] The election initiating unit 901 is used to send a first voting request to other nodes in the consistency group to which it belongs, so that other nodes generate and feedback voting results according to the log information in the first voting request and the target weight value corresponding to the current node;
[0170] A heartbeat report sending unit 902, configured to send a heartbeat report to other nodes to maintain a leadership state when the voting result meets a preset condition;
[0171] The election triggering unit 903 is used to trigger a specific node to send a second voting request to other nodes in the consistency group to which it belongs when there is a specific node whose weight value is greater than the target weight value among other nodes and the specific node corresponds to the latest log information.
[0172] It can be seen that implementation Fig. 9 The device shown can balance the load between node clusters to ensure the stability and throughput of the node cluster. In addition, it can also improve the utilization efficiency of the nodes in the node cluster.
[0173] In an exemplary embodiment of the present application, before the election initiating unit 901 sends the first voting request to other nodes in the consistency group to which it belongs, it also includes:
[0174] Each node in the node cluster receives the group creation request sent by the client and responds to the group creation request;
[0175] The group building request is used to build at least one consistency group composed of multiple nodes in the node cluster, and the at least one consistency group includes the consistency group to which the current node belongs.
[0176] It can be seen that implementing this optional embodiment can build one or more required consistency groups according to the group building request sent by the client, so as to balance the load of each node according to the weight sequence in the group building request and avoid different consistency groups corresponding to the same leader node.
[0177] In an exemplary embodiment of the present application, after the request receiving unit responds to the group establishment request, the method further includes:
[0178] Each node in the node cluster determines a leader node corresponding to each consistency group in at least one consistency group according to multiple weight sequences in the group creation request;
[0179] Among them, the multiple weight sequences correspond one-to-one to at least one consistency group, and the leader node is used to send heartbeat reports to other nodes in the consistency group to which it belongs to maintain the leadership state.
[0180] It can be seen that the implementation of this optional embodiment can balance the load of each node according to the weight sequence in the group creation request, avoiding different consistency groups corresponding to the same leader node.
[0181] In an exemplary embodiment of the present application, the election initiating unit 901 sends a first voting request to other nodes in the consistency group to which it belongs, including:
[0182] If the current node does not receive a heartbeat report from the target leader node within a random time period, the current node sends a first voting request to other nodes in the consistency group to which it belongs;
[0183] Among them, the target leader node belongs to the consistency group to which the current node belongs.
[0184] It can be seen that by implementing this optional embodiment, when the heartbeat report of the leader node is not received, a new leader node can be elected to ensure that data can be read and written normally.
[0185] In an exemplary embodiment of the present application, the above-mentioned device further includes:
[0186] A term update unit (not shown), used to update the target term value before the election initiating unit 901 sends the first voting request to other nodes in the consistency group to which it belongs, and to generate the first voting request according to the target log identifier and the updated target term value;
[0187] The log information in the first voting request at least includes a target log identifier and an updated target term value; the target log identifier is used to record the number of log entries.
[0188] It can be seen that the implementation of this optional embodiment can timely elect a new leader node when the target leader node cannot send a heartbeat report in time (such as when it crashes), so as to avoid the situation where read and write operations cannot be recorded in time.
[0189] In an exemplary embodiment of the present application, the voting result includes a favorable result and a unfavorable result. Other nodes generate and feedback the voting result according to the log information in the first voting request and the target weight value corresponding to the current node, including:
[0190] Other nodes compare the target term value with their own term value, and compare the target log identifier with their own log identifier;
[0191] If the target term value is greater than its own term value, and the target log identifier is greater than its own log identifier, other nodes generate a favorable result and feed it back to the current node;
[0192] If the target term value is greater than its own term value, and the target log identifier is equal to its own log identifier, other nodes will compare the target weight value with their own weight value. If the target weight value is greater than or equal to its own weight value, other nodes will generate a favorable result and feedback to the current node.
[0193] If the target term value is greater than its own term value, and the target log identifier is less than its own log identifier, other nodes generate objection results and feed them back to the current node;
[0194] If the target term value is greater than its own term value, the target log identifier is equal to its own log identifier, and the target weight value is less than its own weight value, other nodes generate objection results and feed them back to the current node.
[0195] In particular, the preset conditions include: the voting results fed back by the specific nodes are all affirmative results, and more than half of all voting results are affirmative results.
[0196] It can be seen that the implementation of this optional embodiment can elect a new leader node by using the log identifier, term value and weight value, wherein the weight value is used as an election reference condition to adjust the node load and avoid a node serving as the leader node of multiple consistency groups at the same time, so as to ensure the stability and throughput of the node cluster.
[0197] In an exemplary embodiment of the present application, after the current node sends a heartbeat report to other nodes to maintain the leadership state, the process further includes:
[0198] Other nodes receive the heartbeat report and convert the current state of the non-following state to the following state; wherein the other nodes include the target leader node.
[0199] It can be seen that by implementing this optional embodiment, the election of the leader node can be completed with reference to the weight value, which is beneficial to node load balancing and thus helps to ensure the stability and throughput of the node cluster.
[0200] In an exemplary embodiment of the present application, the above-mentioned device further includes a state conversion unit (not shown), wherein:
[0201] The state conversion unit is used to convert the current state into the leading state, and the current node after the state conversion is the new target leading node.
[0202] It can be seen that by implementing this optional embodiment, the leader node can be elected with reference to the weight value, which can be beneficial to node load balancing.
[0203] In an exemplary embodiment of the present application, the election triggering unit 903 triggers a specific node to send a second voting request to other nodes in the consistency group to which it belongs, including:
[0204] A timeout request is sent to the specific node, so that the timeout request triggers the specific node to send a second voting request to the remaining nodes.
[0205] It can be seen that by implementing this optional embodiment, if the current leading node in the consistency group is not the node with the highest weight, the node with the highest weight can be triggered in time to run for the leading node for the next term when it synchronizes to the latest log. Since the election refers to the weight factor, the node with a higher weight is more likely to be elected as the leading node if other conditions are not lagging behind. In this way, the node with the highest weight in each consistency group can be elected as the leading node as much as possible, so as to ensure the load balance of each node, and then ensure the stability and throughput of the node cluster.
[0206] In an exemplary embodiment of the present application, the above-mentioned device further includes a determination unit (not shown), wherein:
[0207] The determination unit is used to determine that the specific node corresponds to the latest log information before the election trigger unit 903 triggers the specific node to send a second voting request to the remaining nodes in the consistency group to which it belongs, and when it detects that the log information of the specific node is consistent with the log information of the current node.
[0208] It can be seen that the implementation of this optional embodiment can ensure load balancing of each node, thereby ensuring the stability and throughput of the node cluster.
[0209] It should be noted that, although several modules or units of the equipment for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into being embodied by multiple modules or units.
[0210] Since the various functional modules of the node election device based on the consistency protocol in the example embodiment of the present application correspond to the steps of the example embodiment of the node election method based on the consistency protocol mentioned above, for details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the node election method based on the consistency protocol mentioned above in the present application.
[0211] As another aspect, the present application also provides a computer-readable medium, which may be included in the electronic device described in the above embodiment; or may exist independently without being assembled into the electronic device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by an electronic device, the electronic device implements the method described in the above embodiment.
[0212] It should be noted that the computer-readable medium shown in the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0213] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the above-mentioned module, program segment or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0214] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. The names of these units do not, in some cases, constitute limitations on the units themselves.
[0215] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary technical means in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0216] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A node election method based on a consistency protocol, characterized in that: include: The current node sends a first voting request to other nodes in the consistency group to which it belongs, so that the other nodes generate and feedback voting results according to the log information in the first voting request and the target weight value corresponding to the current node; wherein, in the same consistency group, the weight values of different nodes are not completely the same; in different consistency groups, the nodes with the highest weight values are different; If the voting result meets the preset conditions, the current node sends a heartbeat report to the other nodes to maintain the leadership state; If there is a specific node among the other nodes whose weight value is greater than the target weight value, and the specific node corresponds to the latest log information, the current node triggers the specific node to send a second voting request to the remaining nodes in the consistency group to which it belongs; Before the current node triggers the specific node to send a second voting request to other nodes in the consistency group to which it belongs, the method further includes: Whether the specific node has the latest log information is detected according to a preset time length. If the specific node does not have the latest log information, the current node sends the current log content of the current node to the specific node to enable the specific node to synchronize the log; and whether the specific node has the latest log information is detected again. If the specific node has the latest log information, it is determined that the specific node corresponds to the latest log information, and the current node triggers the specific node to send the second voting request to the remaining nodes in the consistency group to which it belongs.
2. The method according to claim 1, characterized in that Before the current node sends the first voting request to other nodes in the consistency group to which it belongs, the method further includes: Each node in the node cluster receives a group creation request sent by the client and responds to the group creation request; The group building request is used to build at least one consistency group composed of multiple nodes in the node cluster, and the at least one consistency group includes the consistency group to which the current node belongs.
3. The method according to claim 2, characterized in that After responding to the group creation request, the method further includes: Each node in the node cluster determines a leader node corresponding to each consistency group in the at least one consistency group according to a plurality of weight sequences in the group creation request; The multiple weight sequences correspond one-to-one to the at least one consistency group, and the leader node is used to send the heartbeat report to other nodes in the consistency group to which it belongs to maintain the leadership state.
4. The method according to claim 3, characterized in that The current node sends a first voting request to other nodes in the consistency group to which it belongs, including: If the current node does not receive the heartbeat report sent by the target leader node within a random time period, the current node sends the first voting request to other nodes in the consistency group to which it belongs; The target leader node belongs to the consistency group to which the current node belongs.
5. The method according to claim 4, characterized in that Before the current node sends the first voting request to other nodes in the consistency group to which it belongs, the method further includes: The current node updates the target term value, and generates a first voting request according to the target log identifier and the updated target term value; Among them, the log information in the first voting request at least includes the target log identifier and the updated target term value; the target log identifier is used to record the number of log entries.
6. The method according to claim 5, characterized in that The voting result includes a positive result and a negative result. The other nodes generate and feed back the voting result according to the log information in the first voting request and the target weight value corresponding to the current node, including: The other nodes compare the target term value with their own term value, and compare the target log identifier with their own log identifier; If the target term value is greater than the own term value, and the target log identifier is greater than the own log identifier, the other node generates the approval result and feeds it back to the current node; If the target term value is greater than the own term value, and the target log identifier is equal to the own log identifier, the other node compares the target weight value with its own weight value. If the target weight value is greater than or equal to its own weight value, the other node generates the approval result and feeds it back to the current node. If the target term value is greater than the own term value, and the target log identifier is less than the own log identifier, the other node generates the objection result and feeds it back to the current node; If the target term value is greater than the own term value, the target log identifier is equal to the own log identifier, and the target weight value is less than the own weight value, the other node generates the objection result and feeds it back to the current node.
7. The method according to claim 6, characterized in that The preset conditions include: the voting results fed back by the specific node are all the approval results, and more than half of all the voting results are the approval results.
8. The method according to claim 4, characterized in that After the current node sends a heartbeat report to the other nodes to maintain the leadership state, the method further includes: The other nodes receive the heartbeat report and convert the current state of the non-following state into the following state; wherein the other nodes include the target leader node.
9. The method according to claim 8, characterized in that The method further comprises: The current node converts the current state into the leading state, and the current node after the state conversion becomes the new target leading node.
10. The method according to claim 1, characterized in that The current node triggers the specific node to send a second voting request to other nodes in the consistency group to which it belongs, including: The current node sends a timeout request to the specific node, so that the timeout request triggers the specific node to send the second voting request to the remaining nodes.
11. The method according to claim 1, characterized in that: Before the current node triggers the specific node to send a second voting request to the remaining nodes in the consistency group to which it belongs, the method further includes: If it is detected that the log information of the specific node is consistent with the log information of the current node, the current node determines that the specific node corresponds to the latest log information.
12. A node election system based on a consistency protocol, characterized in that: The system includes a plurality of consistency groups, each of which includes a current node and other nodes, wherein: The current node is used to send a first voting request to other nodes in the consistency group to which it belongs; The other nodes are configured to generate and feed back voting results according to the log information in the first voting request and the target weight value corresponding to the current node; The current node is further configured to send a heartbeat report to the other nodes to maintain a leadership state when the voting result meets a preset condition; The current node is further configured to trigger a specific node to send a second voting request to other nodes in the consistency group to which it belongs when there is a specific node whose weight value is greater than the target weight value among the other nodes and the specific node corresponds to the latest log information; Before triggering the specific node to send a second voting request to other nodes in the consistency group to which it belongs, the current node is further used to: Check whether the specific node has the latest log information according to a preset time length. If the specific node does not have the latest log information, send the current log content of the current node to the specific node to enable the specific node to synchronize the log; and check again whether the specific node has the latest log information. If the specific node has the latest log information, determine that the specific node corresponds to the latest log information, and trigger the specific node to send a second voting request to the remaining nodes in the consistency group to which it belongs.
13. A node election device based on a consistency protocol, characterized in that: include: An election initiating unit, configured to send a first voting request to other nodes in the corresponding consistency group, so that the other nodes generate and feedback voting results according to the log information in the first voting request and the target weight value corresponding to the current node; A heartbeat report sending unit, configured to send a heartbeat report to the other nodes to maintain a leadership state when the voting result meets a preset condition; an election triggering unit, configured to trigger, when there is a specific node whose weight value is greater than the target weight value among the other nodes and the specific node corresponds to the latest log information, the specific node to send a second voting request to the remaining nodes in the consistency group to which it belongs; Before triggering the specific node to send a second voting request to other nodes in the consistency group to which it belongs, the election triggering unit is further used to: Detecting whether the specific node has the latest log information according to a preset time period, and if the specific node does not have the latest log information, sending the current log content of the current node to the specific node, so that the specific node performs log synchronization; And detect again whether the specific node has the latest log information. If the specific node has the latest log information, determine that the specific node corresponds to the latest log information, and trigger the specific node to send the second voting request to the remaining nodes in the consistency group to which it belongs.
14. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 11 is implemented.
15. An electronic device, characterized in that: include: processor; as well as A memory, configured to store executable instructions of the processor; The processor is configured to perform the method of any one of claims 1-11 by executing the executable instructions.
16. A computer program product, characterized in that The method comprises computer instructions, which, when executed by a processor of a computer device, enable the computer device to implement the method according to any one of claims 1 to 11.
Citation Information
Patent Citations
Node equipment operation method and node equipment
CN107105032A
Node synchronization method, device and equipment of block chain and storage medium
CN111586147A