A cluster election method, device, apparatus and storage medium

By introducing an inertia coefficient mechanism into the Raft algorithm, and combining voting results and heartbeat signals, the availability problem of the Raft algorithm in even-numbered node clusters and when nodes change is solved, thereby improving the stability and availability of the cluster.

CN119892848BActive Publication Date: 2026-02-27LENOVO (BEIJING) LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411927198.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-25
Publication Date
2026-02-27
Estimated Expiration
2044-12-25

AI Technical Summary

Technical Problem

The Raft algorithm has several drawbacks in distributed systems, including lower availability for clusters with even-numbered nodes compared to clusters with odd-numbered nodes, automatic switching of master node roles leading to connection changes, and unavailability when nodes are changed.

Method used

An inertia coefficient mechanism is introduced, which sets the inertia coefficient of candidate nodes based on the results of the previous election, and determines whether to become the master node based on the voting results. The cluster state consistency is maintained through heartbeat signals.

Benefits of technology

It improves the availability of the Raft algorithm in even-numbered node clusters and node change scenarios, reduces cluster unavailability, and maintains the stability of node states within the cluster.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119892848B_ABST
    Figure CN119892848B_ABST
Patent Text Reader

Abstract

The present disclosure provides a cluster election method, device, equipment and storage medium, 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 comprises: initiating a voting request to other nodes in the cluster except itself;Receive the first voting result from the other nodes;Determine the inertia coefficient of the candidate node itself, determine whether itself becomes the master node according to the inertia coefficient and the first voting result together;Wherein, the inertia coefficient is set based on the last election result, if the candidate node is the master node in the last election result, set its own inertia coefficient to a target value greater than 0, if the candidate node is the slave node in the last election result, set the inertia coefficient to 0.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present disclosure relates to the technical field of cloud services, and particularly relates to a cluster election method and device, equipment and a storage medium. BACKGROUND

[0002] Raft algorithm is a key consensus algorithm in the field of distributed systems, which provides a simple and efficient way to ensure that the cluster reaches a consistent state on the basis of traditional consensus algorithms. However, the Raft algorithm also has some inherent problems, including: 1. The availability of an N even node cluster is lower than that of an (N-1) odd node cluster. 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, and the overall availability is only 81%, which is lower than that of a 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, such as adding a new server after an old node is down, the new node cannot catch up with the log during the period, and the entire Raft algorithm will be in an unusable state due to the inability to meet the condition of more than half of the nodes. SUMMARY

[0003] The present disclosure provides a cluster election method, device, equipment and storage medium.

[0004] According to a first aspect of the present disclosure, a cluster election method is provided, the cluster comprising at least one candidate node and at least one voting node; the method is applied to the candidate node, and the method comprises:

[0005] initiating a voting request to other nodes in the cluster except itself;

[0006] receiving a first voting result from the other nodes;

[0007] determining an inertia coefficient of the candidate node itself, and determining whether the candidate node itself becomes a master node according to the inertia coefficient and the first voting result;

[0008] wherein the inertia coefficient is set based on the last round of election results. If the candidate node is a master node in the last round of election results, the inertia coefficient of the candidate node itself is set to a target value greater than 0, and if the candidate node is a slave node in the last round of election results, the inertia coefficient is set to 0.

[0009] According to a second aspect of the present disclosure, a cluster election device is provided, the cluster comprising at least one candidate node and at least one voting node; the device is applied to the candidate node, and the device comprises:

[0010] sending a voting request to other nodes in the cluster except itself;

[0011] receiving a first voting result from the other nodes;

[0012] determining an inertia coefficient of the candidate node itself, and determining whether the candidate node itself becomes a master node according to the inertia coefficient and the first voting result;

[0013] The inertia coefficient is set based on a last round of election result. If the candidate node is a master node in the last round of election result, the inertia coefficient of the candidate node itself is set as a target value greater than 0. If the candidate node is a slave node in the last round of election result, the inertia coefficient is set as 0.

[0014] According to a third aspect of the present disclosure, an electronic device is provided, comprising:

[0015] at least one processor; and

[0016] a memory connected with the at least one processor in communication; wherein

[0017] The memory stores instructions executable 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 of 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, and the computer instructions are used to enable the computer to perform the method of the present disclosure. BRIEF DESCRIPTION OF DRAWINGS

[0019] The above and other objects, features and advantages of the present disclosure exemplary embodiments will be readily understood through reading the detailed description below taken in conjunction with the accompanying drawings. In the drawings, several embodiments of the present disclosure are illustrated, by way of example, and not limitation, in which:

[0020] In the drawings, the same or corresponding parts are denoted by the same or corresponding reference numerals.

[0021] Figure 1 A flowchart of a cluster election method provided by an embodiment of the present disclosure;

[0022] Figure 2 A principle diagram of an election method provided by an embodiment of the present disclosure;

[0023] Figure 3 A diagram of a cluster provided by an embodiment of the present disclosure;

[0024] Figure 4 A structural schematic diagram of a cluster election device provided by an embodiment of the present disclosure is provided.

[0025] Figure 5 A structural schematic diagram of an electronic device provided by an embodiment of the present disclosure is provided. DETAILED DESCRIPTION

[0026] In order to make the objectives, 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 with reference to the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, but not all the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by those skilled in the art without creative work fall within the scope of the present disclosure.

[0027] In the following description, "some embodiments" are described, which describe a subset of all possible embodiments, but it can be understood that "some embodiments" can be the same subset or different subset of all possible embodiments, and can be combined with each other without conflict.

[0028] In the following description, the term "first\second" is only to distinguish similar objects, and does not represent a specific order of the objects. It can be understood that "first\second" can be interchanged in a specific order or sequence as allowed, 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 the present disclosure have the same meaning as commonly understood by those skilled in the art to which the present disclosure belongs. The terms used in the present disclosure are only for the purpose of describing the embodiments of the present disclosure, and are not intended to limit the present disclosure.

[0030] It should be understood that in various embodiments of the present disclosure, the size of the serial number of each implementation process does not mean the order of execution, and the execution order of each process should be determined by its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiments of the present disclosure.

[0031] Figure 1 A flowchart of a cluster election method provided by an embodiment of the present disclosure is provided. As shown in the figure, the method is applied to the candidate node, and the cluster includes at least one candidate node and at least one voting node. The method includes: Figure 1

[0032] Step 101, initiating a voting request to other nodes in the cluster except itself;

[0033] Step 102, receiving a first voting result from the other nodes;​

[0034] determining whether to become the leader node according to the inertia coefficient and the first voting result;

[0035] The inertia coefficient is set based on a last round of election result. If the candidate node is the leader node in the last round of election result, the inertia coefficient of the candidate node is set as a target value greater than 0. If the candidate node is a follower node in the last round of election result, the inertia coefficient is set as 0.

[0036] In some embodiments, the cluster includes at least one candidate node and at least one voting node. The candidate node refers to a node expected to become the leader node through the election in the voting process. The number of candidate nodes is one or more. If there are multiple candidate nodes, it is assumed that a certain candidate node becomes the leader node (Leader) through the election, and other candidate nodes become follower nodes (Follower) accordingly.

[0037] The voting node refers to a node participating in the voting in addition to the candidate node, that is, the voting node is a node in the cluster voting for the candidate node. After the leader node is determined through the election, the voting node becomes a follower node.

[0038] The cluster can be a cluster of a Raft algorithm, referred to as a Raft cluster.

[0039] Here, the target value of the inertia coefficient is greater than 0. The specific value of the target value is not limited, for example, it can be 0.1, 0.5, etc.

[0040] Here, each candidate node determines whether to become the leader node according to the inertia coefficient and the first voting result. Thus, due to the inertia coefficient, the entire cluster tends to maintain the previous state of each node in the cluster. If the last round is the leader node, and the leader node has a large inertia coefficient, the overall availability of the cluster based on the Raft algorithm can be improved in the even node cluster, node change and node switching scenarios, greatly reducing the situation of cluster unavailability.

[0041] In some embodiments, the determining whether to become the leader node according to the inertia coefficient and the first voting result includes:

[0042] determining the sum of the inertia coefficient and the first voting result as a second voting result;

[0043] If the second voting result is greater than a target threshold, it is determined that the candidate node becomes the leader node. The target threshold is determined based on the total number of nodes in the cluster.

[0044] Here, for a Raft cluster, the target threshold can 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, for example, 0.5, and the follower node defaults the inertia coefficient of itself to be 0.

[0046] In each subsequent voting scenario, such as a follower node being offline or being in a quorum under the Check Quorum mechanism, due to the inertia coefficient, the candidate node calculates the voting according to the submitted data in the following manner: (1 + inertia coefficient), that is, if the candidate node is a master node before, the number of votes of the candidate node itself in this voting is 1.5 votes, and if it is a follower node before, the number of votes of the candidate node itself in this voting is 1 vote.

[0047] The calculation method of more than half of the votes is: quorum > (voters / 2); voters represents the number of all nodes participating in the voting in the election process of a Raft cluster or distributed system, and here quorum > (voters / 2) indicates that quorum can be a non-integer. Based on the above formula, even in the scenarios of an even number of nodes in a cluster, node changes, and node switching, due to the inertia coefficient, there must be a candidate node that can satisfy quorum > (voters / 2), that is, the candidate node becomes a master node after the election.

[0048] In some embodiments, if the candidate node becomes a master node, the method further comprises:

[0049] setting the inertia coefficient of itself to be the target value.

[0050] Here, if the candidate node becomes a master node, it can set the inertia coefficient of itself to be the target value, so that in the case of subsequent re-election, it can determine whether to become a master node according to the inertia coefficient of itself 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 inertia coefficient, the entire cluster tends to maintain the previous state of each node in the cluster. If the last round is a master node, and the master node has a large inertia coefficient, it can improve the overall availability of the cluster based on the Raft algorithm in the scenarios of an even number of nodes in a cluster, node changes, and node switching.

[0052] In some embodiments, if the candidate node becomes a master node and a master node failure occurs, the method further comprises:

[0053] setting the inertia coefficient of itself to be 0.

[0054] Here, if the master node fails, the cluster re-election, the failure of the master node if the recovery needs to re-join the cluster, at this time, because it has become a slave node, so it sets its own inertia coefficient to 0.

[0055] And because of the master node failure, the inertia coefficient of all nodes needs to be reset, that is, the other slave nodes are re-determined by the subsequent election of a master node, which sets its own inertia coefficient to the target value, and the failed master node after rejoining the cluster after recovery, the same as other slave nodes, sets its own inertia coefficient to 0.

[0056] Through the above setting of the inertia coefficient, in the subsequent each voting scene, the existence of 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 to become a master node further comprises:

[0058] Detecting whether a heartbeat signal from the master node is received, and if the heartbeat signal is received, determining to become a slave node.

[0059] Here, in the election process, the candidate node can also detect whether a heartbeat signal from the master node is received, that is, whether a master node has been elected, if the heartbeat signal is received, that is, the heartbeat signal sent by the new master node is received, then directly determine itself to become a slave node. In this way, the candidate node can immediately know the latest master node.

[0060] In some embodiments, if the candidate node becomes a slave node, the method further comprises:

[0061] Setting 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 in the subsequent election again, it can determine whether to become a master node according to the inertia coefficient and the first voting result jointly.

[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 last round is the master node, and the master node has a larger inertia coefficient, it can improve the overall availability of the cluster based on the Raft algorithm in the even-numbered node cluster, node change and node switching scene.

[0064] In some embodiments, the voting request comprises: a leader election period determined by the candidate node.

[0065] If the candidate node determines to become a master node, the method further comprises:

[0066] sending a heartbeat signal to other nodes in the cluster except itself, the heartbeat signal being used to inform other nodes that itself is a master node, the heartbeat signal including: the leader election period.

[0067] Here, the cluster is usually composed of multiple nodes that cooperate with each other, which can be servers, virtual machines or other computing units.

[0068] The heartbeat signal is a signal periodically sent between nodes, which can be a simple data packet or a specific message. For example, in a cluster composed of servers A, B and C, server A as the master node can send a heartbeat signal to servers B and C every certain time (e.g., every 2 seconds) to inform servers B and C that the current master node is running normally and it is in normal communication with the master node.

[0069] Here, the heartbeat signal periodically sent by the master node to all follower nodes can contain the current term number. The term is used to ensure the consistency of nodes in the system and to help follower nodes judge the current leader election state. In this way, it is ensured that the follower nodes know that the term number of the current master node is the latest, thereby maintaining the consistency of the cluster. If the term number received by the follower node is higher than the current term number of itself, it will update its own term number to keep consistent with the master node.

[0070] Figure 2 A principle schematic diagram of an election method provided by an embodiment of the present disclosure; Figure 2 Here, leader represents master node, follower represents follower node, and candidate represents candidate node.

[0071] Term represents: the number of a time period, used to distinguish different leader election periods.

[0072] Discovering a new leader and starting a new term means: when a node discovers a new leader, it will update its own term to the term of the new leader, indicating that the current node is now in a new leader election period.

[0073] Meeting 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 a follower state, indicating that it has followed a leader of a higher term.

[0074] The nodes in the Raft cluster have an inertia coefficient variable, the initial value of which is 0, and after the normal voting elects the master node, the leader automatically sets the inertia coefficient to be greater than 0, such as 0.5, and the vote (which can also be understood as the voting right or the number of votes) of the leader is 1.5 in the formula (1 + inertia coefficient), and the default inertia coefficient of the follower is 0, so the vote of the leader itself is 1 in the formula (1 + inertia coefficient). Figure 2 Figure 2

[0075] It should be noted that the candidate in the figure can be any node or the leader of the last round, and if it becomes the leader again, the inertia coefficient is also set to be greater than 0, such as 0.5, after the election in this round, and the vote in the next round is 1.5.

[0076] In the subsequent voting scenarios, such as follower node offline or Check Quorum mechanism (the Check Quorum mechanism refers to every period of time, the master node will try to connect to the follower nodes (send heartbeat), and if the number of nodes that can be connected to itself does not exceed half, it will actively switch to a follower node), under the condition of half nodes (quorum), due to the existence of the inertia coefficient, the voting calculation method for data submission is (1 + inertia coefficient), that is, the vote number of the previous master node is 1.5 votes, and the vote number of the previous follower node is 1 vote.

[0077] The calculation method of more than half of the votes adopted is: quorum > (voters / 2), where voters represents the number of all nodes participating in the voting in the election process of a Raft cluster or distributed system, and quorum > (voters / 2) indicates that quorum can be a non-integer. In the above way, if the leader fails, the inertia coefficient of the node is reset after the leader is selected according to the normal process, and for the previous failed leader, even if it joins again, it has become a follower, so the inertia coefficient of the leader is set to 0, and the overall Raft election process does not change.

[0078] ​​Thus, even in scenarios such as an even number of nodes, more than half of the votes can still be obtained, the problem of leader degradation and inability to select a master can be avoided, and the leader of the Raft cluster still exists and remains available; under the Check Quorum mechanism, the leader is still reselected as the leader due to the large inertia coefficient, and the master node switching does not occur; for an odd number of nodes of the Raft cluster, the inertia coefficient does not affect the Raft algorithm, and the entire cluster does not change in terms of processing as before the Raft cluster; for the case that the Raft cluster may become unavailable due to node changes, the leader has a higher voting right due to the inertia coefficient, and the cluster is still available.

[0079] Thus, by the method provided in the embodiments of the present disclosure, the situation of cluster unavailability can be greatly reduced.

[0080] Figure 3 A schematic diagram of a cluster is provided in the embodiments of the present disclosure; as shown in Figure 3 S1, S2, S3, and S4 all represent servers, which are nodes in the cluster. It is assumed that after a new server S4 is added to the cluster, server S3 is down, 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, at this time, the Raft cluster is unavailable due to the fact that there is no more than half of the nodes.

[0081] If the method provided in the embodiments of the present disclosure is used, the entire cluster tends to maintain the state of the nodes in the cluster before due to the existence of the inertia coefficient. If the last round is the master node, and the master node has a large inertia coefficient, if a new server S4 is added to the cluster after server S3 is down, even if server S4 needs to catch up with the log, the entire cluster tends to maintain the state of the nodes in the cluster before due to the existence of the inertia coefficient, and the Raft cluster is still available.

[0082] Specifically, the cluster election method provided in the embodiments of the present disclosure can include: the cluster has servers S1, S2, and S3. It is assumed that server S1 is the master node, after a new server S4 is added, server S3 is down, and due to the existence of the inertia coefficient, even if server S1 as the master node has a large inertia coefficient, the voting result is still more than half, and the Raft cluster is still available. After server S4 completes log replication, at this time, the cluster includes servers S1, S2, and S4, if election is needed, the above method can be continued; that is, since server S1 in servers S1, S2, and S4 is the master node, servers S2 and S4 are slave nodes, server S1 sets its own inertia coefficient to a target value (such as 0.5), servers S2 and S4 set their own inertia coefficients to 0, and in the future, if a node becomes a candidate node, it can still be determined whether to become a master node according to the joint action of the inertia coefficient and the voting result.

[0083] Figure 4 A structural schematic diagram of a cluster election device provided by an embodiment of the present disclosure; as shown in the figure, 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: Figure 4

[0084] a sending module configured to initiate a voting request to other nodes in the cluster except itself;

[0085] a receiving module configured to receive a first voting result from the other nodes;

[0086] a processing module configured to determine an inertia coefficient of the candidate node itself, and determine whether to become a master node according to the inertia coefficient and the first voting result;

[0087] wherein the inertia coefficient is set based on a last round election result, if the candidate node is a master node in the last round election result, the inertia coefficient of the candidate node itself is set as a target value greater than 0, and if the candidate node is a slave node in the last round election result, the inertia coefficient is set as 0.

[0088] In some embodiments, the processing module is configured to determine a sum of the inertia coefficient and the first voting result as a second voting result.

[0089] If the second voting result is greater than a target threshold value, the candidate node is determined to become a master node; the target threshold value is determined based on a total number of nodes in the cluster.

[0090] In some embodiments, if the candidate node becomes a master node, the processing module is further configured to set the inertia coefficient of the candidate node as the target value.

[0091] In some embodiments, if a master node failure occurs after the candidate node becomes a master node, the processing module is further configured to set the inertia coefficient of the candidate node as 0.

[0092] In some embodiments, the processing module is further configured to detect whether a heartbeat signal from a master node is received, and if the heartbeat signal is received, the candidate node 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 the inertia coefficient of the candidate node as 0.

[0094] In some embodiments, the voting request includes a leader election period determined by the candidate node.

[0095] ​If the candidate node determines to become the master node, the processing module is further configured to send a heartbeat signal to other nodes in the cluster except for the candidate node itself, the heartbeat signal being used to inform the other nodes that the candidate node is the master node, and the heartbeat signal comprising the leader election period.

[0096] It can be understood that the cluster election apparatus provided by the above embodiments can be used to complete all or part of the above processing by different program modules according to the needs when implementing the corresponding cluster election method. In addition, the apparatus provided by the above embodiments and the corresponding method embodiments belong to the same concept, and the specific implementation process is described in the method embodiments, which will not be described here.

[0097] The present disclosure provides a computer readable storage medium storing executable instructions, wherein the executable instructions, when executed by a processor, trigger the processor to execute the cluster election method provided by the present disclosure.

[0098] In some embodiments, the computer readable storage medium can be a Ferroelectric RAM (FRAM), a Read-Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Programmable ROM (EPROM), an Electrically Erasable Programmable ROM (EEPROM), a flash memory, a magnetic surface memory, an optical disc, or a CD-ROM, etc. The computer readable storage medium can also be various devices including one or any combination of the above storage devices.

[0099] In some embodiments, the executable instructions can be in the form of programs, software, software modules, scripts or codes, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and can be deployed in any form, including being deployed as independent programs or being deployed as modules, models, subroutines or other units suitable for use in a computing environment.

[0100] As an example, the executable instructions can be deployed to execute on one computing device, or on multiple computing devices located in one place, or on multiple computing devices distributed in multiple places and interconnected through a communication network.

[0101] The computer program product includes computer programs / instructions, which, when executed by a processor, implement the cluster election method provided by the present disclosure.

[0102] Figure 5 A structural schematic diagram of an electronic device is provided in the embodiments of the present disclosure. As shown in the figure, the electronic device 50 includes a processor 501 and a memory 502 for storing computer programs capable of running on the processor; and the processor 501 is configured to run the computer programs to implement the cluster election method provided by the embodiments of the present disclosure. Figure 5

[0103] In actual application, the electronic device 50 can further include at least one network interface 503. The various components in the electronic device 50 are coupled together through a bus system 504. It can be understood that the bus system 504 is used to realize the connection and communication between the components. The bus system 504 includes not only a data bus, but also a power supply bus, a control bus and a status signal bus. However, in order to clearly illustrate the present disclosure, all the buses are marked as the bus system 504 in the figure. The number of the processor 501 can be at least one. The network interface 503 is used for wired or wireless communication between the electronic device 50 and other devices. Figure 5

[0104] The memory 502 in the embodiments 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 embodiments of the present disclosure can be applied to the processor 501 or implemented by the processor 501. The processor 501 can be an integrated circuit chip with a signal processing capability. In the implementation process, each step of the above method can be completed by the integrated logic circuit of hardware in the processor 501 or the instruction in the form of software. The processor 501 mentioned above can be a general-purpose processor, a digital signal processor (DSP, DiGital Signal Processor), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The processor 501 can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiments of the present disclosure. The general-purpose processor can be a microprocessor or any conventional processor, etc. In combination with the steps of the method disclosed in the embodiments of the present disclosure, the hardware decoding processor can be directly embodied to execute the above-mentioned steps, or the combination of hardware and software modules in the decoding processor can be executed. The software module can be located in a storage medium, which is located in the memory 502, and the processor 501 reads the information in the memory 502 and combines the hardware to complete the steps of the above-mentioned method.

[0106] ​​In some embodiments, the electronic device 50 can be implemented with one or more Application Specific Integrated Circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), general purpose processors, controllers, microcontrollers (MCUs), microprocessors (Microprocessors), or other electronic elements for executing the aforementioned methods.

[0107] It should be understood that the various forms of flow shown above can be re-ordered, added to, or have steps deleted, for example. The steps recited in the present disclosure can be performed in parallel, in series, or in a different order, as long as the desired results of the technology disclosed in the present disclosure are achieved, and are not limited herein.

[0108] In addition, the terms "first", "second", etc., are used only for the purpose of description, and should not be understood as indicating or implying relative importance or implying a specific number of the technical features indicated. Therefore, the features defined with "first", "second" can explicitly or implicitly include at least one of the features. In the description of the present disclosure, the meaning of "a plurality of" is two or more, unless otherwise specifically limited.

[0109] The above is only a specific implementation of the present disclosure, but the protection scope of the present disclosure is not limited thereto, and any person skilled in the art can easily think of changes or replacements within the technical scope disclosed in the present disclosure, which should be covered within the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be subject to 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 vote request to other nodes in the cluster besides itself; Receive the first vote results from the other nodes; The inertia coefficient of the candidate node is determined, and based on the combined effect of the inertia coefficient and the first voting result, it is determined whether the node should become the master node. The inertia coefficient is set based on the results of the previous election. If the candidate node is the master node in the previous election, its own inertia coefficient is set to a target value greater than 0. If the candidate node is the slave node in the previous election, the inertia coefficient is set to 0. The process of determining whether to become a master node based on the combined effect of the inertia coefficient and the first voting result includes: The sum of the inertia coefficient and the first voting result is determined as the second voting result; If the second voting result is greater than the target threshold, it determines itself to become the master node; the target threshold is determined based on the total number of nodes in the cluster.

2. The method according to claim 1, characterized in that, If the candidate node becomes the master node, the method further includes: Set its own inertia coefficient as the target value.

3. The method according to claim 1, characterized in that, If a primary node fails after becoming the primary node, the method further includes: Set its own inertia coefficient to 0.

4. The method according to claim 1, characterized in that, The process of determining whether to become a master node also includes: Detect whether a heartbeat signal is received from the master node. If the heartbeat signal is received, determine whether to become a slave node.

5. The method according to claim 4, characterized in that, If the candidate node becomes a slave node, the method further includes: Set its own inertia coefficient to 0.

6. The method according to claim 1, characterized in that, The voting request includes: the leadership election cycle determined by the candidate node; If the candidate node is determined to become the master node, the method further includes: Send a heartbeat signal to other nodes in the cluster besides itself. The heartbeat signal is used to inform other nodes that it is the master node. The heartbeat signal includes the leader election cycle.

7. 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: The sending module is used to initiate voting requests to other nodes in the cluster besides itself. The receiving module is used to receive the first voting results from the other nodes; The processing module is used to determine the inertia coefficient of the candidate node itself, and to determine whether it should become the master node based on the inertia coefficient and the first voting result. The inertia coefficient is set based on the results of the previous election. If the candidate node is the master node in the previous election, its own inertia coefficient is set to a target value greater than 0. If the candidate node is the slave node in the previous election, the inertia coefficient is set to 0. The processing module is used to determine the sum of the inertia coefficient and the first voting result as the second voting result; If the second voting result is greater than the target threshold, it determines itself to become the master node; the target threshold is determined based on the total number of nodes in the cluster.

8. 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 to enable the at least one processor to perform: The electronic device initiates a voting request to other nodes in the cluster besides itself; the cluster includes at least one candidate node and at least one voting node; the electronic device is applied to the candidate node; Receive the first vote results from the other nodes; The inertia coefficient of the candidate node is determined, and based on the combined effect of the inertia coefficient and the first voting result, it is determined whether the node should become the master node. The inertia coefficient is set based on the results of the previous election. If the candidate node is the master node in the previous election, its own inertia coefficient is set to a target value greater than 0. If the candidate node is the slave node in the previous election, the inertia coefficient is set to 0. The process of determining whether to become a master node based on the combined effect of the inertia coefficient and the first voting result includes: The sum of the inertia coefficient and the first voting result is determined as the second voting result; If the second voting result is greater than the target threshold, it determines itself to become the master node; the target threshold is determined based on the total number of nodes in the cluster.

9. A non-transitory computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to execute: The node initiates a voting request to other nodes in the cluster besides itself; the cluster includes at least one candidate node and at least one voting node; the storage medium is applied to the candidate node. Receive the first vote results from the other nodes; The inertia coefficient of the candidate node is determined, and based on the combined effect of the inertia coefficient and the first voting result, it is determined whether the node should become the master node. The inertia coefficient is set based on the results of the previous election. If the candidate node is the master node in the previous election, its own inertia coefficient is set to a target value greater than 0. If the candidate node is the slave node in the previous election, the inertia coefficient is set to 0. The process of determining whether to become a master node based on the combined effect of the inertia coefficient and the first voting result includes: The sum of the inertia coefficient and the first voting result is determined as the second voting result; If the second voting result is greater than the target threshold, it determines itself to become the master node; the target threshold is determined based on the total number of nodes in the cluster.

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