Cluster election method and device, equipment and storage medium
By introducing the inertia coefficient mechanism into the Raft algorithm, the problem of low availability of Raft algorithm in even node clusters is solved, and the overall availability and stability of the cluster is improved.
Patent Information
- Application Number
- CN202411927198.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-25
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2044-12-25
AI Technical Summary
The availability of Raft algorithm in even node clusters is lower than that of odd node clusters, and the cluster is easily unavailable when switching master nodes and changing nodes.
Introducing an inertia coefficient mechanism, candidate nodes set inertia coefficients based on the results of the previous round of elections, and determining whether they become the master node based on the results of the voting. A target value with an inertia coefficient greater than 0 indicates that it was the master node before, and a 0 indicates that it was the slave node before.
Improves the overall availability of Raft clusters in even node clusters, and reduces the cluster unavailability, especially in node changes and handover scenarios.
Smart Images

Figure CN119892848A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of cloud service technology, and in particular to a cluster election method, device, equipment and storage medium. Background Art
[0002] The Raft algorithm is a key consistency algorithm in the field of distributed systems. Based on the traditional consistency algorithm, it provides a simple and efficient way to ensure that the cluster reaches a consistent state. However, the Raft algorithm also has some inherent problems, including: 1. The availability of a cluster of N even nodes is lower than that of a cluster of (N-1) odd nodes. Specifically, if the availability of a node is 90%, the availability of a single-node Raft cluster is 90%, while a two-node Raft cluster requires both nodes to be available at the same time. After calculation, the overall availability is only 81%, which is lower than the single-node case. 2. The master node will automatically switch roles according to the Check Quorum mechanism. Once the master node loses connectivity with more than half of the nodes in the cluster, it will be downgraded to a slave node, resulting in a connection change; 3. During the node change operation, if an old node happens to be down after adding a server, the new node will catch up with the log. Since the condition of more than half of the nodes cannot be met, the entire Raft algorithm will fall into an unavailable state. Summary of the invention
[0003] The present disclosure provides a cluster election method, apparatus, device and storage medium.
[0004] According to a first aspect of the present disclosure, a cluster election method is provided, wherein the cluster includes at least one candidate node and at least one voting node; the method is applied to the candidate node, and the method includes:
[0005] Initiate a voting request to other nodes in the cluster except itself;
[0006] Receiving a first voting result from the other nodes;
[0007] Determine the inertia coefficient of the candidate node itself, and determine whether to become the master node based on the inertia coefficient and the first voting result;
[0008] Among them, the inertia coefficient is set based on the results of the previous round of elections. If the candidate node in the previous round of elections is a master node, its own inertia coefficient is set to a target value greater than 0; if the candidate node in the previous round of elections is a slave node, its inertia coefficient is set to 0.
[0009] According to a second aspect of the present disclosure, a cluster election device is provided, wherein the cluster includes at least one candidate node and at least one voting node; the device is applied to the candidate node, and the device includes:
[0010] A sending module, used to initiate a voting request to other nodes in the cluster except itself;
[0011] A receiving module, configured to receive the first voting result from the other nodes;
[0012] A processing module, used to determine the inertia coefficient of the candidate node itself, and determine whether to become the master node according to the inertia coefficient and the first voting result;
[0013] Among them, the inertia coefficient is set based on the results of the previous round of elections. If the candidate node in the previous round of elections is a master node, its own inertia coefficient is set to a target value greater than 0; if the candidate node in the previous round of elections is a slave node, its inertia coefficient is set to 0.
[0014] According to a third aspect of the present disclosure, there is provided an electronic device, including:
[0015] at least one processor; and
[0016] a memory communicatively connected to the at least one processor; wherein,
[0017] 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 in the present disclosure.
[0018] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause the computer to execute the method described in the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The above and other objects, features and advantages of the exemplary embodiments of the present disclosure will become readily understood by reading the detailed description below with reference to the accompanying drawings. In the accompanying drawings, several embodiments of the present disclosure are shown in an exemplary and non-limiting manner, in which:
[0020] In the drawings, the same or corresponding reference numerals represent the same or corresponding parts.
[0021] Figure 1 A schematic diagram of a cluster election method provided in an embodiment of the present disclosure;
[0022] Figure 2 A schematic diagram of the principle of an election method provided in an embodiment of the present disclosure;
[0023] Figure 3 A schematic diagram of a cluster provided in an embodiment of the present disclosure;
[0024] Figure 4 A schematic diagram of the structure of a cluster election device provided in an embodiment of the present disclosure;
[0025] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0026] In order to make the purpose, features, and advantages of the present disclosure more obvious and easy to understand, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present disclosure.
[0027] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it can be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0028] In the following description, the terms "first\second" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present disclosure described herein can be implemented in an order other than that illustrated or described herein.
[0029] Unless otherwise defined, all technical and scientific terms used in this disclosure have the same meaning as those commonly understood by those skilled in the art to which this disclosure belongs. The terms used in this disclosure are only for the purpose of describing the embodiments of this disclosure and are not intended to limit this disclosure.
[0030] It should be understood that in the various embodiments of the present disclosure, the size of the serial number of each implementation process does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present disclosure.
[0031] Figure 1 A schematic diagram of a cluster election method provided in an embodiment of the present disclosure; Figure 1 As shown, the method is applied to the candidate node, the cluster includes at least one candidate node and at least one voting node; the method includes:
[0032] Step 101: Initiate a voting request to other nodes in the cluster except itself;
[0033] Step 102: Receive the first voting result from the other nodes;
[0034] Step 103: determine the inertia coefficient of the candidate node itself, and determine whether to become the master node based on the inertia coefficient and the first voting result;
[0035] Among them, the inertia coefficient is set based on the results of the previous round of elections. If the candidate node in the previous round of elections is a master node, its own inertia coefficient is set to a target value greater than 0; if the candidate node in the previous round of elections is a slave node, its inertia coefficient is set to 0.
[0036] In some embodiments, the cluster includes at least one candidate node and at least one voting node, wherein the candidate node refers to a node that is expected to become a master node after election during the voting process; the number of candidate nodes is 1 or more. If there are multiple candidate nodes, assuming that a candidate node becomes a master node (Leader) after election, the other candidate nodes become followers accordingly.
[0037] Voting nodes refer to nodes that participate in voting except candidate nodes. In other words, voting nodes are nodes in the cluster that vote for candidate nodes. After the master node is determined through election, the voting node becomes a slave node.
[0038] The cluster may be a Raft algorithm cluster, referred to as a Raft cluster.
[0039] Here, the inertia coefficient is a target value greater than 0, and there is no limitation on the specific value of the target value, for example, it can be 0.1, 0.5, etc.
[0040] Here, each candidate node determines whether to become the master node based on the inertia coefficient and the first voting result. In this way, due to the existence of the inertia coefficient, the entire cluster tends to maintain the previous state of each node in the cluster. If the master node is the master node in the previous round, and the master node has a large inertia coefficient, the overall availability of the cluster based on the Raft algorithm can be improved in even-numbered node clusters, node changes, and node switching scenarios, greatly reducing the possibility of cluster unavailability.
[0041] In some embodiments, determining whether to become a master node based on the inertia coefficient and the first voting result includes:
[0042] determining a sum of the inertia coefficient and the first voting result as a second voting result;
[0043] If the second voting result is greater than the target threshold, it is determined that the node becomes the master node; the target threshold is determined based on the total number of nodes in the cluster.
[0044] Here, for the Raft cluster, the target threshold may be half of the total number of nodes in the cluster.
[0045] Specifically, after a normal voting election, the master node automatically sets the inertia coefficient to be greater than 0, such as 0.5, and the slave node defaults to its own inertia coefficient of 0;
[0046] In subsequent voting scenarios, such as when the slave node is offline or is in the quorum under the Check Quorum mechanism, due to the existence of the inertia coefficient, the candidate node calculates the vote based on the submitted data in the following way: (1+inertia coefficient), that is, if the candidate node was the master node before, then the candidate node's own votes in this vote are 1.5 votes; if it was the slave node before, then the candidate node's own votes in this vote are 1 vote.
[0047] The calculation method for more than half of the votes is: quorum>(voters / 2); voters represents the number of nodes participating in the election process in a Raft cluster or distributed system, and here quorum>(voters / 2) means that quorum can be a non-integer. Based on the above formula, even in an even-numbered node cluster, node change, and node switching scenario, due to the inertia coefficient, there must be a candidate node that can satisfy quorum>(voters / 2), that is, the candidate node is elected as the master node.
[0048] In some embodiments, if the candidate node becomes the master node, the method further includes:
[0049] Set its own inertia coefficient to the target value.
[0050] Here, if the candidate node becomes the master node, it can set its own inertia coefficient as the target value, so that when an election is needed again in the future, it can determine whether to become the master node based on its own inertia coefficient and the first voting result (the first voting result represents the number of votes received from other nodes).
[0051] In this way, due to the existence of the inertia coefficient, the entire cluster tends to maintain the previous state of each node in the cluster. If the previous round is the master node, and the master node has a large inertia coefficient, the overall availability of the cluster based on the Raft algorithm can be improved in even-numbered node clusters, node changes, and node switching scenarios.
[0052] In some embodiments, if a master node failure occurs after the candidate node becomes the master node, the method further includes:
[0053] Set its own inertia coefficient to 0.
[0054] Here, if the master node fails, the cluster re-elects. If the failed master node recovers, it needs to rejoin the cluster. At this time, since it has become a slave node, it sets its own inertia coefficient to 0.
[0055] Moreover, due to the failure of the master node, the inertia coefficients of all nodes actually need to be reset, that is, the other slave nodes subsequently re-determine a master node through election, and the master node sets its own inertia coefficient as the target value. After the failed master node recovers and rejoins the cluster, it sets its own inertia coefficient to 0, just like the other slave nodes.
[0056] After the above inertia coefficient is set, in subsequent voting scenarios, the inertia coefficient can still be used to make the entire cluster tend to maintain the previous state of each node in the cluster.
[0057] In some embodiments, the determining whether the node becomes the master node further includes:
[0058] Check whether a heartbeat signal from the master node is received. If the heartbeat signal is received, it is determined to be a slave node.
[0059] Here, during the election process, the candidate node can also detect whether it has received a heartbeat signal from the master node, that is, determine whether the master node has been elected. If it receives the heartbeat signal, that is, receives the heartbeat signal sent by the new master node, it directly determines that it has become a slave node. In this way, the candidate node can know the latest master node in real time.
[0060] In some embodiments, if the candidate node becomes a slave node, the method further includes:
[0061] Set its own inertia coefficient to 0.
[0062] Here, if the candidate node becomes a slave node, it can set its own inertia coefficient to 0, so that when it is re-elected later, it can determine whether to become the master node based on the inertia coefficient and the first voting result.
[0063] In this way, due to the existence of the inertia coefficient, the entire cluster tends to maintain the previous state of each node in the cluster. If the previous round is the master node, and the master node has a large inertia coefficient, the overall availability of the cluster based on the Raft algorithm can be improved in even-numbered node clusters, node changes, and node switching scenarios.
[0064] In some embodiments, the voting request includes: a leadership election period determined by the candidate node;
[0065] If the candidate node is determined to become the master node, the method further includes:
[0066] A heartbeat signal is sent to other nodes in the cluster except itself, wherein the heartbeat signal is used to inform other nodes that it is a master node, and the heartbeat signal includes: the leader election cycle.
[0067] Here, a cluster usually consists of multiple nodes that cooperate with each other, which may be servers, virtual machines, or other computing units.
[0068] A heartbeat signal is a signal sent periodically between nodes. It can be a simple data packet or a specific message. For example, in a cluster consisting of servers A, B, and C, server A, as the master node, can send a heartbeat signal to servers B and C at regular intervals (such as every 2 seconds) to inform servers B and C that the current master node is operating normally and that it is communicating normally with the master node.
[0069] Here, the heartbeat signal that the master node sends to all slave nodes periodically can include the current term number. The term is used to ensure the consistency of nodes in the system and help the slave nodes determine the current leadership election status. In this way, the slave nodes are ensured to know that the current term number of the master node is the latest, thereby maintaining the consistency of the cluster. If the term number received by the slave node is higher than its current term number, it will update its own term number to keep it consistent with the master node.
[0070] Figure 2 A schematic diagram of the principle of an election method provided in an embodiment of the present disclosure; Figure 2 In the table, leader refers to the primary node, follower refers to the secondary node, and candidate refers to the candidate node;
[0071] Term means: a time period number, used to distinguish different leader election cycles.
[0072] Discovering a new leader and starting a new term means: When a node discovers a new leader, it updates its term to the new leader's term, indicating that the current node is now in a new leadership election cycle.
[0073] Encountering a higher term means: If the term in the message received by a node is higher than the term of the current node, the node will update its own term to a higher value and change to the follower state, indicating that it has followed a leader with a higher term.
[0074] The nodes in the Raft cluster have an inertia coefficient variable with an initial value of 0. After the primary node is elected through normal voting, the leader automatically sets the inertia coefficient to be greater than 0, such as 0.5. The leader's votes (votes, which can also be understood as voting rights or number of votes) are Figure 2 1.5 in the example, the default inertia coefficient of the follower is 0, so the leader’s own vote is Figure 2 1 in .
[0075] It should be noted that the candidate in the figure can be any node or the leader of the previous round. If it becomes the leader again, the inertia coefficient is also set to be greater than 0 after the election in this round, such as 0.5, and its votes in the next round are 1.5.
[0076] In subsequent voting scenarios, such as the follower node being offline, or being in the quorum under the Check Quorum mechanism (the Check Quorum mechanism means that the master node will try to connect to the slave nodes in the cluster (send heartbeats) at regular intervals. If it finds that the number of nodes it can connect to does not exceed half, it will actively switch to the slave node), due to the existence of the inertia coefficient, the voting calculation method for data submission is: (1+inertia coefficient), that is, if it was the master node before, the number of votes was 1.5 votes, and if it was the follower node before, the number of votes was 1 vote.
[0077] The calculation method for more than half of the votes is: quorum>(voters / 2), where voters represents the number of all nodes participating in the election process of a Raft cluster or distributed system, and quorum>(voters / 2) means that quorum can be a non-integer. Using the above method, if the leader fails, after the leader is elected according to the normal process, the inertia coefficient of the node is reset. For the previously failed leader, even if it joins again, it has become a follower. Therefore, it sets its own inertia coefficient to 0, and the overall Raft election process does not change.
[0078] In this way, even in scenarios with an even number of nodes, more than half of the votes will still be obtained, thus avoiding the problems of leader downgrade and inability to elect a master. The leader of the Raft cluster still exists and maintains availability. Under the Check Quorum mechanism, the leader will still be re-elected as the leader due to its large inertia coefficient, and the master node will not switch. For Raft clusters with an odd number of nodes, the inertia coefficient will not affect the Raft algorithm, and all links of the entire cluster will be handled in the same way as before. Node changes may cause the Raft cluster to be unavailable, but due to the existence of the inertia coefficient, the leader has a higher voting right and the cluster is still available.
[0079] In this way, the method provided by the embodiment of the present disclosure can greatly reduce the situation where the cluster is unavailable.
[0080] Figure 3 A schematic diagram of a cluster provided in an embodiment of the present disclosure; Figure 3 As shown in the figure, S1, S2, S3, and S4 all represent servers, which are nodes in the cluster. Assume that after adding a new server S4 to the cluster, server S3 crashes, and server S4 needs to catch up with the log (that is, obtain the log entries that have been generated and replicated in the cluster before it joins). If the traditional method is used, the Raft cluster will be unavailable at this time because there is no more than half of the nodes.
[0081] If the method provided by the embodiment of the present disclosure is adopted, due to the existence of the inertia coefficient, the entire cluster tends to maintain the previous state of each node in the cluster. If the previous round is the master node, and the master node has a large inertia coefficient, if a new server S4 is added to the cluster and server S3 crashes, even if server S4 needs to catch up with the log, due to the existence of the inertia coefficient, the entire cluster tends to maintain the previous state of each node in the cluster, and the Raft cluster is still available.
[0082] Specifically, the cluster election method provided by the embodiment of the present disclosure may include: the cluster has servers S1, S2, and S3. Assuming that server S1 is the master node, after adding a new server S4, server S3 crashes. Due to the existence of the inertia coefficient, even if server S1 has a larger inertia coefficient as the master node, its vote result is still greater than half, and the Raft cluster is still available. After server S4 completes log replication, the cluster includes servers S1, S2, and S4. If an election is required, the above method can continue to be used; that is, since server S1 is the master node among servers S1, S2, and S4, and servers S2 and S4 are slave nodes, server S1 sets its own inertia coefficient to the target value (such as 0.5), and servers S2 and S4 set their own inertia coefficients to 0. If the node becomes a candidate node later, it can still determine whether it becomes the master node based on the inertia coefficient and the voting result.
[0083] Figure 4 A schematic diagram of the structure of a cluster election device provided by an embodiment of the present disclosure; Figure 4 As shown, the cluster includes at least one candidate node and at least one voting node; the device is applied to the candidate node, and the device includes:
[0084] A sending module, used to initiate a voting request to other nodes in the cluster except itself;
[0085] A receiving module, configured to receive the first voting result from the other nodes;
[0086] A processing module, used to determine the inertia coefficient of the candidate node itself, and determine whether to become the master node according to the inertia coefficient and the first voting result;
[0087] Among them, the inertia coefficient is set based on the results of the previous round of elections. If the candidate node in the previous round of elections is a master node, its own inertia coefficient is set to a target value greater than 0; if the candidate node in the previous round of elections is a slave node, its inertia coefficient is set to 0.
[0088] In some embodiments, the processing module is used to determine the sum of the inertia coefficient and the first voting result as the second voting result;
[0089] If the second voting result is greater than the target threshold, it is determined that the node becomes the master node; the target threshold is determined based on the total number of nodes in the cluster.
[0090] In some embodiments, if the candidate node becomes the master node, the processing module is further configured to set its own inertia coefficient as a target value.
[0091] In some embodiments, if a master node failure occurs after the candidate node becomes the master node, the processing module is further used to set its own inertia coefficient to 0.
[0092] In some embodiments, the processing module is further used to detect whether a heartbeat signal from the master node is received, and if the heartbeat signal is received, it is determined to become a slave node.
[0093] In some embodiments, if the candidate node becomes a slave node, the processing module is further configured to set its own inertia coefficient to 0.
[0094] In some embodiments, the voting request includes: a leadership election period determined by the candidate node;
[0095] If the candidate node is determined to become the master node, the processing module is further used to send a heartbeat signal to other nodes in the cluster except itself, and the heartbeat signal is used to inform other nodes that it is the master node. The heartbeat signal includes: the leader election cycle.
[0096] It is understandable that the cluster election device provided in the above embodiment can distribute the above processing to different program modules as needed when implementing the corresponding cluster election method, so as to complete all or part of the above-described processing. In addition, the device provided in the above embodiment and the embodiment of the corresponding method belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.
[0097] An embodiment of the present disclosure provides a computer-readable storage medium storing executable instructions, wherein the executable instructions are stored. When the executable instructions are executed by a processor, the processor is triggered to execute the cluster election method provided by the embodiment of the present disclosure.
[0098] In some embodiments, the computer-readable storage medium may be a ferroelectric random access memory (FRAM), a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a flash memory, a magnetic surface memory, an optical disk, or a CD-ROM; it may also be various devices including one or any combination of the above memories.
[0099] In some embodiments, executable instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, model, subroutine or other unit suitable for use in a computing environment.
[0100] By way of example, executable instructions may be deployed to be executed on one computing device, or on multiple computing devices located at one site, or on multiple computing devices distributed across multiple sites and interconnected by a communication network.
[0101] An embodiment of the present disclosure provides a computer program product, which includes a computer program / instructions. When the computer program / instructions are executed by a processor, the cluster election method described in the present disclosure is implemented.
[0102] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure; Figure 5 As shown, the electronic device 50 includes: a processor 501 and a memory 502 for storing a computer program that can be run on the processor; when the processor 501 is used to run the computer program, it executes the cluster election method provided in the embodiment of the present disclosure.
[0103] In actual application, the electronic device 50 may further include: at least one network interface 503. The various components in the electronic device 50 are coupled together via a bus system 504. It is understood that the bus system 504 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 504 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, Figure 5 In the figure, various buses are all labeled as bus system 504. There may be at least one processor 501. The network interface 503 is used for wired or wireless communication between the electronic device 50 and other devices.
[0104] The memory 502 in the embodiment of the present disclosure is used to store various types of data to support the operation of the electronic device 50 .
[0105] The method disclosed in the above embodiment of the present disclosure can be applied to the processor 501, or implemented by the processor 501. The processor 501 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit in the processor 501 or the instruction in the form of software. The above processor 501 can be a general processor, a digital signal processor (DSP, DiGital Signal Processor), or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The processor 501 can implement or execute the disclosed methods, steps and logic block diagrams in the embodiment of the present disclosure. The general processor can be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiment of the present disclosure can be directly embodied as a hardware decoding processor to execute, or the hardware and software modules in the decoding processor can be combined to execute. The software module can be located in a storage medium, which is located in the memory 502. The processor 501 reads the information in the memory 502 and completes the steps of the above method in combination with its hardware.
[0106] In some embodiments, the electronic device 50 can be implemented by one or more application specific integrated circuits (ASIC), DSP, programmable logic device (PLD), complex programmable logic device (CPLD), field programmable gate array (FPGA), general processor, controller, microcontroller (MCU), microprocessor, or other electronic components to execute the aforementioned method.
[0107] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0108] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of the present disclosure, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0109] The above is only a specific embodiment of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any person skilled in the art who is familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present disclosure, which should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A cluster election method, characterized in that: The cluster includes at least one candidate node and at least one voting node; the method is applied to the candidate node, and the method includes: Initiate a voting request to other nodes in the cluster except itself; Receiving a first voting result from the other nodes; Determine the inertia coefficient of the candidate node itself, and determine whether to become the master node based on the inertia coefficient and the first voting result; Among them, the inertia coefficient is set based on the results of the previous round of elections. If the candidate node in the previous round of elections is a master node, its own inertia coefficient is set to a target value greater than 0; if the candidate node in the previous round of elections is a slave node, its inertia coefficient is set to 0.
2. The method according to claim 1, characterized in that The determining whether to become a master node according to the inertia coefficient and the first voting result includes: determining a sum of the inertia coefficient and the first voting result as a second voting result; If the second voting result is greater than the target threshold, it is determined that the node becomes the master node; the target threshold is determined based on the total number of nodes in the cluster.
3. The method according to claim 1 or 2, characterized in that: If the candidate node becomes the master node, the method further includes: Set its own inertia coefficient to the target value.
4. The method according to claim 3, characterized in that If a master node failure occurs after the candidate node becomes the master node, the method further includes: Set its own inertia coefficient to 0.
5. The method according to claim 1 or 2, characterized in that: The step of determining whether the node itself becomes the master node also includes: Check whether a heartbeat signal from the master node is received. If the heartbeat signal is received, it is determined to be a slave node.
6. The method according to claim 5, characterized in that If the candidate node becomes a slave node, the method further includes: Set its own inertia coefficient to 0.
7. The method according to claim 1, characterized in that The voting request includes: a leadership election cycle determined by the candidate node; If the candidate node is determined to become the master node, the method further includes: A heartbeat signal is sent to other nodes in the cluster except itself, wherein the heartbeat signal is used to inform other nodes that it is a master node, and the heartbeat signal includes: the leader election cycle.
8. A cluster election device, characterized in that: The cluster includes at least one candidate node and at least one voting node; the device is applied to the candidate node, and the device includes: A sending module, used to initiate a voting request to other nodes in the cluster except itself; A receiving module, configured to receive the first voting result from the other nodes; A processing module, used to determine the inertia coefficient of the candidate node itself, and determine whether to become the master node according to the inertia coefficient and the first voting result; Among them, the inertia coefficient is set based on the results of the previous round of elections. If the candidate node in the previous round of elections is a master node, its own inertia coefficient is set to a target value greater than 0; if the candidate node in the previous round of elections is a slave node, its inertia coefficient is set to 0.
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 executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to execute: Initiate a voting request to other nodes in the cluster except itself; Receiving a first voting result from the other nodes; Determine the inertia coefficient of the candidate node itself, and determine whether to become the master node based on the inertia coefficient and the first voting result; Among them, the inertia coefficient is set based on the results of the previous round of elections. If the candidate node in the previous round of elections is a master node, its own inertia coefficient is set to a target value greater than 0; if the candidate node in the previous round of elections is a slave node, its inertia coefficient is set to 0.
10. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to cause the computer to execute: Initiate a voting request to other nodes in the cluster except itself; Receiving a first voting result from the other nodes; Determine the inertia coefficient of the candidate node itself, and determine whether to become the master node based on the inertia coefficient and the first voting result; Among them, the inertia coefficient is set based on the results of the previous round of elections. If the candidate node in the previous round of elections is a master node, its own inertia coefficient is set to a target value greater than 0; if the candidate node in the previous round of elections is a slave node, its inertia coefficient is set to 0.
Citation Information
Patent Citations
A method to enhance the reliability of the cluster and a high reliability communication node
CN101217402A
Cluster main node voting method and device
CN106331046A
Node synchronization method, device and equipment of block chain and storage medium
CN111586147A
Distributed cluster election method and device
CN115801773A
Main node selection method and device in consensus algorithm, electronic equipment and storage medium
CN115883308A