A leadership node election method and system

By adopting a hierarchical election method in a distributed system, the number of nodes in each round of elections is reduced, and the problems of high cost and low efficiency of network communication in the existing technology are solved, and a more efficient election process and better system availability are achieved.

CN111770178BActive Publication Date: 2025-03-28WEBANK (CHINA)
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202010607789.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-06-29
Publication Date
2025-03-28
Estimated Expiration
2040-06-29

AI Technical Summary

Technical Problem

The election process in the existing distributed system requires participation of all nodes, and each round of voting requires collecting votes from all nodes, resulting in high network communication costs and low election efficiency.

Method used

The hierarchical election method is adopted to reduce the number of nodes participating in each round of election through the voting process of the second-level node set and the voting process of the first-level node set. The specific steps include: the participating nodes in each second-level node set vote to select the second-level voting nodes, forming multiple second-level voting nodes; these second-level voting nodes act as participatory nodes, form the first-level node set, conduct the first-level voting election, and select the leadership node.

Benefits of technology

By reducing the number of nodes in each round of elections, network communication costs are reduced, election efficiency is improved, and election time is shortened, thereby improving the overall high availability of services.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111770178B_ABST
    Figure CN111770178B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention relates to the field of computer technology, and in particular to a method and system for selecting a leader node, which is used to reduce the network communication cost in the election process and improve the election efficiency. The embodiment of the present invention includes: each participating node in the first-level node set broadcasts reference data to the other participating nodes in the same set; all participating nodes in the first-level node set vote to select a first-level voting node according to the reference data; wherein the first-level node set is composed of a plurality of second-level voting nodes as participating nodes, and a second-level voting node is voted by all participating nodes in a second-level node set; the first-level voting node, as a leader node, sends an election result message to all participating nodes in the first-level node set; each participating node in the first-level node set sends an election result message to all participating nodes in the corresponding second-level node set.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology in financial technology (Fintech), and in particular to a leader node election method and system. Background Art

[0002] With the continuous development of financial technology, especially Internet technology finance, more and more technologies (such as distributed, blockchain, artificial intelligence, etc.) are applied in the financial field, but the financial industry also puts forward higher requirements for technology, such as data processing for distributed systems.

[0003] Election is a common problem in distributed system practice and is the key to ensuring the consistency of distributed data. By breaking the peer-to-peer relationship between nodes, the selected leader node helps to achieve transaction atomicity and improve decision-making efficiency.

[0004] The existing election process is: all nodes participate in the election, all nodes send votes to each other, and collect and judge the votes. After all nodes have judged, they send the latest votes to all nodes. When the node elected by all machines in the entire system has more than 50% of the votes, the node will be selected as the leader node. The existing technology is that all nodes in the system must participate in each round of voting, and each round of voting requires collecting votes from all nodes, so the required network communication cost is high and the election efficiency is low. Summary of the invention

[0005] The present application provides a method and device for electing a leader node in a distributed system, which are used to reduce network communication costs during the election process and improve election efficiency.

[0006] A leader node election method provided by an embodiment of the present invention is applied to a distributed system, comprising:

[0007] Each participating node in the first-level node set broadcasts reference data to the other participating nodes in the same set; all participating nodes in the first-level node set vote to elect a first-level voting node based on the reference data; wherein the first-level node set is composed of a plurality of second-level voting nodes as participating nodes, and a second-level voting node is voted by all participating nodes in a second-level node set;

[0008] The first-level voting node, as a leader node, sends an election result message to all participating nodes in the first-level node set;

[0009] Each participating node in the first-level node set sends an election result message to all participating nodes in the corresponding second-level node set.

[0010] In an optional embodiment, the distributed system includes a set of N-level nodes, where N is an integer greater than 3;

[0011] Before each participating node in the first-level node set broadcasts reference data to other participating nodes in the same set, the method further includes:

[0012] For each node set in the Nth level node set, each participating node in the node set broadcasts reference data to other participating nodes in the same set; all participating nodes in the node set vote to elect an Nth level voting node as the N-1th level participating node according to the reference data; wherein the Nth level node set is formed by dividing all participating nodes in the distributed system;

[0013] For each node set in the M-1th level node set, each participating node in the node set broadcasts reference data to other participating nodes in the same set; all participating nodes in the node set vote to elect an M-1th level voting node as an M-2th level participating node according to the reference data; wherein the M-1th level node set is formed by dividing the Mth level voting node as a participating node; wherein M is an integer equal to N to 3 in sequence;

[0014] After each participating node in the first-level node set sends an election result message to all participating nodes in the corresponding second-level node set, the method further includes:

[0015] The participating nodes in the M-1th level node set send election result messages to all participating nodes in the corresponding Mth level node set; where M is an integer equal to 3 to N respectively.

[0016] In an optional embodiment, for each node set in the M-1th level node set, after all participating nodes in the node set vote to elect the M-1th level voting node as the M-2th level participating node according to the reference data, the method further includes:

[0017] All participating nodes in the node set vote to elect an M-1th level candidate node according to the reference data; the M-1th level candidate node is a participating node in the node set except the M-1th level voting node.

[0018] In an optional embodiment, the reference data includes an identifier of a corresponding M-th level node set and a comparison identifier of a corresponding M-th level voting node;

[0019] For each participating node in the M-1th level node set, after each participating node in the node set broadcasts reference data to other participating nodes in the same set, the method further includes:

[0020] The participating nodes compare the identifiers of the Mth level node set in each reference data;

[0021] If the identifiers of two or more reference data's M-th level node sets are the same, the participating node retains one reference data according to the comparison identifier, and sends a split-brain alarm message to all participating nodes in the M-th level node set corresponding to the same identifier;

[0022] All participating nodes in the Mth level node set corresponding to the same identifier re-vote to select the Mth level voting node.

[0023] In an optional embodiment, all participating nodes in the first-level node set vote to elect a first-level voting node according to reference data, including:

[0024] For each participating node in the first-level node set, the participating node compares the received multiple reference data and determines the first-level candidate node from the participating nodes corresponding to the multiple reference data; the participating node sends voting data to the remaining participating nodes, and the voting data includes the reference data of the first-level candidate node;

[0025] If the first-level candidate node determines that the number of reference data of the first candidate node included in the received voting data is greater than the voting threshold, it sends voting result data to all other participating nodes in the first-level node set as the first-level voting node.

[0026] In an optional embodiment, the reference data includes an identifier of a corresponding second-level node set;

[0027] For each participating node in the first-level node set, the participating node performs comparison according to the received multiple reference data, including:

[0028] The participating nodes compare the identifiers of the second level node sets in each reference data;

[0029] If the identifiers of two or more second-level node sets of reference data are the same, the participating node sends a split-brain alarm message to all participating nodes in the second-level node set corresponding to the same identifier;

[0030] The participating nodes and the second-level voting nodes re-selected by voting by the set of second-level nodes corresponding to the same identifier send reference data to each other.

[0031] The present invention also provides a leadership node election system, comprising:

[0032] The participating nodes in the first-level node set are used to broadcast reference data to the other participating nodes in the same set; based on the reference data, a first-level voting node is voted;

[0033] The participating nodes in the second-level node set are used to broadcast reference data to other participating nodes in the same set; based on the reference data, multiple second-level voting nodes are voted and elected;

[0034] Wherein, the first-level node set is composed of a plurality of second-level voting nodes as participating nodes, and a second-level voting node is voted and elected by all participating nodes in a second-level node set;

[0035] The first-level voting node is used to send an election result message to all participating nodes in the first-level node set as a leader node;

[0036] The participating nodes in the first-level node set are used to send election result messages to all participating nodes in the corresponding second-level node set.

[0037] In an optional embodiment, the distributed system includes a set of N-level nodes, where N is an integer greater than 3; the system includes:

[0038] The participating nodes in the Nth level node set are used to broadcast reference data to other participating nodes in the same set; based on the reference data, the Nth level voting nodes are voted to be the N-1th level participating nodes; wherein the Nth level node set is formed by dividing all participating nodes in the distributed system;

[0039] The participating nodes in the M-1th level node set are used to broadcast reference data to other participating nodes in the same set; based on the reference data, the M-1th level voting nodes are voted to be the M-2th level participating nodes; wherein the M-1th level node set is formed by dividing the Mth level voting nodes as participating nodes; wherein M is an integer equal to N to 3 in sequence;

[0040] The participating nodes in the M-1th level node set are also used to send election result messages to all participating nodes in the corresponding Mth level node set; wherein M is an integer equal to 3 to N respectively.

[0041] An embodiment of the present invention further provides an electronic device, including:

[0042] at least one processor; and,

[0043] a memory communicatively connected to the at least one processor; wherein,

[0044] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method described above.

[0045] An embodiment of the present invention further provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the method as described above.

[0046] In the embodiment of the present invention, the election process of the distributed system is divided into the voting process of the second-level node set and the voting process of the first-level node set. Among them, the first-level set is composed of multiple second-level voting nodes as participating nodes, and one second-level voting node is voted by all participating nodes in a second-level node set. That is to say, the distributed system includes multiple second-level node sets, and each second-level node set includes multiple participating nodes. All participating nodes in a second-level node set vote to select a second-level voting node, and then multiple second-level node sets can select a corresponding number of second-level voting nodes. These second-level voting nodes are used as participating nodes to form a first-level node set. Each participating node in the first-level node set broadcasts reference data to the remaining participating nodes in the same set, and all participating nodes vote to select a first-level voting node based on the received reference data. In this way, the first-level voting node is the elected leader node, and sends an election result message to all participating nodes in the first-level node set to inform the participating nodes in the first-level node set of the election result. Furthermore, each participating node in the first-level node set sends the election result to the corresponding second-level node set, so that all participating nodes in the second-level node set can obtain the election result message. During the implementation of the present invention, a hierarchical election method is used to reduce the number of nodes participating in each round of elections, thereby reducing network communication costs, significantly and effectively improving election efficiency, shortening election time, and thus improving the overall high availability of the service. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, 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 invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0048] Figure 1 A schematic diagram of a possible system architecture provided by an embodiment of the present invention;

[0049] Figure 2 A schematic diagram of a process flow of a leader node election method for a distributed system provided by an embodiment of the present invention;

[0050] Figure 3 A schematic diagram of the structure of a distributed system provided by an embodiment of the present invention;

[0051] Figure 4 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0052] In order to make the purpose, technical solution and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0053] like Figure 1 As shown, a system architecture applicable to the embodiment of the present invention includes N participating nodes, wherein the structures and parameters between any two sub-nodes are the same, so each sub-node can achieve the same function.

[0054] The node can be a network device such as a computer, an independent device, or a server cluster formed by multiple servers. Preferably, the node can use cloud computing technology to process information.

[0055] The nodes can communicate with each other through the INTERNET network, or through mobile communication systems such as the Global System for Mobile Communications (GSM) and the Long Term Evolution (LTE) system.

[0056] To facilitate understanding, the terms that may be involved in the embodiments of the present invention are defined and explained below.

[0057] Leader node: Many types of tasks in distributed systems require a single process (or instance or node) to play the role of a coordinator, such as data backup management, group member communication, or atomic commit protocol formulation. This coordinator role is the leader node.

[0058] LOOKING: Looking for Leader state. In this state, the election process needs to be entered.

[0059] LEADING: Leader state. A node in this state is already a leader.

[0060] FOLLOWING: Follower state, indicating that the Leader has been elected and the current node role is follower.

[0061] ZXID: Transaction ID. To ensure the order consistency of transactions, an incremental transaction ID is used to identify transactions. All proposals are added with ZXID when they are proposed. In the implementation, ZXID is a 64-bit number. Each operation of node status change will cause the node to receive a timestamp in ZXID format, and this timestamp is globally ordered. In other words, each change to a node will generate a unique ZXID.

[0062] Split-brain problem: Two subsets of the server cluster can independently elect a leader and run normally at the same time to form two clusters. Split-brain will cause data incompleteness and may have a serious impact on services.

[0063] Based on the above architecture, an embodiment of the present invention provides a method for selecting a leader node, which is applied to a distributed system, such as Figure 2 As shown, the leader node election method provided by the embodiment of the present invention includes the following steps:

[0064] Step 201: Each participating node in the first-level node set broadcasts reference data to other participating nodes in the same set.

[0065] The first-level node set is composed of multiple second-level voting nodes as participating nodes, and a second-level voting node is voted and selected by all participating nodes in a second-level node set.

[0066] Step 202: All participating nodes in the first-level node set vote to elect a first-level voting node based on reference data.

[0067] That is to say, the election process of the distributed system in the embodiment of the present invention is divided into a voting process of the second-level node set and a voting process of the first-level node set.

[0068] First, all participating nodes in the distributed system are divided into multiple second-level node sets. The division can be based on the geographical location of the nodes or based on different network providers. During the election, the participating nodes conduct elections within their respective node sets, and each node set elects a voting node. That is, the participating nodes in a second-level node set vote to elect a second-level voting node. For example, if the distributed system contains 100 nodes, the 100 nodes are divided into 10 second-level node sets for the participating nodes. Then, 10 second-level voting nodes are elected through voting by the second-level node sets.

[0069] These 10 second-level voting nodes then form a first-level node set as first-level participating nodes, conduct first-level voting elections, and finally select one from these 10 first-level participating nodes as the final leader node. In this way, there are fewer participating nodes in the first round of elections, and the network communication cost between nodes is effectively reduced.

[0070] Step 203: The first-level voting node, as a leader node, sends an election result message to all participating nodes in the first-level node set.

[0071] After the leader node is elected, the leader node sends an election result message to the participating nodes in the first-level node set to inform the first-level participating nodes. Afterwards, each first-level participating node sends an election result message to the corresponding second-level node set.

[0072] Step 204: Each participating node in the first-level node set sends an election result message to all participating nodes in the corresponding second-level node set.

[0073] In the embodiment of the present invention, the election process of the distributed system is divided into the voting process of the second-level node set and the voting process of the first-level node set. Among them, the first-level set is composed of multiple second-level voting nodes as participating nodes, and one second-level voting node is voted by all participating nodes in a second-level node set. That is to say, the distributed system includes multiple second-level node sets, and each second-level node set includes multiple participating nodes. All participating nodes in a second-level node set vote to select a second-level voting node, and then multiple second-level node sets can select a corresponding number of second-level voting nodes. These second-level voting nodes are used as participating nodes to form a first-level node set. Each participating node in the first-level node set broadcasts reference data to the remaining participating nodes in the same set, and all participating nodes vote to select a first-level voting node based on the received reference data. In this way, the first-level voting node is the elected leader node, and sends an election result message to all participating nodes in the first-level node set to inform the participating nodes in the first-level node set of the election result. Furthermore, each participating node in the first-level node set sends the election result to the corresponding second-level node set, so that all participating nodes in the second-level node set can obtain the election result message. During the implementation of the present invention, a hierarchical election method is used to reduce the number of nodes participating in each round of elections, thereby reducing network communication costs, significantly and effectively improving election efficiency, shortening election time, and thus improving the overall high availability of the service.

[0074] Furthermore, all participating nodes in the first-level node set vote to elect a first-level voting node based on the reference data, including:

[0075] For each participating node in the first-level node set, the participating node compares the received multiple reference data and determines the first-level candidate node from the participating nodes corresponding to the multiple reference data; the participating node sends voting data to the first-level candidate node;

[0076] If the first-level candidate node determines that the number of received voting data is greater than the voting threshold, it acts as the first-level voting node to send voting result data to all other participating nodes in the first-level node set.

[0077] In the specific real-time process, the reference data may include the ZXID and node number (myid) of each node. The participating nodes compare the ZXIDs and select the participating node with the largest ZXID as the voting node. If the ZXIDs are the same, the participating node with the larger node number is selected.

[0078] Since the voting process for each node set is similar, it is described here uniformly. The specific election process is as follows:

[0079] Step 1: Each participating node issues a vote. Since this is the initial situation, each participating node will vote as the Leader. Each vote will contain the myid and ZXID of the recommended server, represented by (myid, ZXID). For example, Server1's vote is (1,0), and Server2's vote is (2,0), and then each sends this vote to other participating nodes in the node set.

[0080] Step 2: Receive votes from each participating node. After receiving the vote, each participating node in the node set first determines the validity of the vote, such as checking whether it is a vote in this round and whether it comes from a server in the LOOKING state.

[0081] Step 3: Processing votes. For each vote, the participating node needs to compare the votes received from other participating nodes with its own vote. The comparison rules are as follows:

[0082] 1. Compare ZXIDs first. Participating nodes with larger ZXIDs will be prioritized as Leaders.

[0083] 2. If the ZXIDs are the same, then myids are compared. The participating node with the larger myid serves as the leader server.

[0084] For Server1, its vote is (1,0), and the vote received from Server2 is (2,0). First, it compares the ZXID of the two, which are both 0; then it compares the myid, and at this time Server2's myid is larger, so Server1 updates its vote to (2,0), and then votes again. For Server2, it does not need to update its vote, but only sends the last voting information to all participating nodes in the node set again.

[0085] Step 4: Count votes. After each vote, participating nodes will count the voting information to determine whether more participating nodes than the threshold have received the same voting information. For example, for Server1 and Server2, both count that two participating nodes in the node set have received the voting information (2,0), and at this time, it is considered that the Leader has been selected.

[0086] Step 5: Change the node status. Once the Leader is determined, each node will update its status. If it is a Follower, the status will be changed to FOLLOWING, and if it is a Leader, the status will be changed to LEADING.

[0087] Further, the reference data includes an identification of a corresponding second-level node set;

[0088] For each participating node in the first-level node set, the participating node performs comparison according to the received multiple reference data, including:

[0089] The participating nodes compare the identifiers of the second level node sets in each reference data;

[0090] If the identifiers of two or more second-level node sets of reference data are the same, the participating node sends a split-brain alarm message to all participating nodes in the second-level node set corresponding to the same identifier;

[0091] The participating nodes and the second-level voting nodes re-selected by voting by the set of second-level nodes corresponding to the same identifier send reference data to each other.

[0092] In the specific implementation process, when the first-level node set is elected, if there are two or more votes for the same second-level node set, it is necessary to wait for the second-level node set to re-elect the only second-level voting node. This is to avoid the brain split phenomenon when the election is completed.

[0093] After the leader node is elected for the last time, the leader node establishes connections with all nodes in the system to inform them of the election results. If the connection with more than 50% of the nodes is successful, it will serve as a valid leader node in the final election and provide services to the outside world.

[0094] The above process is to divide the nodes in the distributed system into two-level node sets. When there are many nodes in the distributed system, all nodes can also be divided into N-level node sets, where N is an integer greater than 3.

[0095] Then, before each participating node in the first-level node set broadcasts the reference data to the other participating nodes in the same set, the process further includes:

[0096] For each node set in the Nth level node set, each participating node in the node set broadcasts reference data to other participating nodes in the same set; all participating nodes in the node set vote to elect an Nth level voting node as the N-1th level participating node according to the reference data; wherein the Nth level node set is formed by dividing all participating nodes in the distributed system;

[0097] For each node set in the M-1th level node set, each participating node in the node set broadcasts reference data to other participating nodes in the same set; all participating nodes in the node set vote to elect an M-1th level voting node as an M-2th level participating node according to the reference data; wherein the M-1th level node set is formed by dividing the Mth level voting node as a participating node; wherein M is an integer equal to N to 3 in sequence;

[0098] After each participating node in the first-level node set sends an election result message to all participating nodes in the corresponding second-level node set, the method further includes:

[0099] The participating nodes in the M-1th level node set send election result messages to all participating nodes in the corresponding Mth level node set; where M is an integer equal to 3 to N respectively.

[0100] During the specific election, the system nodes are divided into multiple levels of node sets. The lowest level node set corresponds to the smallest area, and the high-level area contains the lower-level area. Here, the low level corresponds to a larger number of N, the high level corresponds to a smaller number of N, and the highest level is the first-level node set.

[0101] During an election, the participating nodes in the smallest area are first elected, and the election condition is a configurable threshold. For example, within the smallest area, the election is considered completed only when the votes of a participating node exceed 60%. The elected voting node can participate in the voting of the higher-level node set, but it is not equivalent to being a leader. Since the first voting process is carried out in small areas, the election speed will be greatly improved. For example, if a cluster has 200 nodes, in the prior art, all 200 nodes must send and receive votes to each other, which puts a lot of pressure on the network. In the embodiment of the present invention, only some nodes participate in each round of elections, which greatly reduces the pressure on the network.

[0102] During the election process, each participating node sends a ballot to all other participating nodes in the node set. The initial ballot is for itself. After receiving the ballots sent by other participating nodes, each participating node compares all the ballots and selects the participating node with the largest ZXID in the ballot as the node selected for the next round of election. If the ZXID is the same, the node with the larger node number is selected. Until a certain round of election, when 60% of the votes received by each participating node are cast to the same participating node, this participating node is elected as the voting node of the node set and can participate in the election of a higher level.

[0103] After a voting node is selected in a node set, all other participating nodes will maintain a heartbeat connection with the voting node. The voting node elected in a lower-level node set is responsible for participating in the election of a higher-level node set, and is also responsible for maintaining contact with the other participating nodes in this node set. The voting node needs to send the election progress and election results of the higher-level node set to all other participating nodes in this node set simultaneously. When a voting node fails and cannot communicate with the corresponding node set, the node set will re-elect, and the newly elected voting node will continue to perform communication tasks.

[0104] When a participating node votes to select a voting node from a node set, and then receives a new ballot, it rejects the ballot and informs the participating node that sent the vote of the current voting status.

[0105] In order to prevent the voting node from being unable to participate in the election of a higher level when the network is unstable, in the embodiment of the present invention, for each node set in the M-1th level node set, all participating nodes in the node set vote to elect the M-1th level voting node as the M-2th level participating node according to the reference data, and then further include:

[0106] All participating nodes in the node set vote to elect an M-1th level candidate node according to the reference data; the M-1th level candidate node is a participating node in the node set except the M-1th level voting node.

[0107] That is to say, in addition to the first-level node set and the second-level node set, each node set is allowed to elect a candidate node. When the voting node of the node set loses connection, the candidate node can actively replace the voting node to participate in the higher-level voting. This can reduce the time spent on re-election when the network is unstable.

[0108] In order to ensure the timeliness of the election, each round of voting has a timeout period. When this time is exceeded, the next round of voting will be automatically entered and the voting in this round will no longer be processed. However, the participating nodes that sent the delayed vote will be informed that they have entered the next round of voting.

[0109] The embodiment of the present invention reduces the number of re-elections while reducing the risk of brain split by setting alternative nodes and rejecting multiple votes from the same node set, thereby effectively improving the election efficiency.

[0110] The reference data of the embodiment of the present invention includes the identifier of the corresponding M-th level node set and the control identifier of the corresponding M-th level voting node. For the split brain phenomenon, for each participating node in the M-1-th level node set, after each participating node in the node set broadcasts the reference data to the other participating nodes in the same set, it also includes:

[0111] The participating nodes compare the identifiers of the Mth level node set in each reference data;

[0112] If the identifiers of two or more reference data's M-th level node sets are the same, the participating node retains one reference data according to the comparison identifier, and sends a split-brain alarm message to all participating nodes in the M-th level node set corresponding to the same identifier;

[0113] All participating nodes in the Mth level node set corresponding to the same identifier re-vote to select the Mth level voting node.

[0114] In the specific implementation process, for each round of voting, if a participating node receives votes from two or more voting nodes in the same node set, the node set has a split-brain phenomenon. For this round of voting, only the votes of the voting nodes with larger ZXID values ​​are accepted, and the votes of the voting nodes with smaller ZXID values ​​are rejected. At the same time, a split-brain alarm message is sent to inform the two or more voting nodes in the same node set.

[0115] When a voting node is informed that a split occurs in the node set, it will send a split-brain alarm message to all other participating nodes in the node set. After that, all nodes in the node set will start a new election. During the election, the node set will not participate in the election process of the higher-level node set, thereby reducing the impact of the split-brain. However, the election process of the higher-level node set will be synchronized to all nodes in the split-brain area.

[0116] When a certain number of rounds have passed and the voting nodes of the higher-level node set of the split-brain node set have been elected, if the split-brain region still has not elected a valid voting node, the voting nodes of the higher-level node set will intervene in the election process of the split-brain node set. The voting nodes of the higher-level node set will directly communicate with all nodes in the split-brain node set to vote, and finally elect the voting nodes of the split-brain node set.

[0117] In the embodiment of the present invention, through hierarchical election, when a node set has a split-brain phenomenon, it can be discovered and corrected in a large area in time, thereby improving the health of the overall service.

[0118] The embodiment of the present invention also provides a leadership node election system, such as Figure 3 As shown, including:

[0119] The participating nodes in the first-level node set are used to broadcast reference data to the other participating nodes in the same set; based on the reference data, a first-level voting node is voted;

[0120] The participating nodes in the second-level node set are used to broadcast reference data to other participating nodes in the same set; based on the reference data, multiple second-level voting nodes are voted and elected;

[0121] Wherein, the first-level node set is composed of a plurality of second-level voting nodes as participating nodes, and a second-level voting node is voted and elected by all participating nodes in a second-level node set;

[0122] The first-level voting node is used to send an election result message to all participating nodes in the first-level node set as a leader node;

[0123] The participating nodes in the first-level node set are used to send election result messages to all participating nodes in the corresponding second-level node set.

[0124] Furthermore, the distributed system includes a set of N-level nodes, where N is an integer greater than 3; the system includes:

[0125] The participating nodes in the Nth level node set are used to broadcast reference data to other participating nodes in the same set; based on the reference data, the Nth level voting nodes are voted to be the N-1th level participating nodes; wherein the Nth level node set is formed by dividing all participating nodes in the distributed system;

[0126] The participating nodes in the M-1th level node set are used to broadcast reference data to other participating nodes in the same set; based on the reference data, the M-1th level voting nodes are voted to be the M-2th level participating nodes; wherein the M-1th level node set is formed by dividing the Mth level voting nodes as participating nodes; wherein M is an integer equal to N to 3 in sequence;

[0127] The participating nodes in the M-1th level node set are also used to send election result messages to all participating nodes in the corresponding Mth level node set; wherein M is an integer equal to 3 to N respectively.

[0128] Based on the same principle, the present invention also provides an electronic device, such as Figure 4 As shown, including:

[0129] The device comprises a processor 401, a memory 402, a transceiver 403, and a bus interface 404, wherein the processor 401, the memory 402 and the transceiver 403 are connected via the bus interface 404;

[0130] The processor 401 is configured to read the program in the memory 402 and execute the following method:

[0131] Send and receive reference data; based on the reference data, vote to elect a first-level voting node;

[0132] Wherein, the first-level node set is composed of a plurality of second-level voting nodes as participating nodes, and a second-level voting node is voted and elected by all participating nodes in a second-level node set;

[0133] Sending an election result message to all participating nodes in the first-level node set; so that the participating nodes in the first-level node set send an election result message to all participating nodes in the corresponding second-level node set.

[0134] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0135] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0136] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0137] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.

[0138] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A leader node election method, applied to a distributed system, characterized in that: include: Each participating node in the first-level node set broadcasts reference data to the other participating nodes in the same set; All participating nodes in the first-level node set vote to elect a first-level voting node based on the reference data; wherein the first-level node set is composed of a plurality of second-level voting nodes as participating nodes, and a second-level voting node is voted and elected by all participating nodes in a second-level node set; The first-level voting node, as a leader node, sends an election result message to all participating nodes in the first-level node set; Each participating node in the first-level node set sends an election result message to all participating nodes in the corresponding second-level node set; For each round of voting, if the participating node receives votes from two or more voting nodes in the same node set, it accepts the votes from the voting node with a larger ZXID value, rejects the votes from the voting node with a smaller ZXID value, and sends an alarm message. After sending the alarm message, all nodes in the node set restart the election; the alarm message is used to inform two or more voting nodes in the same node set that the participating node is a split-brain node; When a certain number of rounds have passed and the voting nodes of the higher-level node set of the node set have been selected, if the node set has not selected a valid voting node, the voting nodes of the higher-level node set will intervene in the election process of the node set.

2. The method according to claim 1, characterized in that The distributed system includes a set of N-level nodes, where N is an integer greater than 3; Before each participating node in the first-level node set broadcasts reference data to other participating nodes in the same set, the method further includes: For each node set in the Nth level node set, each participating node in the node set broadcasts reference data to other participating nodes in the same set; all participating nodes in the node set vote to elect an Nth level voting node as the N-1th level participating node according to the reference data; wherein the Nth level node set is formed by dividing all participating nodes in the distributed system; For each node set in the M-1th level node set, each participating node in the node set broadcasts reference data to other participating nodes in the same set; all participating nodes in the node set vote to elect an M-1th level voting node as an M-2th level participating node according to the reference data; wherein the M-1th level node set is formed by dividing the Mth level voting node as a participating node; wherein M is an integer equal to N to 3 in sequence; After each participating node in the first-level node set sends an election result message to all participating nodes in the corresponding second-level node set, the method further includes: The participating nodes in the M-1th level node set send election result messages to all participating nodes in the corresponding Mth level node set; where M is an integer equal to 3 to N respectively.

3. The method according to claim 2, characterized in that For each node set in the M-1th level node set, after all participating nodes in the node set vote to elect the M-1th level voting node as the M-2th level participating node according to the reference data, the method further includes: All participating nodes in the node set vote to elect an M-1th level candidate node according to the reference data; the M-1th level candidate node is a participating node in the node set except the M-1th level voting node.

4. The method according to claim 2, characterized in that The reference data includes the identifier of the corresponding M-th level node set and the corresponding M-th level voting node comparison identifier; For each participating node in the M-1th level node set, after each participating node in the node set broadcasts reference data to other participating nodes in the same set, the method further includes: The participating nodes compare the identifiers of the Mth level node set in each reference data; If the identifiers of two or more reference data's M-th level node sets are the same, the participating node retains one reference data according to the comparison identifier, and sends a split-brain alarm message to all participating nodes in the M-th level node set corresponding to the same identifier; All participating nodes in the Mth level node set corresponding to the same identifier re-vote to select the Mth level voting node.

5. The method according to claim 1, characterized in that All participating nodes in the first-level node set vote to elect a first-level voting node based on the reference data, including: For each participating node in the first-level node set, the participating node compares the received multiple reference data and determines the first-level candidate node from the participating nodes corresponding to the multiple reference data; the participating node sends voting data to the remaining participating nodes, and the voting data includes the reference data of the first-level candidate node; If the first-level candidate node determines that the number of reference data of the first-level candidate node included in the received voting data is greater than the voting threshold, it sends voting result data to all other participating nodes in the first-level node set as the first-level voting node.

6. The method according to claim 5, characterized in that The reference data includes an identifier of a corresponding second-level node set; For each participating node in the first-level node set, the participating node performs comparison according to the received multiple reference data, including: The participating nodes compare the identifiers of the second level node sets in each reference data; If the identifiers of two or more second-level node sets of reference data are the same, the participating node sends a split-brain alarm message to all participating nodes in the second-level node set corresponding to the same identifier; The participating nodes and the second-level voting nodes re-selected by voting by the set of second-level nodes corresponding to the same identifier send reference data to each other.

7. A leadership node election system, characterized in that: include: The participating nodes in the first-level node set are used to broadcast reference data to the other participating nodes in the same set; Based on the reference data, a first-level voting node is elected through voting; The participating nodes in the second-level node set are used to broadcast reference data to other participating nodes in the same set; Based on the reference data, multiple second-level voting nodes are elected by voting; Wherein, the first-level node set is composed of a plurality of second-level voting nodes as participating nodes, and a second-level voting node is voted and elected by all participating nodes in a second-level node set; The first-level voting node is used to send an election result message to all participating nodes in the first-level node set as a leader node; The participating nodes in the first-level node set are used to send election result messages to all participating nodes in the corresponding second-level node set; The participating nodes in the first-level node set are used for each round of voting. If they receive votes from two or more voting nodes in the second-level node set, they accept the votes from the voting nodes with larger ZXID values, reject the votes from the voting nodes with smaller ZXID values, and send an alarm message; The participating nodes in the second-level node set are used to vote for the second-level voting nodes after receiving the alarm message; The participating nodes in the first-level node set are used to intervene in the election process of the second-level node set when a certain number of rounds have passed and the voting nodes of the higher-level node set of the node set have been selected, if the node set has not selected a valid voting node.

8. The system according to claim 7, characterized in that The distributed system includes a set of N-level nodes, where N is an integer greater than 3; the system includes: The participating nodes in the Nth level node set are used to broadcast reference data to other participating nodes in the same set; based on the reference data, the Nth level voting nodes are voted to be the N-1th level participating nodes; wherein the Nth level node set is formed by dividing all participating nodes in the distributed system; The participating nodes in the M-1th level node set are used to broadcast reference data to other participating nodes in the same set; based on the reference data, the M-1th level voting nodes are voted to be the M-2th level participating nodes; wherein the M-1th level node set is formed by dividing the Mth level voting nodes as participating nodes; wherein M is an integer equal to N to 3 in sequence; The participating nodes in the M-1th level node set are also used to send election result messages to all participating nodes in the corresponding Mth level node set; wherein M is an integer equal to 3 to N respectively.

9. An electronic device, characterized in that: include: at least one processor; as well as, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can perform the method according to any one of claims 1 to 6.

10. A non-transitory computer-readable storage medium, characterized in that: The non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute any one of the methods of claims 1 to 6.

Citation Information

Patent Citations

  • A hierarchical consensus method and system for a block chain

    CN109819003A