A method, device, equipment and storage medium for selecting a master node in a multi-node network
By broadcasting node election information and receiving other node information in the distributed system, determining priorities and converting node status, and setting up backup slave nodes, the problems of unstable performance and complicated failover during the master node selection process are solved, and multiple implementations are realized. Efficient performance and robustness of the node network.
Patent Information
- Application Number
- CN202410593703.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-14
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2044-05-14
AI Technical Summary
In the process of selecting the master node in the existing distributed system, due to the untimely update of performance parameters, the performance of the selected master node is unstable, and the failover process is complex and time-consuming, affecting the functions and performance of the entire system.
By broadcasting node election information during initialization, receiving election information from other nodes, determining the election priority, and converting to the master node at the highest priority, sending heartbeat request messages to convert other nodes into slave nodes, and setting up backup slave nodes. for seamless failover.
It reduces the complexity of master node election and data processing volume, improves system robustness, reduces the number of executions of the master node election process, and improves the performance of multi-node networks.
Smart Images

Figure CN118200123B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Internet technology, and in particular to a method, device, equipment and storage medium for selecting a master node in a multi-node network. Background Art
[0002] With the rapid development of Internet technology, the application scope of distributed systems is becoming wider and wider. A distributed system is a cluster system composed of multiple autonomous computers as nodes through a communication network. For example, in the power field, the intelligent fusion terminal is an intelligent collection and control terminal installed in the low-voltage area of the power grid, which can support business functions such as fault prediction, fault repair, load forecasting and new energy access control.
[0003] With the rapid development of distributed photovoltaic and new energy charging piles, the load differences between stations and the imbalance of new energy consumption have become increasingly prominent. In order to achieve collaborative governance between stations with intelligent fusion terminals as nodes, different intelligent fusion terminals are often used to form multi-node networks through wireless communication networks to break the limitations of independent operation of traditional stations and realize information sharing and collaborative work between stations. When building a multi-node network, it is often necessary to select a node as the master node. In a distributed system composed of intelligent fusion terminals, the selection of the master node is an important process. The determined master node can be used to coordinate the entire distributed system application, maintain the stability and consistency of the system operation, and avoid multiple nodes competing for resources or task conflicts at the same time.
[0004] In existing distributed systems, each node often sends its own performance parameters to other nodes, and the other nodes record the performance parameters. When faced with the need to determine the master node in the future, the node with better performance parameters is selected as the master node based on the stored performance parameters. After the master node fails, the master node is re-selected from other nodes. However, when the master node is selected in the above manner, it is difficult to guarantee the performance of the selected master node because the recorded performance parameters cannot be updated in time. At the same time, the master node will be directly re-selected after the master node fails. The re-selection process often requires judging other nodes in turn, which makes the re-election take more time and data computing. In addition, during the transfer of the master node, the performance and storage content of the transferred node are unpredictable, which will affect the function and performance of the entire distributed system. Summary of the invention
[0005] The present invention provides a method, device, equipment and storage medium for selecting a master node in a multi-node network, which reduces the complexity of master node election and the amount of data processing, realizes seamless replacement of master node functions in the event of a master node failure, improves system robustness, reduces the number of executions of the master node election process, and improves the performance of the multi-node network.
[0006] In a first aspect, an embodiment of the present invention provides a method for selecting a master node in a multi-node network, which is applied to any node in the multi-node network. The method includes:
[0007] During initialization, the first node election information of the current node is broadcasted once, and the second node election information of other nodes in the multi-node network is received during the election duration;
[0008] Determine the election priority of the current node in the multi-node network according to the first node election information and each second node election information;
[0009] When the election priority is the highest priority, the current node is converted into a master node in the multi-node network, and a heartbeat request message is sent to each other node to convert each other node into a slave node in the multi-node network;
[0010] Receive the heartbeat response message fed back by each slave node, and determine the target slave node in each slave node according to each heartbeat response message;
[0011] Generate backup node switching control information, and send the backup node switching control information to the target slave node, so that the target slave node is converted into a backup slave node corresponding to the master node, and the backup slave node is switched to the master node when receiving the master node replacement control instruction or the master node fails;
[0012] The first node election information includes at least the current node device identification number and the current node remaining resource value of the current node; the second node election information includes at least the node device identification number and the node remaining resource value of the corresponding node.
[0013] In a second aspect, an embodiment of the present invention further provides a multi-node network master node selection device, which is applied to any node in the multi-node network, comprising:
[0014] An election information processing module, used to broadcast the first node election information of the current node once at the time of initialization, and receive the second node election information of other nodes in the multi-node network during the election duration;
[0015] A priority determination module, used to determine the election priority of the current node in the multi-node network according to the first node election information and the second node election information;
[0016] A node conversion module, used to convert the current node into a master node in a multi-node network when the election priority is the highest priority, and send a heartbeat request message to each other node to convert each other node into a slave node in the multi-node network;
[0017] The target node determination module is used to receive the heartbeat response messages fed back by each slave node, and determine the target slave node in each slave node according to each heartbeat response message;
[0018] A node switching module is used to generate backup node switching control information and send the backup node switching control information to a target slave node, so that the target slave node is converted into a backup slave node corresponding to the master node, and the backup slave node is switched to the master node when receiving a master node replacement control instruction or the master node fails;
[0019] The first node election information includes at least the current node device identification number and the current node remaining resource value of the current node; the second node election information includes at least the node device identification number and the node remaining resource value of the corresponding node.
[0020] In a third aspect, an embodiment of the present invention further provides a multi-node network master node selection device, including:
[0021] at least one processor; and
[0022] a memory communicatively connected to at least one processor; wherein,
[0023] The memory stores a computer program that can be executed by at least one processor, and the computer program is executed by at least one processor so that the at least one processor can execute the multi-node network master node selection method of any embodiment of the present invention.
[0024] In a fourth aspect, an embodiment of the present invention further provides a storage medium comprising computer executable instructions, which, when executed by a computer processor, are used to execute the method for selecting a master node in a multi-node network according to any embodiment of the present invention.
[0025] The embodiment of the present invention provides a method, device, equipment and storage medium for selecting a master node in a multi-node network, which is applied to any node in the multi-node network, broadcasts the first node election information of the current node once during initialization, and receives the second node election information of other nodes in the multi-node network during the election duration; determines the election priority of the current node in the multi-node network according to the first node election information and each second node election information; converts the current node into a master node in the multi-node network when the election priority is the highest priority, and sends a heartbeat request message to each other node to convert each other node into a master node in the multi-node network. The slave nodes in the master node; receive the heartbeat response message fed back by each slave node, and determine the target slave node in each slave node according to each heartbeat response message; generate backup node cut-in control information, and send the backup node cut-in control information to the target slave node, so that the target slave node is converted into a backup slave node corresponding to the master node, and the backup slave node is switched to the master node when receiving the master node replacement control instruction or the master node fails; wherein the first node election information at least includes the current node device identification number and the current node remaining resource value of the current node; the second node election information at least includes the node device identification number and the node remaining resource value of the corresponding node. By adopting the above technical solution, when selecting the master node for the initialized multi-node network, the node election information containing the current node device identification number and the current node remaining resource value is broadcasted once by all the nodes therein, so that each node in the multi-node network that receives the node election information can complete its own priority determination in the multi-node network according to each node election information, and then complete the master node selection according to the determined election priority. After the master node is selected, the heartbeat request message sent by the master node ensures that all nodes in the multi-node network that can receive the master node heartbeat request message and can communicate directly with the master node are converted into slave nodes, and the integrity of the master node selection among the master node and all the slave nodes that can communicate directly with it is guaranteed through one communication. At the same time, the master node sets a backup slave node that can seamlessly replace the master node function in each slave node according to the heartbeat response message fed back by each slave node corresponding to it, so that the master node can be seamlessly replaced by the backup slave node as the new master node in case of failure, without the need to directly re-select the master node, thereby improving the system robustness of the multi-node network, reducing the number of executions of the master node election process, and improving the performance of the multi-node network.
[0026] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0028] Figure 1 A flowchart of a method for selecting a master node in a multi-node network provided in Embodiment 1 of the present invention;
[0029] Figure 2 A flowchart of a method for selecting a master node in a multi-node network provided in Embodiment 2 of the present invention;
[0030] Figure 3 A schematic diagram of the structure of a multi-node network master node selection device provided in Embodiment 3 of the present invention;
[0031] Figure 4 A structural diagram of a multi-node network master node selection device provided in Embodiment 4 of the present invention. DETAILED DESCRIPTION
[0032] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme 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 only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0033] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0034] Embodiment 1
[0035] Figure 1A flowchart of a method for selecting a master node in a multi-node network provided in the first embodiment of the present invention. The embodiment of the present invention can be applied to the situation where, after the multi-node network is constructed, the master node is selected for each node contained therein to coordinate the entire multi-node network application and maintain its operational stability and consistency, such as the situation where a distributed system is formed by a plurality of intelligent fusion terminals in an electric power network after multi-node networking through a wireless communication network, and an intelligent fusion terminal that can be used as a master node is selected from each intelligent fusion terminal. The method can be executed by a multi-node network master node selection device, and the multi-node network master node selection device can be configured in a multi-node network master node selection device. Optionally, the multi-node network master node selection device can be a notebook, an intelligent fusion terminal, a cluster, a desktop computer, a smart tablet, etc., and the embodiment of the present invention does not limit this.
[0036] like Figure 1 As shown, a method for selecting a master node in a multi-node network provided by an embodiment of the present invention can be applied to any node in a multi-node network. For example, when the multi-node network is composed of multiple intelligent fusion terminals, the method can be applied to any intelligent fusion terminal, and specifically includes the following steps:
[0037] S101. Broadcast the first node election information of the current node once during initialization, and receive the second node election information of other nodes in the multi-node network within the election duration.
[0038] The first node election information includes at least the current node device identification number and the current node remaining resource value of the current node; the second node election information includes at least the node device identification number and the node remaining resource value of the corresponding node.
[0039] In this embodiment, the first node election information can be specifically understood as a set of necessary information for participating in the master node election sent out by the nodes participating in the master node election in the multi-node network. The second node election information can be specifically understood as a set of necessary information for participating in the master node election received from other nodes by the nodes participating in the master node election in the multi-node network. It can be understood that the node election information sent by the node itself in the multi-node network is the first node election information, the node election information received by the node is the second node election information, and the second node election information received by a certain node is the first node election information of the node itself corresponding to the second node election information. The election duration can be specifically understood as a time determination method for determining the duration of the multi-node network master node election, which is pre-set according to actual conditions. For example, the election duration can be a continuous time length defined according to the network delay state. If the current node does not receive the second node election information again for the continuous time length after receiving the second node election information for the last time, the election duration is considered to be over. Optionally, the continuous time length defined according to the network delay state can be adjusted in real time according to actual conditions, or can be periodically updated based on the network delay state in the historical time period, and the embodiment of the present invention does not limit this.
[0040] In this embodiment, the current node can be specifically understood as the node that sends the first node election information in the multi-node network. The current node device identification number can be specifically understood as an identification number used to indicate the identity information of the device corresponding to the current node. For example, it can be the equipment serial number (ESN) of the device corresponding to the current node. The current node remaining resource value can be specifically understood as the remaining status of resources related to data processing capabilities such as the central processing unit (CPU) and memory of the device corresponding to the current node. Correspondingly, the power-saving device identification number and node remaining resource value of the corresponding node contained in the second node election information can be understood as the current node device identification number and the current node remaining resource value in the first node election information of the corresponding node.
[0041] Specifically, for any node used to constitute a multi-node network, when the multi-node network is initialized such as power-on, the node is used as the current node to broadcast its own first node election information to other nodes used to construct the multi-node network, and at the same time continues to receive second node election information sent by other nodes in the multi-node network until it is determined according to the method for determining the election duration that the reception of the second node election information of all nodes in the multi-node network has been completed while satisfying the network delay status.
[0042] S102: Determine the election priority of the current node in the multi-node network according to the first node election information and each second node election information.
[0043] In this embodiment, the election priority can be specifically understood as the priority of the current node to be used as a master node in a multi-node network.
[0044] Specifically, since the master node in a multi-node network needs to be responsible for coordinating and managing other slave nodes, ensuring the stability and consistency of the operation of the distributed system formed by the multi-node network, and avoiding conflicts caused by multiple nodes competing for resources or tasks at the same time, the selected master node needs to perform more operations than the slave nodes. Therefore, after the current node obtains multiple second node election information, it can judge whether its remaining computing resources can meet the requirements of being a master node in a multi-node network based on the second node election information and its own first node election information. At the same time, when the current node and other nodes meet the requirements of being a master node in a multi-node network, the master node is determined according to the node device identification numbers of different nodes, and finally the election priority of the current node among all nodes in the multi-node network is obtained.
[0045] In an embodiment of the present invention, each node in a multi-node network determines its own election priority through the node remaining resource value and the node device identification number, thereby ensuring the consistency of the highest priority node determined during a master node election, so that the selection of the master node can be completed by broadcasting the node election information only once, thereby improving the efficiency of master node selection and reducing the election complexity and data processing volume.
[0046] S103. When the election priority is the highest priority, convert the current node into a master node in the multi-node network, and send a heartbeat request message to each other node to convert each other node into a slave node in the multi-node network.
[0047] In this embodiment, the heartbeat request message can be specifically understood as a message sent by the master node to obtain the operating status of each node in its network and maintain the connection.
[0048] Specifically, when the current node determines that its own election priority is the highest priority, it can be considered that the current node is the most suitable node to become the master node in the multi-node network. At this time, the node state of the current node is converted to the master node. After the conversion is completed, a heartbeat request message containing at least the message type and the current node device identification number of the current node is generated, and the heartbeat request message is broadcast in the multi-node network, so that other nodes that receive the heartbeat request message can clearly know that the master node has been generated, and then other nodes that receive the heartbeat request message can convert themselves into slave nodes on the basis of clearly knowing that there is an existing master node.
[0049] It is understandable that, in theory, each node in a multi-node network can complete the determination of its own election priority based on its own first node election information and the received second node election information, and complete the conversion of its own node state in the multi-node network based on the determined election priority. However, due to the different network delay states and their own working states of each node, the conversion time of each node in completing its own identity state is different. The node converted to the master node sends a heartbeat request message to the outside when the conversion is completed, so that the node that has not completed its own node state transformation due to network delay and other reasons can be directly converted to a slave node, reducing the amount of data and processing time for the slave node to process data itself. At the same time, since other nodes in the multi-node network may have anomalies in the priority determination process, the sending of the heartbeat request message by the determined master node plays a role of verification and supervision in this case, so that the node where the abnormal calculation occurs can be switched to a slave node in time, which improves the timeliness and accuracy of the determination of the master and slave nodes in the multi-node network, and thus improves the robustness of the multi-node network.
[0050] S104, receiving the heartbeat response messages fed back by each slave node, and determining the target slave node among the slave nodes according to each heartbeat response message.
[0051] In this embodiment, the heartbeat reply message can be specifically understood as a message generated by the node receiving the heartbeat request message in response to the heartbeat request message, which is used to feed back its own operating status to the master node and maintain connection with the master node. Optionally, the heartbeat reply message should at least include information such as the message type, the node device identification number of the corresponding node, the node remaining resource value of the corresponding node, and the node's own operating status, which is not limited by the embodiment of the present invention. The target slave node can be specifically understood as a slave node determined by the master node based on the working status of each slave node, which can be used as a slave node of the master node backup slave node.
[0052] Specifically, the master node receives the heartbeat reply message fed back by each slave node in response to the heartbeat request message, and each heartbeat reply message contains the node remaining resource value and the node's own operating status of the corresponding slave node. Therefore, the master node can determine the slave node with the richest resource reserves and the ability to bear the largest amount of computing power among the slave nodes as the target slave node based on the node remaining resource value and the node's own operating status.
[0053] In the embodiment of the present invention, the master node directly determines the remaining resource status of each slave node based on the heartbeat response message fed back by each slave node, and then selects the target slave node that is most suitable as the backup of the master node based on the remaining resource status. By setting the target slave node, a secondary backup guarantee for the selection of the master node is realized. At the same time, the master node completes the determination of the slave node based on the heartbeat response message that must be received, which reduces the amount of data transmission required for selecting the target slave node in the multi-node network, ensures the accuracy and timeliness of the determination of the target slave node, and further improves the stability of the entire multi-node network.
[0054] S105. Generate backup node switching control information, and send the backup node switching control information to the target slave node, so that the target slave node is converted into a backup slave node corresponding to the master node, and the backup slave node is switched to the master node when receiving the master node replacement control instruction or the master node fails.
[0055] In this embodiment, the backup node switching control information can be specifically understood as control information sent by the master node to the target slave node to control its node state to be converted to a backup slave node and to start functions related to the backup slave node. Exemplarily, the backup node switching control information includes at least a message type, a node device identification number of the master node, and a control instruction, which is not limited in the embodiment of the present invention. The master node replacement control instruction can be specifically understood as a control instruction for instructing the backup slave node to replace the master node and become the new master node.
[0056] Specifically, after the master node identifies the target slave node, it will generate backup node entry control information including the message type, the node device identification number of the master node, and control instructions for controlling the target slave node to switch to the backup slave node, and send the backup node entry control information to the target slave node, so that the target slave node can convert the node state to the backup slave node corresponding to the master node according to the received backup node entry control information, and start the corresponding function of the backup slave node in the network corresponding to the master node, so that the backup slave node can maintain basically consistent content with the master node, and then seamlessly switch to the master node when the backup slave node receives the master node replacement control instruction, or seamlessly switch the backup slave node to the master node when the master node fails.
[0057] The technical solution of the embodiment of the present invention is to broadcast the first node election information of the current node once during initialization, and receive the second node election information of other nodes in the multi-node network within the election duration; determine the election priority of the current node in the multi-node network according to the first node election information and each second node election information; convert the current node into a master node in the multi-node network when the election priority is the highest priority, and send a heartbeat request message to each other node to convert each other node into a slave node in the multi-node network; receive the heartbeat response message fed back by each slave node, and determine the target slave node in each slave node according to each heartbeat response message; generate backup node cut-in control information, and send the backup node cut-in control information to the target slave node, so that the target slave node is converted into a backup slave node corresponding to the master node, and the backup slave node switches to the master node when receiving the master node replacement control instruction or the master node fails; wherein the first node election information at least includes the current node device identification number and the current node remaining resource value of the current node; the second node election information at least includes the node device identification number and the node remaining resource value of the corresponding node. By adopting the above technical solution, when selecting the master node for the initialized multi-node network, all nodes in the network broadcast the node election information containing the current node device identification number and the current node remaining resource value, so that each node in the multi-node network that receives the node election information can complete its own priority determination in the multi-node network based on the election information of each node, and then complete the master node selection based on the determined election priority. After the master node selection is completed, the heartbeat request message sent by the master node ensures that all nodes in the multi-node network that can receive the master node heartbeat request message and can communicate directly with the master node are converted into slave nodes, and the integrity of the master node selection among the nodes in the master node and all the slave nodes that can communicate directly with it is guaranteed through one communication. At the same time, the master node sets a backup slave node in each slave node that can seamlessly take over the function of the master node based on the heartbeat response messages fed back by the corresponding slave nodes. As a result, when the master node fails, the backup slave node can seamlessly take over as the new master node without the need to directly re-select the master node. This improves the system robustness of the multi-node network, reduces the number of executions of the master node election process, and improves the performance of the multi-node network.
[0058] Embodiment 2
[0059] Figure 2A flowchart of a method for selecting a master node in a multi-node network is provided for the second embodiment of the present invention. The technical solution of the embodiment of the present invention is further optimized on the basis of the above-mentioned optional technical solutions, and determines whether the election priority of the current node is the highest priority according to the node remaining resource values and node device identification numbers of different nodes in turn. At the same time, it is clarified that after the current node is determined to be a slave node, if a heartbeat request message is not received for a long time, it will be re-elected to ensure that the master node of the multi-node network always exists. After determining that the current node is the master node, the master node determines the target slave node that can be used as a backup slave node from each slave node based on the slave node remaining resource value contained in each received heartbeat response message. At the same time, the master node can send multicast network joining control information to all slave nodes that feed back heartbeat response messages to it, so that all slave nodes that can communicate with the master node can join the same multicast network with the master node, thereby enabling the monitoring function of the backup slave node for each slave node in the multicast network and the data consistency verification function of the backup slave node for the master node, thereby realizing hot backup of the master node by the backup slave node and reducing the amount of data that needs to be communicated between the backup slave node and the master node, so that the backup slave node that is consistent with the content of the master node can seamlessly switch to the master node when receiving the master node replacement control instruction or the master node fails, without the need to directly re-select the master node, or the situation where the newly selected master node cannot directly adapt to the slave node task, thereby improving the system robustness of the multi-node network, reducing the number of executions of the master node election process, and improving the performance of the multi-node network.
[0060] like Figure 2 As shown, a method for selecting a master node in a multi-node network provided by Embodiment 2 of the present invention specifically includes the following steps:
[0061] S201. Broadcast the first node election information of the current node once during initialization, and receive the second node election information of other nodes in the multi-node network within the election duration.
[0062] The first node election information includes at least the current node device identification number and the current node remaining resource value of the current node; the second node election information includes at least the node device identification number and the node remaining resource value of the corresponding node.
[0063] S202, determine whether the remaining resource value of the current node is less than the remaining resource value of any node, if so, execute S205; if not, execute S203.
[0064] Specifically, by judging whether the remaining resource value of the current node is less than the remaining resource value of any other node, it is determined whether the current node is the node with the most remaining resources in the multi-node network. If so, it can be considered that there is a node in the current multi-node network whose remaining resource value is greater than that of the current node, and the current node cannot be the master node in the multi-node network, and S205 is executed at this time; if not, it can be considered that the current node has the possibility of becoming the master node in the multi-node network, and S203 is executed at this time.
[0065] S203, determine whether the remaining resource value of the current node is greater than the remaining resource value of each node, if so, execute S206; if not, execute S204.
[0066] Specifically, by determining whether the remaining resource value of the current node is greater than the remaining resource value of each other node, if so, it can be considered that there is only the current node in the current multi-node network, which is the node with the most remaining resources, and S206 is executed at this time; if not, it can be considered that although the current node is the node with the most remaining resources in the current multi-node network, there are also nodes in other nodes with the same remaining resource amount as the current node, and S204 is executed at this time.
[0067] S204. Determine the node remaining resource value equal to the current node remaining resource value as the remaining resource value of the node to be selected. If the current node device identification number is greater than the node device identification number corresponding to each remaining resource value of the node to be selected, execute S206; otherwise, execute S205.
[0068] Specifically, the node remaining resource value that is equal to the current node remaining resource value of the current node in the multi-node network is determined as the remaining resource value of the node to be selected, which means that the node corresponding to the remaining resource value of the node to be selected and the current node may both become the main node in the multi-node network. At this time, the current node device identification number and the node device identification numbers corresponding to the remaining resource value of the node to be selected can be compared in size, and the node corresponding to the node remaining resource value with the largest node device identification number is considered to be the node that can be used as the main node in the multi-node network, that is, when the current node device identification number is greater than the node device identification numbers corresponding to the remaining resource values of each node to be selected, execute S206; otherwise, execute S205.
[0069] S205. Determine the election priority of the current node as a non-highest priority, and execute S211.
[0070] Specifically, when the election priority of the current node is not the highest priority, it can be considered that the current node cannot serve as the master node in the multi-node network, that is, it can be considered that the current node should exist as a slave node in the multi-node network, and S211 is executed at this time.
[0071] S206: Determine the election priority of the current node as the highest priority, and execute S207.
[0072] S207: Convert the current node into a master node in the multi-node network, and send a heartbeat request message to each other node to convert each other node into a slave node in the multi-node network.
[0073] S208, receiving the heartbeat response message fed back by each slave node, and determining the slave node remaining resource value of the corresponding slave node according to each heartbeat response message.
[0074] Specifically, the master node receives the heartbeat response messages fed back by each slave node in response to the heartbeat request message, and can determine the information of the slave nodes that can communicate with it later through the received heartbeat response messages, and then can clarify the slave node remaining resource value corresponding to each slave node based on the information carried by the slave node in the heartbeat response message.
[0075] Optionally, after receiving the heartbeat response message fed back by each slave node, the method further includes: generating multicast network joining control information, and sending the multicast network joining control information to each slave node respectively, so that each slave node and the master node join the same multicast network.
[0076] In this embodiment, the multicast network joining control information can be specifically understood as control information sent by the master node to the slave node that feeds back a heartbeat response message to the master node, so as to control each slave node to join the same multicast network as the master node.
[0077] Specifically, after receiving the heartbeat response message fed back by each slave node, the master node can clearly identify the slave node communicating with it, and then build a multicast network for the master node and each slave node communicating with the master node, and the master node generates multicast network joining control information that at least includes the message type, the node device identification number of the master node and the multicast network joining control instruction, and sends the multicast network joining control information to each slave node that feeds back the heartbeat response message to the master node, so that each slave node can respond to the multicast network joining control information and join the same multicast network corresponding to the master node.
[0078] S209: Determine the slave node corresponding to the largest slave node remaining resource value among the remaining resource values of the slave nodes as the target slave node.
[0079] Specifically, since the backup slave node needs to undertake more data storage and computing tasks than other slave nodes in the multicast network, it requires more resources for data processing. At this time, the master node can compare the remaining resource values of each slave node obtained, and determine the slave node corresponding to the largest slave node remaining resource value as the target slave node that can be used as a backup slave node in the future.
[0080] S210. Generate backup node switching control information, and send the backup node switching control information to the target slave node, so that the target slave node is converted into a backup slave node corresponding to the master node, and the backup slave node is switched to the master node when receiving the master node replacement control instruction or the master node fails.
[0081] It can be understood that the master node replacement control instruction is a control instruction that is actively generated by the master node when it is clear that its own resources or capabilities cannot meet the working requirements of the master node, and is used to send to the backup slave node to complete the master node switching. When the master node fails, the backup slave node switches to the master node, which can be achieved by the backup slave node performing periodic availability queries on the master node, that is, the backup slave node performs availability queries on it at a frequency higher than that of the master node sending heartbeat request messages, or performs other types of information interaction with the master node. When the master node is found to have a failure, the backup slave node can directly complete the identity succession of the master node, and the backup slave node sends a heartbeat request message to the multicast network as the new master node, ensuring the seamless switching of the master node in the multicast network. And because the data in the backup slave node is consistent with the master node, after the backup slave node takes over as the master node, it will not affect the information transmission of other slave nodes in the multicast network.
[0082] Optionally, after converting the target slave node to a backup slave node corresponding to the master node, the method further includes:
[0083] Enable the monitoring function of the backup slave node so that the backup slave node can monitor the communication messages between all slave nodes and the master node in the multicast network;
[0084] A data consistency verification message from the backup slave node is received at a first preset period, and data synchronization is performed with the backup slave node according to the data consistency verification message.
[0085] In this embodiment, the first preset period can be specifically understood as a period predetermined according to the period of the master node sending heartbeat request messages to the multicast network, which is used to ensure that the interaction frequency between the backup slave node and the master node is higher than the interaction frequency between other slave nodes and the master node. The data consistency verification message can be specifically understood as a message used to verify whether the information in the backup slave node is consistent with the information in the master node.
[0086] Specifically, in order to realize hot backup between the master node and the backup slave node, after the backup slave node joins the multicast network consistent with the master node, the monitoring function of the backup slave node can be synchronously turned on based on the backup node access control information, so that the backup slave node can monitor and process the communication messages between other slave nodes and the master node in the multicast network, and maintain the consistency of the master node and the backup slave node in processing other slave node information during the backup slave node monitoring process. At the same time, the backup slave node will send a data consistency verification message to the master node at a first preset period shorter than the heartbeat request message sent by the master node to the outside, and verify the consistency of data storage in the master node and the backup slave node while verifying the availability of the master node, thereby ensuring data synchronization between the master node and the backup slave node.
[0087] In the embodiment of the present invention, since the monitoring function of the backup slave node on each slave node in the multicast network is enabled, the backup slave node will process the business messages sent to the master node by other slave nodes monitored, and obtain the same result as the master node processing the above business message for hot backup storage, so that the backup slave node does not need to obtain its own processing results for the received slave node business message from the master node in the process of maintaining data consistency with the master node, which reduces the amount of data transmission required between the master node and the backup slave node, reduces the hot backup cost and improves the data processing efficiency. At the same time, since the data consistency verification message between the backup slave node and the master node is sent at a cycle shorter than the heartbeat request message sent by the master node to the outside, the backup slave node can monitor the working status of the master node at a higher frequency than other slave nodes in the multicast network, so that the backup slave node can identify the failure of the master node in advance and seamlessly switch to the master node, reducing the impact of the master node failure on the work of each node in the multi-node network.
[0088] Optionally, after each slave node and the master node are added to the same multicast network, the method further includes:
[0089] Sending a heartbeat request message to each slave node in the multicast network at a second preset period, and receiving a heartbeat response message fed back by each slave node;
[0090] Storing the node device identification number and the node remaining resource value in each heartbeat response message;
[0091] When the slave node corresponding to the node device identification number is a backup slave node, verifying the sufficiency of the node remaining resource value of the backup slave node;
[0092] If the verification fails, backup node cut-out control information is generated and sent to the backup slave node, so that the backup slave node is converted into a slave node in the multi-node network, and a new target slave node is determined according to the remaining resource value of each node, and the step of generating backup node cut-in control information and sending the backup node cut-in control information to the target slave node is returned to execute;
[0093] The second preset period is greater than the first preset period.
[0094] In this embodiment, the backup node cut-out control information can be specifically understood as control information sent by the master node to the backup slave node to control its node state to be converted from a backup slave node to a slave node, and to shut down its functions related to the backup slave node. The second preset period can be specifically understood as a period preset according to actual conditions, in which the master node sends a heartbeat request message to the outside to ensure communication between nodes in the multicast network.
[0095] Specifically, after the master node clarifies its own identity and adds each slave node that can communicate with it to the same multicast network, it will send a heartbeat request message to each slave node contained in the multicast network at a second preset period, and after receiving the heartbeat response message fed back by each slave node, it will parse each heartbeat response message, store the power-saving device identification number and node remaining resource value included in each heartbeat response message, so as to constantly update the identity and working status of each slave node in the multicast network. While parsing the heartbeat response message, it can be determined whether the slave node corresponding to the heartbeat response message is a backup slave node based on the node device identification number in the heartbeat response message. If so, it can be determined whether the remaining resources in the backup slave node still support its work as a backup slave node based on the node remaining resource value in the heartbeat response message. That is, the sufficiency of the remaining resource value of the backup slave node is verified. When the verification fails, it is considered that the backup slave node has difficulty in continuing to perform hot backup for the master node and serve as a substitute for the master node. At this time, the master node generates backup node cut-out control information for controlling the backup slave node to exit the backup slave node state, and sends the backup node cut-out control information to the backup slave node, so that the backup slave node is converted into a slave node in the multi-node network. Furthermore, since the master node can obtain multiple heartbeat response messages corresponding to the heartbeat request message it sends, it can re-determine the target slave node based on the remaining resource value of the node corresponding to each slave node except the backup slave node, and return to execute the steps of generating the backup node cut-in control information, and sending the backup node cut-in control information to the target slave node to complete the reset of the backup slave node, ensuring that the backup slave node always exists in the multicast network, so that the master node can be seamlessly switched in time when the master node fails.
[0096] In an embodiment of the present invention, the master node periodically sends a heartbeat request message to the multicast network to which it belongs to maintain the connection with each slave node, and monitors the working state of each slave node based on the heartbeat response message fed back by each slave node. At the same time, the working state of the selected backup slave node and the remaining situation of the node resources can be periodically monitored based on the obtained heartbeat response message, and it can be timely clarified whether the node currently serving as the backup slave node is competent for the work of the master node backup, and it can be replaced in time when it is determined that it is not competent. And when replacement is needed, the new target slave node can be directly determined by directly relying on the received heartbeat response message, without the need for each slave node in the multicast network to resend information, which reduces the cost of determining the new target slave node and improves the determination state of the new backup slave node. At the same time, since the backup slave node can be replaced in time, the real-time existence of the backup slave node in the multicast network is guaranteed, so that when the master node fails, the backup slave node can be found to replace the master node, which improves the robustness of the multi-node network.
[0097] It can be understood that the adequacy verification of the node remaining resource value for the backup slave node in the embodiment of the present invention is not that the backup slave node is considered to be unsatisfied when the node remaining resource value of any slave node among the remaining slave nodes in the multicast network is greater than the node remaining resource value of the backup slave node, but that the adequacy verification of the backup slave node is considered to have failed when the difference between the node remaining resource value of the backup slave node and the node remaining resource value of the remaining slave nodes is greater than a preset resource value threshold. By adopting the above-mentioned processing method, the frequent switching of the backup slave node due to data processing and node performance fluctuations is avoided, the stability of the multi-node network operation is improved, and the robustness of the multi-node network is further improved.
[0098] S211. Convert the current node into a slave node in the multi-node network, and store the node device identification number in the received heartbeat request message as the master node information.
[0099] Specifically, when the current node in a multi-node network determines that its election priority is not the highest priority, it can be considered that it cannot become the master node in the multi-node network. At this time, the current node can be converted into a slave node in the multi-node network. Alternatively, when the current node receives a heartbeat request message, it can be considered that the selection of the master node in the multi-node network has been completed, and it itself cannot exist as a master node. At this time, the current node will also be converted into a slave node in the multi-node network. When receiving a heartbeat request message as a slave node, the slave node will parse the heartbeat request message and store the node device identification number contained therein as the master node information, that is, the node device identity information that currently serves as the master node in the multi-node network can be clarified based on the heartbeat request message.
[0100] It can be understood that the slave node can always assume that the sender of the last received heartbeat request message is the only master node in its network. When the node device identification number parsed from the received heartbeat request message is inconsistent with the master node information previously stored, the master node information will be updated based on the latest received heartbeat request message.
[0101] Optionally, when the time from the last receipt of the heartbeat request message exceeds a preset time threshold, the slave node is converted into a node to be elected in the multi-node network, and the third node election information of the node to be elected is broadcasted externally.
[0102] In this embodiment, the preset time threshold can be specifically understood as a time threshold that is pre-set according to actual conditions and is used to determine the disconnection between the slave node and the master node. The node to be elected can be specifically understood as a node that needs to be elected as the master node in the multi-node network at the current moment. The third node election information can be specifically understood as a set of necessary information sent by the node to be elected to the outside, including the node to be elected to participate in the master node election.
[0103] Specifically, after leaving the initialization state, it can be considered that each node in the multi-node network has different status information, that is, it has been divided into a master node or a slave node. If the slave node does not receive other heartbeat request messages within the preset time threshold after receiving the heartbeat request message for the last time, it can be considered that the slave node has disconnected from the master node, and the master node may not exist in the multi-node network. At this time, the slave node can think that the multi-node network needs to re-enter the master node election state, that is, the slave node can be converted into a node to be elected in the multi-node network, and the same master node election method as the initialization is used to broadcast the third node election information of the node to be elected.
[0104] It can be understood that the third node election information is similar to the first node election information, and can be understood as a set of necessary information for participating in the master node election that is broadcast externally when the node to be elected is the current node in order to implement the master node election.
[0105] Optionally, when third node election information sent by other nodes in the multi-node network is received and the time from the last reception of the heartbeat request message does not exceed a preset time threshold, the third node election information is stored.
[0106] Specifically, when a slave node that is not a master node in a multi-node network receives the third node election information sent by other nodes, it can be considered that there are other nodes in the current multi-node network that are disconnected from the master node and re-elect the master node, and the current master node may be faulty. However, since the time from the current slave node to the last reception of the heartbeat request message does not exceed the preset time threshold, it cannot determine whether the master node is in a normal working state. At this time, the current slave node will save the received third node election information and temporarily do not perform any operations. Until the current slave node receives the heartbeat request message again, it can be considered that there is no abnormality in the master node in the current multi-node network, and the third node election information can be directly ignored; and if the time from the current slave node to the last reception of the heartbeat request message exceeds the preset time threshold, it can be considered that there is an abnormality in the master node in the multi-node network, and the current slave node will perform the same operation as the above-mentioned node to be elected, and complete the same master node election as the initialization based on the previously received and saved third node election information.
[0107] Optionally, if the master node receives the third node election information, it sends a new heartbeat request message to the node to be elected corresponding to the third node election information, so that the node to be elected is converted into a slave node in the multi-node network.
[0108] Specifically, when the master node in a multi-node network receives the third node election information sent by other nodes, it can be considered that there are nodes in the current multi-node network that have not established a connection with itself. On the basis that it itself is the master node, it can immediately send a new heartbeat request message to the node to be elected corresponding to the third node election information, so that the node state of the node to be elected is converted to a slave node in the multi-node network, thereby ensuring the uniqueness of the master node in the multi-node network.
[0109] Optionally, after converting the current node to a master node in a multi-node network when the election priority is the highest priority, it also includes:
[0110] If an abnormal heartbeat request message is received, the priority of the master node and the node corresponding to the abnormal heartbeat request message is compared according to the current node election information of the master node and the node device identification number and node remaining resource value in the abnormal heartbeat request message;
[0111] When the comparison result shows that the master node has a high priority, a new heartbeat request message is sent to the node corresponding to the abnormal heartbeat request message, so that the node corresponding to the abnormal heartbeat request message is converted into a slave node in the multi-node network;
[0112] When the comparison result shows that the master node has a low priority, the master node is converted into a slave node in the multi-node network, and the node device identification number corresponding to the abnormal heartbeat request message is stored as the master node information.
[0113] In this embodiment, the abnormal heartbeat request message can be specifically understood as when a master node already exists in the multi-node network, the master node receives a heartbeat request message sent by other nodes, which can also be understood as a heartbeat request message sent to the outside by another node in the multi-node network whose status is the master node.
[0114] Specifically, after a master node has been elected in a multi-node network, if the master node receives a heartbeat request message sent by other master nodes that should not exist in the multi-node network, the heartbeat request message can be regarded as an abnormal heartbeat request message. In this case, since only one master node that is most suitable for data processing is needed in a multi-node network, the priorities of the above two master nodes can be compared. The specific comparison method is the same as the method for determining the election priority during initialization. By comparing the current node election information of the current node, as well as the node device identification number and the node remaining resource value contained in the abnormal heartbeat request message, the priority comparison between the current node and the node corresponding to the abnormal heartbeat request message is realized. When it is determined that the priority of the master node is higher than the priority of the node corresponding to the abnormal heartbeat request message, the master node will send a new heartbeat request message to the node corresponding to the abnormal heartbeat request message, so that the abnormal heartbeat request message node will complete the same priority comparison process as the current master node and convert itself into a slave node in the multi-node network; when it is determined that the priority of the master node is lower than the priority of the node corresponding to the abnormal heartbeat request message, it can be considered that the node corresponding to the abnormal heartbeat request message is more suitable as the master node of the multi-node network. At this time, the current master node can convert itself into a slave node in the multi-node network, and store the node device identification number corresponding to the abnormal heartbeat request message as the master node information, and perform the same processing as the above-mentioned slave node.
[0115] The technical solution of this embodiment determines whether the election priority of the current node is the highest priority according to the node remaining resource values and node device identification numbers of different nodes in turn. At the same time, it is clarified that after the current node is determined as a slave node, it will re-elect when it has not received a heartbeat request message for a long time, so as to ensure that the master node of the multi-node network always exists. After determining that the current node is the master node, the master node determines the target slave node that can be used as a backup slave node from each slave node based on the slave node remaining resource value contained in each received heartbeat response message. At the same time, the master node can send multicast network joining control information to all slave nodes that feed back heartbeat response messages to it, so that all slave nodes that can communicate with the master node can join the same multicast network with the master node, thereby enabling the monitoring function of the backup slave node for each slave node in the multicast network and the data consistency verification function of the backup slave node for the master node, thereby realizing hot backup of the master node by the backup slave node and reducing the amount of data that needs to be communicated between the backup slave node and the master node, so that the backup slave node that is consistent with the content of the master node can seamlessly switch to the master node when receiving the master node replacement control instruction or the master node fails, without the need to directly re-select the master node, or the situation where the newly selected master node cannot directly adapt to the slave node task, thereby improving the system robustness of the multi-node network, reducing the number of executions of the master node election process, and improving the performance of the multi-node network.
[0116] Embodiment 3
[0117] Figure 3 Schematic diagram of the structure of a multi-node network master node selection device provided in Embodiment 3 of the present invention. The multi-node network master node selection device can be applied to any node in the multi-node network, such as Figure 3 As shown, the multi-node network master node selection device includes: an election information processing module 31, a priority determination module 32, a node conversion module 33, a target node determination module 34 and a node switching module 35.
[0118] Among them, the election information processing module 31 is used to broadcast the first node election information of the current node once during initialization, and receive the second node election information of other nodes in the multi-node network during the election duration; the priority determination module 32 is used to determine the election priority of the current node in the multi-node network according to the first node election information and the second node election information; the node conversion module 33 is used to convert the current node into a master node in the multi-node network when the election priority is the highest priority, and send a heartbeat request message to each other node to convert each other node into a slave node in the multi-node network; the target node determination module 34 is used Receive the heartbeat response message fed back by each slave node, and determine the target slave node in each slave node according to each heartbeat response message; the node switching module 35 is used to generate backup node switching control information, and send the backup node switching control information to the target slave node, so that the target slave node is converted into a backup slave node corresponding to the master node, and the backup slave node is switched to the master node when receiving the master node replacement control instruction or the master node fails; wherein the first node election information includes at least the current node device identification number and the current node remaining resource value of the current node; the second node election information includes at least the node device identification number and the node remaining resource value of the corresponding node.
[0119] The technical solution of this embodiment, when selecting the master node for the initialized multi-node network, adopts a method in which all nodes broadcast the node election information containing the current node device identification number and the current node remaining resource value, so that each node in the multi-node network that receives the node election information can complete its own priority determination in the multi-node network according to the election information of each node, and then complete the master node selection according to the determined election priority. Then, after the master node selection is completed, through the heartbeat request message sent by the master node, it is guaranteed that all nodes in the multi-node network that can receive the master node heartbeat request message and can communicate directly with the master node are converted into slave nodes, and the integrity of the master node selection in the master node and all the slave nodes that can communicate directly with it is guaranteed through one communication. At the same time, the master node sets a backup slave node that can seamlessly replace the master node function in each slave node according to the heartbeat response message fed back by each slave node corresponding to it, so that the master node can be seamlessly replaced by the backup slave node to become the new master node when it fails, without directly re-selecting the master node, thereby improving the system robustness of the multi-node network, reducing the number of executions of the master node election process, and improving the performance of the multi-node network.
[0120] Optionally, the priority determination module 32 includes:
[0121] The first priority determination unit is used to determine the election priority of the current node as a non-highest priority if the remaining resource value of the current node is less than the remaining resource value of any of the nodes.
[0122] The second priority determination unit is used to determine the election priority of the current node as the highest priority if the remaining resource value of the current node is greater than the remaining resource value of each node.
[0123] The third priority determination unit is used to determine the election priority of the current node according to the node device identification number corresponding to each of the candidate node residual resource values and the current node device identification number if there is at least one candidate node residual resource value among the candidate node residual resource values that is equal to the current node residual resource value and greater than the remaining node residual resource values.
[0124] Optionally, the third priority determination unit is specifically configured to:
[0125] If the current node device identification number is greater than the node device identification number corresponding to the remaining resource value of each node to be selected, the election priority of the current node is determined as the highest priority; otherwise, the election priority of the current node is determined as a non-highest priority.
[0126] Optionally, the target node determination module 34 includes:
[0127] The resource value determination unit is used to determine the slave node remaining resource value of the corresponding slave node according to each of the heartbeat response messages.
[0128] The target node determination unit is used to determine the slave node corresponding to the largest slave node remaining resource value among the slave node remaining resource values as the target slave node.
[0129] Optionally, the multi-node network master node selection device further includes:
[0130] The multicast network construction module is used to generate multicast network joining control information after receiving the heartbeat response message fed back by each slave node, and send the multicast network joining control information to each slave node respectively, so that each slave node and the master node join the same multicast network.
[0131] Optionally, the multi-node network master node selection device further includes:
[0132] A data synchronization module is used to enable the monitoring function of the backup slave node after converting the target slave node into a backup slave node corresponding to the master node, so that the backup slave node can monitor the communication messages between all slave nodes in the multicast network and the master node; receive the data consistency verification message of the backup slave node at a first preset period, and synchronize data with the backup slave node based on the data consistency verification message.
[0133] Optionally, the multi-node network master node selection device also includes: a node verification module.
[0134] Node verification module, specifically used for:
[0135] After each of the slave nodes and the master node are added to the same multicast network, a heartbeat request message is sent to each slave node in the multicast network at a second preset period, and a heartbeat response message fed back by each of the slave nodes is received;
[0136] Storing the node device identification number and the node remaining resource value in each of the heartbeat response messages;
[0137] When the slave node corresponding to the node device identification number is a backup slave node, verifying the sufficiency of the node remaining resource value of the backup slave node;
[0138] If the verification fails, backup node cut-out control information is generated and sent to the backup slave node, so that the backup slave node is converted into a slave node in the multi-node network, and a new target slave node is determined according to the remaining resource value of each node, and the step of generating backup node cut-in control information and sending the backup node cut-in control information to the target slave node is returned to execute;
[0139] Wherein, the second preset period is greater than the first preset period.
[0140] Optionally, the multi-node network master node selection device further includes: a master node conflict module, which is used to:
[0141] After converting the current node into a master node in the multi-node network when the election priority is the highest priority, if an abnormal heartbeat request message is received, a priority comparison is performed between the master node and the node corresponding to the abnormal heartbeat request message according to the current node election information of the master node and the node device identification number and the node remaining resource value in the abnormal heartbeat request message;
[0142] When the comparison result shows that the master node has a high priority, a new heartbeat request message is sent to the node corresponding to the abnormal heartbeat request message, so that the node corresponding to the abnormal heartbeat request message is converted into a slave node in the multi-node network;
[0143] When the comparison result shows that the master node has a low priority, the master node is converted into a slave node in the multi-node network, and the node device identification number corresponding to the abnormal heartbeat request message is stored as the master node information.
[0144] Optionally, the multi-node network master node selection device further includes:
[0145] A slave node conversion module is used to, after determining the election priority of the current node in the multi-node network based on the first node election information and each of the second node election information, convert the current node into a slave node in the multi-node network when the election priority is not the highest priority or when a heartbeat request message is received, and store the node device identification number in the received heartbeat request message as the master node information.
[0146] Optionally, the multi-node network master node selection device further includes:
[0147] A re-election module is used to, after converting the current node into a slave node in the multi-node network, convert the slave node into a node to be elected in the multi-node network when the time from the last reception of a heartbeat request message exceeds a preset time threshold, and broadcast the third node election information of the node to be elected once; and store the third node election information when the third node election information sent by other nodes in the multi-node network is received and the time from the last reception of a heartbeat request message does not exceed the preset time threshold.
[0148] Optionally, the multi-node network master node selection device further includes:
[0149] A message retransmission module is used to convert the current node into a master node in the multi-node network when the election priority is the highest priority. If the third node election information is received, a new heartbeat request message is sent to the node to be elected corresponding to the third node election information to convert the node to be elected into a slave node in the multi-node network.
[0150] The multi-node network master node selection device provided in the embodiment of the present invention can execute the multi-node network master node selection method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0151] Embodiment 4
[0152] Figure 4A structural diagram of a multi-node network master node selection device provided for Embodiment 4 of the present invention. The multi-node network master node selection device 40 may be an electronic device intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. Exemplarily, in the field of power grids, the multi-node network master node selection device may be an intelligent fusion terminal for constituting any node in a multi-node network, and the embodiments of the present invention are not limited to this. The electronic device may also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0153] like Figure 4 As shown, the multi-node network master node selection device 40 includes at least one processor 41, and a memory connected to the at least one processor 41, such as a read-only memory (ROM) 42, a random access memory (RAM) 43, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 41 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 42 or the computer program loaded from the storage unit 48 to the random access memory (RAM) 43. In RAM 43, various programs and data required for the operation of the multi-node network master node selection device 40 can also be stored. The processor 41, ROM 42 and RAM 43 are connected to each other through a bus 44. The input / output (I / O) interface 45 is also connected to the bus 44.
[0154] Multiple components in the multi-node network master node selection device 40 are connected to the I / O interface 45, including: an input unit 46, such as a keyboard, a mouse, etc.; an output unit 47, such as various types of displays, speakers, etc.; a storage unit 48, such as a disk, an optical disk, etc.; and a communication unit 49, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 49 allows the multi-node network master node selection device 40 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0155] The processor 41 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 41 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 41 executes the various methods and processes described above, such as a multi-node network master node selection method.
[0156] In some embodiments, the multi-node network master node selection method can be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 48. In some embodiments, part or all of the computer program can be loaded and / or installed on the multi-node network master node selection device 40 via the ROM 42 and / or the communication unit 49. When the computer program is loaded into the RAM 43 and executed by the processor 41, one or more steps of the multi-node network master node selection method described above can be performed. Alternatively, in other embodiments, the processor 41 can be configured to execute the multi-node network master node selection method by any other appropriate means (for example, by means of firmware).
[0157] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0158] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0159] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, device, or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0160] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0161] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0162] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0163] 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 described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0164] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for selecting a master node in a multi-node network, characterized in that: Applied to any node in a multi-node network, the method comprises: Broadcasting the first node election information of the current node once at the time of initialization, and receiving the second node election information of other nodes in the multi-node network during the election duration; Determine the election priority of the current node in the multi-node network according to the first node election information and each of the second node election information; When the election priority is the highest priority, converting the current node into a master node in the multi-node network, and sending a heartbeat request message to each of the other nodes to convert each of the other nodes into a slave node in the multi-node network; Receive the heartbeat response message fed back by each of the slave nodes, and determine the target slave node among the slave nodes according to each of the heartbeat response messages; Generate backup node switching control information, and send the backup node switching control information to the target slave node, so that the target slave node is converted into a backup slave node corresponding to the master node, and the backup slave node is switched to the master node when receiving a master node replacement control instruction or the master node fails; The first node election information includes at least the current node device identification number and the current node remaining resource value of the current node; the second node election information includes at least the node device identification number and the node remaining resource value of the corresponding node; Wherein, after receiving the heartbeat response message fed back by each slave node, the method further includes: Generate multicast network joining control information, and send the multicast network joining control information to each slave node respectively, so that each slave node and the master node join the same multicast network; Wherein, after converting the target slave node into a backup slave node corresponding to the master node, the method further includes: Turning on the monitoring function of the backup slave node so that the backup slave node can monitor the communication messages between all slave nodes in the multicast network and the master node; receiving a data consistency verification message from the backup slave node at a first preset period, and performing data synchronization with the backup slave node according to the data consistency verification message; After each of the slave nodes and the master node are added to the same multicast network, the method further includes: Sending a heartbeat request message to each slave node in the multicast network at a second preset period, and receiving a heartbeat response message fed back by each slave node; Storing the node device identification number and the node remaining resource value in each of the heartbeat response messages; When the slave node corresponding to the node device identification number is a backup slave node, verifying the sufficiency of the node remaining resource value of the backup slave node; If the verification fails, backup node cut-out control information is generated and sent to the backup slave node, so that the backup slave node is converted into a slave node in the multi-node network, and a new target slave node is determined according to the remaining resource value of each node, and the step of generating backup node cut-in control information and sending the backup node cut-in control information to the target slave node is returned to execute; Wherein, the second preset period is greater than the first preset period.
2. The method according to claim 1, characterized in that The determining the election priority of the current node in the multi-node network according to the first node election information and each second node election information includes: If the remaining resource value of the current node is less than the remaining resource value of any of the nodes, the election priority of the current node is determined as a non-highest priority; If the remaining resource value of the current node is greater than the remaining resource value of each node, the election priority of the current node is determined as the highest priority; If there is at least one remaining resource value of a candidate node among the remaining resource values of each node that is equal to the remaining resource value of the current node and greater than the remaining resource values of the remaining nodes, the election priority of the current node is determined based on the node device identification number corresponding to each of the remaining resource values of the candidate nodes and the current node device identification number.
3. The method according to claim 2, characterized in that The step of determining the election priority of the current node according to the node device identification number corresponding to the remaining resource value of each of the candidate nodes and the current node device identification number includes: If the current node device identification number is greater than the node device identification number corresponding to the remaining resource value of each node to be selected, the election priority of the current node is determined as the highest priority; otherwise, the election priority of the current node is determined as a non-highest priority.
4. The method according to claim 1, characterized in that: Determining a target slave node among the slave nodes according to the heartbeat response messages includes: Determine the slave node remaining resource value of the corresponding slave node according to each of the heartbeat response messages; The slave node corresponding to the largest slave node remaining resource value among the slave node remaining resource values is determined as the target slave node.
5. The method according to claim 1, characterized in that After converting the current node into a master node in the multi-node network when the election priority is the highest priority, the method further includes: If an abnormal heartbeat request message is received, a priority comparison is performed between the master node and the node corresponding to the abnormal heartbeat request message according to the current node election information of the master node and the node device identification number and the node remaining resource value in the abnormal heartbeat request message; When the comparison result shows that the master node has a high priority, a new heartbeat request message is sent to the node corresponding to the abnormal heartbeat request message, so that the node corresponding to the abnormal heartbeat request message is converted into a slave node in the multi-node network; When the comparison result shows that the master node has a low priority, the master node is converted into a slave node in the multi-node network, and the node device identification number corresponding to the abnormal heartbeat request message is stored as the master node information.
6. The method according to claim 1, characterized in that After determining the election priority of the current node in the multi-node network according to the first node election information and each of the second node election information, the method further includes: When the election priority is not the highest priority or when a heartbeat request message is received, the current node is converted into a slave node in the multi-node network, and the node device identification number in the received heartbeat request message is stored as the master node information.
7. The method according to claim 6, characterized in that After converting the current node into a slave node in the multi-node network, the method further includes: When the time from the last reception of the heartbeat request message exceeds a preset time threshold, converting the slave node into a node to be elected in the multi-node network, and broadcasting the third node election information of the node to be elected externally once; When the third node election information sent by other nodes in the multi-node network is received and the time from the last reception of the heartbeat request message does not exceed the preset time threshold, the third node election information is stored.
8. The method according to claim 7, characterized in that After converting the current node into a master node in the multi-node network when the election priority is the highest priority, the method further includes: If the third node election information is received, a new heartbeat request message is sent to the node to be elected corresponding to the third node election information, so that the node to be elected is converted into a slave node in the multi-node network.
9. A multi-node network master node selection device, characterized in that: Applicable to any node in a multi-node network, including: An election information processing module, used to broadcast first node election information of the current node once upon initialization, and receive second node election information of other nodes in the multi-node network during the election duration; a priority determination module, configured to determine the election priority of the current node in the multi-node network according to the first node election information and each of the second node election information; A node conversion module, used for converting the current node into a master node in the multi-node network when the election priority is the highest priority, and sending a heartbeat request message to each of the other nodes to convert each of the other nodes into a slave node in the multi-node network; A target node determination module, used for receiving the heartbeat response message fed back by each of the slave nodes, and determining the target slave node among the slave nodes according to each of the heartbeat response messages; A node switching module, used for generating backup node switching control information, and sending the backup node switching control information to the target slave node, so that the target slave node is converted into a backup slave node corresponding to the master node, and the backup slave node is switched to the master node when receiving the master node replacement control instruction or the master node fails; The first node election information includes at least the current node device identification number and the current node remaining resource value of the current node; the second node election information includes at least the node device identification number and the node remaining resource value of the corresponding node; The multi-node network master node selection device further includes: a multicast network construction module, which is used to generate multicast network joining control information after receiving the heartbeat response message fed back by each slave node, and send the multicast network joining control information to each slave node respectively, so that each slave node and the master node join the same multicast network; Wherein, the multi-node network master node selection device further includes: a data synchronization module, which is used to enable the monitoring function of the backup slave node after the target slave node is converted into a backup slave node corresponding to the master node, so that the backup slave node can monitor the communication messages between all slave nodes in the multicast network and the master node; receive the data consistency verification message of the backup slave node at a first preset period, and synchronize data with the backup slave node according to the data consistency verification message; Among them, the multi-node network master node selection device also includes: a node verification module, which is used to send a heartbeat request message to each slave node in the multicast network at a second preset period after each slave node and the master node are added to the same multicast network, and receive a heartbeat response message fed back by each slave node; store the node device identification number and the node remaining resource value in each heartbeat response message; when the slave node corresponding to the node device identification number is a backup slave node, verify the sufficiency of the node remaining resource value of the backup slave node; if the verification fails, generate and send a backup node cut-out control information to the backup slave node, so that the backup slave node is converted into a slave node in the multi-node network, and determine a new target slave node according to the remaining resource value of each node, return to execute the step of generating the backup node cut-in control information, and send the backup node cut-in control information to the target slave node; wherein, the second preset period is greater than the first preset period.
10. A multi-node network master node selection 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 a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the multi-node network master node selection method described in any one of claims 1-8.
11. A storage medium containing computer executable instructions, characterized in that: When the computer executable instructions are executed by a computer processor, they are used to execute the multi-node network master node selection method as described in any one of claims 1-8.
Citation Information
Patent Citations
Cluster election processing method and device, equipment and storage medium
CN113014634A
Election method and device for a main node in a cluster, equipment and a storage medium
CN113965578A
System and method for automatic election of a representative node within a communications network with built-in redundancy
US6363416B1
Master node election method and apparatus, and storage system
WO2016150066A1
