An optimization method for leader selection strategy in distributed systems
By judging the state of network links between nodes in distributed systems and optimizing the master selection strategy, the problem of insufficient fault tolerance of the master selection process in the existing technology for transient and crash failures is solved, and the stability and robustness of the system are improved.
Patent Information
- Application Number
- CN202310541217.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-15
- Publication Date
- 2025-08-29
- Estimated Expiration
- 2043-05-15
AI Technical Summary
In the process of selecting mains in distributed systems, it is difficult to effectively deal with transient and crash failures, resulting in insufficient system stability and robustness.
By judging the network link status between nodes, different master selection strategies are adopted, including the use of heartbeat messages, counters and timers, to ensure that the master selection process is optimized under different system states.
It improves the fault tolerance of distributed systems for transient and crash faults, and enhances the stability and robustness of the system.
Smart Images

Figure CN116614511B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of distributed computing technology, and in particular to a method for optimizing a master selection strategy of a distributed system. Background Art
[0002] Leader election is the process of selecting a single node as a "leader" or "master" in a distributed system to coordinate the behavior of all nodes. This node is responsible for coordinating and managing the entire system. The goal of leader election is to ensure the system can operate correctly and process various requests while avoiding contention and conflicts between nodes. During leader election, various factors, such as node reliability, network latency, and load balancing, must be considered to ensure the selected master node has good performance and reliability. Leader election is a crucial step in distributed systems and is essential for ensuring system correctness and performance.
[0003] The proper functioning of the master election process in a distributed system depends on the state of each node and the state of inter-node communication—that is, whether each node is functioning properly and whether inter-node network communication is functioning properly. For nodes, two abnormal states are generally considered: transient failures and catastrophic failures. These two abnormal states correspond to the two dimensions of system reliability: stability and robustness. The former describes the system's ability to recover from transient failures, while the latter describes the system's ability to maintain a high degree of functionality even after experiencing a catastrophic failure. Stabilization techniques typically employed by system nodes can tolerate transient failures but are generally not robust, meaning they offer poor fault tolerance for catastrophic failures. Robust algorithms are generally not designed to address transient failures.
[0004] Leader election in distributed systems has been extensively studied in the areas of stabilization and robustness. In some systems, leader election is also considered a fault detector; failure to elect a leader indicates a system failure. Stabilization algorithms ensure that, regardless of the system's initial configuration, the system reaches a desired stable configuration within a bounded time, thus preventing deviations from its intended operation. This ensures that the system always converges to the correct state. However, stabilization algorithms cannot guarantee proper operation in extreme situations, such as when some nodes in the system fail to function properly or when there are network issues between nodes. Summary of the Invention
[0005] To address the above technical issues, the present invention provides a method for optimizing a distributed system leader election strategy. This method optimizes the distributed system leader election strategy in terms of robustness and stability. By assessing the status of inter-node network links and adopting different leader selection methods, the leader election strategy improves the distributed system's fault tolerance to transient and catastrophic failures.
[0006] The technical solution of the present invention is:
[0007] A method for optimizing a distributed system master election strategy includes the following steps:
[0008] 1) Obtain the node and link status of the distributed system;
[0009] 2) According to the network link status, determine whether the system type belongs to s0, s1, s2, or s3;
[0010] 3) Execute the corresponding master election strategy based on the judgment results.
[0011] Furthermore, the distributed system model is as follows:
[0012] In a distributed system, nodes can communicate with each other. Each node exchanges data with other nodes through unidirectional links. If the number of nodes in the system is n, then any node in the master election process needs to establish links with n-1 other nodes. The master election strategy only uses n-1 unidirectional links, which is considered the optimal solution.
[0013] Furthermore, the nodes and network links are as follows:
[0014] Node: In a round of master election, (1) the node sends a message to a certain node or receives a message from a certain node, or neither receives nor sends a message, and then (2) changes its own state. In a round of master election, there may be a delay between (1) and (2). In this model, the time difference of each process is ignored, and it is assumed that a round of master election occurs instantaneously. If the node is in a crashed state, it is considered to have exited the master election round. A normally working node can complete a round of master election. In order to prevent the number of concurrent requests at a certain time from being too large (for example, all nodes send messages to other nodes at a certain time to request that they be elected as the master node), it is necessary to set the execution time of the master election process of each node to be differentiated, that is, set a different waiting time t before each node's respective master election process, so that the range of this waiting time is [t min , t max ].
[0015] Link: Nodes send and receive messages to other nodes through links. Set a constant T. If a message is sent from node p to node q at time t, and node q receives this message at time t+T, the link is considered to be in a normal state.
[0016] Furthermore, distributed systems can be divided into the following categories based on whether their links are normal or not:
[0017] System s0: All links are not in normal state.
[0018] System s1: There is at least one node whose link for sending outward messages is in a normal state.
[0019] System s2: There is at least one node whose link for sending and receiving messages is in a normal state.
[0020] System sx: All links are up.
[0021] Going further,
[0022] For distributed systems, the following parameters are defined:
[0023] In a system s, in a certain round of master election process, the master node recommended by node p is L p , the master node recommended by p can be itself. Generally, after the master election is successfully completed, the master node L of all nodes N N It should be the same node, and the final master node is identified as L fin .
[0024] Going further,
[0025] For system s3, the following distributed system master election strategy is adopted:
[0026] Any node p periodically sends heartbeat messages to other nodes, unless L p =p;
[0027] For any L p If p≠p, p will elect the node q from which it receives the most heartbeat messages as the master node;
[0028] When L p = p When the p node receives the heartbeat message of q, if q<p, L p =q, so that there is only one L left. p =p;
[0029] For any L p ≠ x After each round of master iteration, a counter that increases with each round is set to detect whether there is L p =q, when the count value is greater than a set value, it is considered that there is no L p =q's q node;
[0030] The timer increases after each round of leader election. By giving a time range for each round of leader election, the number of leader election rounds that p will take within a given time can be determined.
[0031] For system s2, the following distributed system master election strategy is adopted:
[0032] Each node p periodically sends a message of (1, p) to all other nodes;
[0033] When p receives a message (k, q) from q, if k < n-1, p sends a message (k+1, q) to all nodes except the message source q. This ensures that p can periodically receive messages sent by other normal nodes. In this way, each normal node can output a list including all normal nodes, and the main process can be selected within the range of this list.
[0034] For system s1, the following distributed system master election strategy is adopted:
[0035] Each node p sets a counter to record the number of times the node crashes. In addition to periodically sending heartbeat messages, p also sends its crash count.
[0036] Each node records a list of itself and the nodes from which it has recently received heartbeat messages, including the number of crashes received for each node;
[0037] Any node p periodically selects the node with the least number of crashes from the recorded list as the master node;
[0038] After the master election process ends, if the master node of node p changes, p will send a message to the previous master node to increase the crash count of this node by 1.
[0039] For system s0, the following distributed system master election strategy is adopted:
[0040] In this system, if all links between nodes are disconnected, the system is paralyzed and the leader election process cannot be executed. At this time, an error alarm will be issued, and the distributed system leader election strategy steps mentioned above will be executed after the system recovers.
[0041] The beneficial effects of the present invention are
[0042] The distributed system leader selection strategy is optimized for robustness and stability. By evaluating the state of network connections between nodes and adopting different leader selection methods, the distributed system improves its fault tolerance to transient and catastrophic failures. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 It is a schematic diagram of the workflow of the present invention;
[0044] Figure 2 This is a schematic diagram of how each node operates in the master selection process. DETAILED DESCRIPTION
[0045] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0046] The present invention discloses a method for optimizing a distributed system leader selection strategy, which optimizes the distributed system leader selection strategy in terms of robustness and stability. The leader selection strategy determines the status of network links between nodes and adopts different leader selection methods, thereby improving the distributed system's fault tolerance to transient and catastrophic failures. The method includes the following steps:
[0047] 1) Obtain the node and link status of the distributed system;
[0048] 2) According to the network link status, determine which of the four types of systems the system belongs to;
[0049] 3) Execute the corresponding master election strategy based on the judgment results.
[0050] Distributed systems can be divided into the following categories based on whether their links are normal or not:
[0051] System s0: All links are not in normal state.
[0052] System s1: There is at least one node whose link for sending outward messages is in a normal state.
[0053] System s2: There is at least one node whose link for sending and receiving messages is in a normal state.
[0054] System s3: All links are in normal state. The following parameters are defined for the distributed system:
[0055] In a system s, in a certain round of master election process, the master node recommended by node p is L p , the master node recommended by p can be itself. Generally, after the master election is successfully completed, the master node L of all nodes N N It should be the same node, and the final master node is identified as L fin .
[0056] For system s3, the following distributed system master election strategy is adopted:
[0057] Any node p periodically sends heartbeat messages to other nodes, unless L p =p;
[0058] For any L p If p≠p, p will elect the node q from which it receives the most heartbeat messages as the master node;
[0059] When L p = p When the p node receives the heartbeat message of q, if q<p, L p =q, so that there is only one L left. p =p;
[0060] For any L p ≠p, after each round of master selection, a counter is set to increase with the round to detect whether there is L p =q, when the count value is greater than a set value, it is considered that there is no L p =q's q node;
[0061] The timer increases after each round of leader election. By giving a time range for each round of leader election, the number of leader election rounds that p will take within a given time can be determined. For example, p must go through at least T / t in T time. min Rotating master.
[0062] For system s2, the following distributed system master election strategy is adopted:
[0063] Each node p periodically sends a message of (1, p) to all other nodes;
[0064] When p receives a message (k, q) from q, if k < n-1, p sends a message (k+1, q) to all nodes except the message source q. This ensures that p can periodically receive messages sent by other normal nodes. In this way, each normal node can output a list including all normal nodes, and the main process can be selected within the range of this list.
[0065] For system s1, the following distributed system master election strategy is adopted:
[0066] Each node p sets a counter to record the number of times the node crashes. In addition to periodically sending heartbeat messages, p also sends its crash count.
[0067] Each node records a list of itself and the nodes from which it has recently received heartbeat messages, including the number of crashes received for each node;
[0068] Any node p periodically selects the node with the least number of crashes from the recorded list as the master node;
[0069] After the master election process ends, if the master node of node p changes, p will send a message to the previous master node to increase the crash count of this node by 1.
[0070] For system s0, the following distributed system master election strategy is adopted:
[0071] In this system, if all links between nodes are disconnected, the system is paralyzed and the leader election process cannot be executed. At this time, an error alarm will be issued, and the distributed system leader election strategy steps mentioned above will be executed after the system recovers.
[0072] The above description is only a preferred embodiment of the present invention and is only used to illustrate the technical solution of the present invention, and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention are included in the scope of protection of the present invention.
Claims
1. A method for optimizing a distributed system master selection strategy, characterized in that: It includes the following steps: 1) Obtain the node and link status of the distributed system; 2) Determine the type of the system according to the network link status; 3) Execute the corresponding master election strategy based on the judgment result; For a distributed system, according to whether the links are in a normal state, it is divided into the following categories: System s0: All links are not in a normal state; System s1: There is at least one node whose outbound message link is in a normal state; System s2: There is at least one node whose message sending and receiving link is in a normal state; System s3: All links are in a normal state; For system s3, adopt the following distributed system master election strategy: Any node p periodically sends heartbeat messages to other nodes, unless L p =p; For any L p If p≠p, p will elect the node q from which it receives the most heartbeat messages as the master node; When L p = When the p node of p receives the heartbeat message of q, if q <p,L p =q, so that there is only one L left. p =p; For any L p ≠p, after each round of master selection, a counter is set to increase with the round to detect whether there is L p =q, when the count value is greater than a set value, it is considered that there is no L p =q's q node; The timer increases after each round of master election. By specifying the time-consuming range for each round of master election, the number of master election rounds of p within a given time can be determined; For system s2, adopt the following distributed system master election strategy: Each node p periodically sends a message (1, p) to all other nodes; When p receives a message (k, q) from q, if k < n - 1, except for the message source q, p sends a message (k + 1, q) to all other nodes; Each normal node can output a list including all normal nodes, and the master election process can be carried out within the scope of this list; For system s1, adopt the following distributed system master election strategy: Each node p sets a counter to record the number of times the node crashes. In addition to periodically sending heartbeat messages, p also attaches and sends its crash count; Each node records a list containing itself and the node from which it recently received a heartbeat message, and records the crash counts of each received node; Any node p periodically selects the node with the fewest crash counts in the recorded list as the master node; After the master election process ends, if the master node of node p changes, p will send a message to the previous master node to increase the crash count of this node by 1; For system s0, adopt the following distributed system master election strategy: In this system, all links between nodes are disconnected, the system is in a paralyzed state, and the master election process cannot be executed; At this time, an error alarm will be sent, and after the system is restored, the above-mentioned distributed system master election strategy steps will be executed. Node: In a round of the master election process, (1) the node sends a message to the node or receives a message from the node or neither receives nor sends a message, and then (2) changes its own state; if the node is in a crashed state, it is considered to have exited the master election round. A normally working node can complete a round of the master election process; the execution time of the master election process of each node is set to be different, that is, a different waiting time t is set before each node's master election process, so that the range of this waiting time is [t min ,t max ]; In a system s, in a round of master election process, the master node recommended by node p is L p , the master node recommended by p is itself; after the master election is successfully completed, the master node L of all nodes N N It should be the same node, and the final master node is identified as L fin .
Citation Information
Patent Citations
Election processing method and device, electronic equipment and computer readable storage medium
CN116051018A