Server cluster main node election method and device, server node and storage medium

By exchange voting data and identification information between nodes in the server cluster, sorting to determine the master node, solve the problem of low main efficiency caused by relying on third -party components in the existing technology, and achieve a more efficient masterpiece election process process process process process Essence

CN119363545AActive Publication Date: 2025-01-24MAIPU COMM TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411484129.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-23
Publication Date
2025-01-24
Estimated Expiration
2044-10-23

AI Technical Summary

Technical Problem

The existing master node election method relies on third-party components, resulting in low efficiency in selecting masters when there are problems with third-party components or slow startup.

Method used

The ordering is performed to determine the master node by exchanging vote data and identification information among the nodes in the server cluster. Specific steps include generating election requests, exchanging vote data, sorting identification information, and determining the master node according to preset rules.

Benefits of technology

It improved the efficiency of the master node election, avoided the problem of low main efficiency caused by relying on third -party components, and reduced the difficulty and burden of software management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119363545A_ABST
    Figure CN119363545A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a server cluster master selection method and device, a server node and a storage medium, and relates to the technical field of distributed clusters, and the method comprises the steps: generating a first election request according to the identification information of the server node, obtaining a second election request generated by other server nodes in a server cluster, each second election request comprises the vote data and the identification information of the corresponding server node, sorting all the identification information according to all the vote data to obtain a sorting result, determining target identification information according to the sorting result and a preset rule, and sending the target identification information to the server node; and determining the server node corresponding to the target identification information as the main server node selected by the server node. According to the method and the device, the owner is selected according to the vote data included in the election request generated by each node, so that the problem of relatively low owner selection efficiency when the third-party component goes wrong due to the fact that owner selection depends on the third-party component is avoided, and the owner selection efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of distributed cluster technology, and in particular to a method, device, server node and storage medium for selecting a master node of a server cluster. Background Art

[0002] In the field of data communication, with the development and maturity of cluster technology and the geometric increase in the amount of data that needs to be processed, more and more software systems use cluster technology to carry their own business. In the cluster system, some key services are multi-instance, which can balance the load and process data synchronously to improve the overall system response speed. There are two types of business using cluster systems, one is stateless and the other is stateful. Stateless business can be executed indiscriminately on all nodes, but some functions of stateful business need to select a fixed node from the multiple nodes of the cluster to perform aggregated tasks. Most of the current businesses cannot be truly stateless and are still stateful. A master server node is required in the cluster to complete some unified work.

[0003] The existing master node election method relies on third-party components. The identification information of its own node is created in the specified file directory of the third-party component. The first created one is the master server node, and the later created one is the slave server node. If there is a problem with the third-party component or it starts slowly, it will affect the efficiency of the business master node election. Summary of the invention

[0004] The object of the present invention is to provide a method, device, server node and storage medium for selecting a master in a server cluster, so as to solve the problem of slow master selection efficiency.

[0005] In a first aspect, the present invention provides a method for selecting a master node in a server cluster, which is applied to any server node in the server cluster. The method comprises:

[0006] Generate a first election request according to the identification information of the server node, and send the first election request to the remaining server nodes in the server cluster;

[0007] Obtaining second election requests generated by the remaining server nodes in the server cluster; each of the second election requests includes vote data and identification information of the corresponding server node;

[0008] All the identification information is sorted according to all the ballot data to obtain a sorting result; the target identification information is determined according to the sorting result according to a preset rule, and the server node corresponding to the target identification information is determined as the main server node selected by this server node.

[0009] In an optional implementation manner, the identification information of the server node generates a first election request, including:

[0010] Get the current master election round of this server node and generate a random number with a preset number of digits;

[0011] Generate ballot data according to the random number and the identification information of the server node;

[0012] The first election request is generated according to the current master election round, the identification information of the server node and the vote data of the server node.

[0013] In an optional implementation manner, generating the ballot data of the server node according to the random number and the identification information of the server node includes:

[0014] The random number is added to the identification information of the server node to generate the ballot data.

[0015] In an optional implementation manner, the sorting of all the identification information according to all the ballot data to obtain a sorting result includes:

[0016] Reverse processing of each of the ballot data;

[0017] Convert each of the ballot data after reverse processing into a preset format;

[0018] All the identification information is sorted according to all the ballot data converted into a preset format to obtain a sorting result.

[0019] In an optional implementation, before reversing each of the ballot data, the method further includes:

[0020] Determining whether the length of each of the ballot data exceeds a preset character length;

[0021] If the length of the ballot data exceeds the preset character length, data of the preset character length is selected from the corresponding ballot data, and the selected data is determined as the new ballot data.

[0022] In an optional implementation manner, after determining the server node corresponding to the target identification information as the primary server node selected by the server node, the method further includes:

[0023] Receiving the selection result confirmation requests sent by the remaining server nodes; each of the selection result confirmation requests includes identification information of the main server node selected by the corresponding server node;

[0024] If the identification information included in each of the selection result confirmation requests is the same as the target identification information, it is confirmed that the master selection is successful.

[0025] In an optional embodiment, the method further comprises:

[0026] Periodically sending keep-alive information to the remaining server nodes;

[0027] Receiving response information sent by the remaining servers according to the keep-alive information;

[0028] According to the response information, find out whether there is a downed server node;

[0029] If there is a downed server node, determine whether the downed server node is the main server node selected by the current server node;

[0030] If the downed server node is the main server node selected by the current server node, the server node corresponding to the next identification information of the target identification information in the sorting result is determined as the main server node newly selected by the current server node.

[0031] In a second aspect, the present invention provides a server cluster master node election device, which is applied to any server node in a server cluster, and the device includes:

[0032] An election request generating module, configured to generate a first election request according to the identification information of the server node, and send the first election request to the remaining server nodes in the server cluster;

[0033] An election request acquisition module, used to acquire second election requests generated by the remaining server nodes in the server cluster; each second election request includes vote data and identification information of the corresponding server node;

[0034] A sorting module, used to sort all the identification information according to all the ballot data to obtain a sorting result;

[0035] The master selection module is used to determine the target identification information according to the sorting result according to a preset rule, and determine the server node corresponding to the target identification information as the master server node selected by the server node.

[0036] In a third aspect, the present invention provides a server node, comprising a processor and a memory, wherein the memory stores a computer program executable by the processor, and the computer program executable by the processor is used to implement the server cluster master node election method described in any of the aforementioned implementation modes.

[0037] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the server cluster master node election method as described in any one of the aforementioned embodiments is implemented.

[0038] The server cluster master node election method, device, server node and storage medium provided by the embodiment of the present invention are applied to any server node in the server cluster. The method includes: generating a first election request according to the identification information of the server node, and sending the first election request to the remaining server nodes in the server cluster, obtaining the second election request generated by the remaining server nodes in the server cluster, each second election request includes the ballot data and identification information of the corresponding server node, sorting all the identification information according to all the ballot data to obtain the sorting result, determining the target identification information according to the preset rules according to the sorting result, and determining the server node corresponding to the target identification information as the main server node selected by the server node. By selecting the master according to the ballot data included in the election request generated by each node, the problem of low efficiency of the master election caused by relying on a third-party component for the master election is avoided when a problem occurs in the third-party component, thereby improving the efficiency of the master election. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.

[0040] Figure 1 A schematic diagram of an application environment of the server cluster master node election method provided by an embodiment of the present invention is shown;

[0041] Figure 2 A schematic diagram of a process of selecting and generating a master node of a server cluster provided by an embodiment of the present invention is shown;

[0042] Figure 3 Another schematic diagram of a process of selecting and generating a server cluster master node provided by an embodiment of the present invention is shown;

[0043] Figure 4 Another schematic diagram of a process of selecting and generating a server cluster master node according to an embodiment of the present invention is shown;

[0044] Figure 5 Another schematic diagram of the process of selecting and generating a server cluster master node provided by an embodiment of the present invention is shown;

[0045] Figure 6 Another schematic diagram of a process of selecting and generating a server cluster master node provided by an embodiment of the present invention is shown;

[0046] Figure 7 A module block diagram of a server node device provided by an embodiment of the present invention is shown;

[0047] Figure 8 A block diagram of a server node provided by an embodiment of the present invention is shown.

[0048] Icon: 100 - server node; 110 - memory; 120 - processor; 130 - communication module; 200 - server cluster master node election device; 210 - election request generation module; 220 - election request acquisition module; 230 - sorting module; 240 - master election module. DETAILED DESCRIPTION

[0049] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.

[0050] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0051] It should be noted that relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprises" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.

[0052] See also Figure 1 , Figure 1A schematic diagram of an application environment of the server cluster master node election method provided by an embodiment of the present invention is shown. Multiple server nodes 100 are located in a server cluster, and multiple server nodes 100 are all connected in communication to achieve data interaction between multiple server nodes 100. As a way, multiple server nodes 100 can be connected via WIFI, ZigBee, 2G / 3G / 4G / 5G, which is not limited here.

[0053] See also Figure 2 , Figure 2 A schematic diagram of a process flow of a method for electing a master node in a server cluster provided by an embodiment of the present invention is shown. The method for electing a master node in a server cluster can be applied to any server node in a server cluster. The following takes any server node in a server cluster as an example to illustrate the specific process of this embodiment. Figure 2 The process shown is described in detail, and the method for selecting the master node of the server cluster may specifically include the following steps:

[0054] Step 110: Generate a first election request according to the identification information of the server node, and send the first election request to the remaining server nodes in the server cluster.

[0055] The identification information may include IP information, HOST information, and other information that can uniquely identify the server node.

[0056] It is understandable that the server node will send the first election request generated by itself to the remaining server nodes in the server cluster, and the remaining server nodes in the server cluster will all receive the first election request generated by the server node.

[0057] Step 120: Obtain the second election request generated by the remaining server nodes in the server cluster.

[0058] Each second election request includes vote data and identification information of the corresponding server node.

[0059] Step 130: Sort all identification information according to all ballot data to obtain a sorting result.

[0060] It should be noted that the first election request includes the vote data of the server node, so the vote data of all server nodes in the server cluster are equal to the total identification information for sorting.

[0061] Step 140: Determine the target identification information according to the sorting result and a preset rule, and determine the server node corresponding to the target identification information as the main server node selected by the server node.

[0062] In some implementations, the server node corresponding to the target identification information may be the current server node, and the current server node is the main server node.

[0063] As an implementation mode, the server node may determine the first identification information in the sorting result as the target identification information.

[0064] As another implementation, the server node may also determine the last identification information in the sorting result as the target identification information.

[0065] In some implementations, if there are two equal vote data in the sorting result, the server node regenerates an election request and sends the regenerated election request to the remaining server nodes in the server cluster to re-elect the leader.

[0066] In some implementations, after all server nodes in the server cluster have selected a master server node, the master server node selected by all server nodes is the same server node, and the task is started with the server node as the master server node.

[0067] The existing leader election method uses third-party components to elect a leader. If the task execution itself does not need to rely on third-party components, introducing third-party components just for leader election will cause difficulties in software management and additional burden. Among them, third-party components may include redis and zookeepr.

[0068] The server cluster master node election method provided by the embodiment of the present invention generates a first election request according to the identification information of the server node, and sends the first election request to the remaining server nodes in the server cluster, and obtains the second election request generated by the remaining server nodes in the server cluster; each second election request includes the ballot data and identification information of the corresponding server node, and all the identification information is sorted according to all the ballot data to obtain the sorting result, and the target identification information is determined according to the preset rules according to the sorting result, and the server node corresponding to the target identification information is determined as the main server node selected by the server node. By selecting the master according to the ballot data included in the election request generated by each node, the problem of low efficiency of the master election caused by relying on a third-party component for the master election is avoided when a problem occurs in the third-party component, thereby improving the efficiency of the master election and reducing the difficulty and burden of software management.

[0069] The existing master election method can also use the node startup time as the basis for master election. Each node will have its own startup completion time. Each node will inform other hosts of its startup completion time. Finally, the host with the earliest startup time will be used as the master server node, and the rest will be slave server nodes. In a single physical node or a virtualized environment, multiple virtual machines (pods) may be started at the same time because they share the resources of the same physical host. That is, the startup times of multiple pods may be exactly the same. Therefore, it is impossible to use the pod startup time as the basis for master election. The server cluster master election method provided by the embodiment of the present invention uses the ballot data as the basis for master election instead of the node startup time. Therefore, the master election can still be performed in a single physical node or a virtualized environment without limiting the master election scenario, and avoids the problem of re-election due to the same startup completion time of multiple nodes, thereby improving the efficiency of master election.

[0070] like Figure 3 As shown, step 110 specifically further includes the following steps:

[0071] Step S111: Obtain the current master election round of the server node and generate a random number of preset digits.

[0072] The current master election round is the master election round of the current server node. For example, if the current round is the first master election, the current round of the current server node is 1.

[0073] In some embodiments, the server node may generate a random number based on a preset number of bits. The preset number of bits in each server node is the same. For example, if the preset number of bits is 5, the random number may be 12345; if the preset number of bits is 3, the random number may be 222.

[0074] Step S112: Generate ballot data based on the random number and the identification information of the server node.

[0075] In some implementations, the random number is added to the identification information of the server node to generate the vote data of the server node. For example, if the identification information of the server node is hostA and the random number is 22122, the vote data of the server node is hostA22122.

[0076] In some implementations, the random number is added before the identification information of the server node to generate the vote data of the server node. For example, if the identification information of the server node is hostB and the random number is 2325, the vote data of the server node is 2325hostB.

[0077] Step S113: Generate a first election request according to the current election round, the identification information of the server node and the vote data of the server node.

[0078] The election request of the server node also includes the information type of the election request, so that the server node receiving the election request can confirm the type of the election request.

[0079] In order to facilitate the sorting of vote data, Figure 4 As shown, step 130 specifically further includes the following steps:

[0080] Step 131: Process each ballot data in reverse order.

[0081] It should be noted that the reverse processing is to reverse the order of the ballot data, that is, to rearrange the characters in the ballot data in the opposite order. For example, if the ballot data is IP4587, the ballot data will be 7854PI after reverse processing.

[0082] Step 132: Convert each ballot data after reverse processing into a preset format.

[0083] In some embodiments, the ballot data is converted into a value corresponding to a preset character encoding standard, and the numerical value of each digit in the converted value is multiplied by 10 to the power of the corresponding digit, and all the results are added to obtain the ballot data converted into a preset format.

[0084] The preset format may be ASCII code, Unicode code, UTF code, etc., which is not limited here.

[0085] Step 133: Sort all identification information according to all ballot data converted into a preset format to obtain a sorting result.

[0086] As an implementation mode, the server node may sort all identification information in descending order according to all ballot data converted into a preset format to obtain a sorting result.

[0087] As another implementation, the server node may sort all identification information in ascending order based on all ballot data converted into a preset format to obtain a sorting result.

[0088] For example, the preset format is the sum of the digits after conversion to ASCII code. The ballot data of server node A is ipA1112, and the ballot data of server node B is ipB2693. The ballot data of server node A is ipA1112, which is 2111Api after reverse processing. 2111Api is converted into ASCII code (51 49 49 49 65 112 105), and the value of each digit in the ASCII code value (51 49 49 49 65 112 105) is multiplied by 10 to the power of the corresponding digit. All the results are added together to obtain the ballot data of server node A converted into the preset format, which is 116904440.

[0089] (50×10 0 +49×10 1 +49×10 2 +49×10 3 +65×10 4 +112×10 5 +105×10 6= 116904440), the voting data of server node B is ipB2693, which is reversed to 3962Bpi, and 3962Bpi is converted into ASCII code (51 57 54 50 66 112 105), and the value of each digit in the ASCII code value (51 5754 50 66 112 105) is multiplied by 10 to the power of the corresponding digit, and all the results are added together to obtain the voting data of server node B converted into the preset format, which is 116916021 (51×10 0 +57×10 1 +54×10 2 +50×10 3 +66×10 4 +112×10 5 +105×10 6= 116916021), sort ipA and ipB in descending order according to the ballot data 116904440 of server node A converted into a preset format and the ballot data 116916021 of server node B converted into a preset format, and the sorting results are ipB and ipA.

[0090] In order to improve the efficiency of sorting the ballot data, the following steps are specifically included before step 131: determine whether the length of each ballot data exceeds the preset character length; if the length of the ballot data exceeds the preset character length, select data with the preset character length from the corresponding ballot data, and determine the selected data as the new ballot data.

[0091] In some implementations, the server node may preferentially select a random number portion from the corresponding ballot data, and then select data of the remaining preset character length from the ballot data.

[0092] For example, the preset character length is 7. If the ballot data is hostA28465, first select the 5-digit random number 28465, and then select the remaining 2 digits tA, then the new ballot data is tA28465; the preset character length is 8. If the ballot data is 875952hostB, first select the 6-digit random number 875952, and then select the remaining 2 digits ho, then the new ballot data is 875952ho.

[0093] In order to ensure that the master server node selected by each server node is the same server node, Figure 5 As shown, after step 140, the following steps are specifically included:

[0094] Step 150: Receive selection result confirmation requests sent by other server nodes.

[0095] Wherein, each selection result confirmation shall include the identification information of the main server node selected by the corresponding server node.

[0096] In some embodiments, after determining the server node corresponding to the target identification information as the main server node selected by this server node, this server node can generate a selection result confirmation request for this server node based on the target identification information, and send the selection result confirmation request for this server node to the remaining server nodes in the server cluster.

[0097] Step 160: If the identification information included in each selection result confirmation request is the same as the target identification information, it is confirmed that the master selection is successful.

[0098] In some implementations, after confirming that the master election is successful, the server node corresponding to the target identification information is used as the master server node to perform the task.

[0099] In order to monitor the working status of the server cluster, find faulty server nodes in time, and reduce system downtime, such as Figure 6 As shown, the above server cluster master election method specifically further includes the following steps:

[0100] Step 210: Periodically send keep-alive information to other server nodes.

[0101] Step 220: Receive response information sent by other servers according to the keep-alive information.

[0102] Step 230: According to the response information, check whether there is a downed server node.

[0103] It should be noted that if a server node crashes, it is impossible to send response information based on the keep-alive information, that is, the server node that does not send response information is determined as a crashed server node.

[0104] Step 240: If there is a downed server node, determine whether the downed server node is the main server node selected by the current server node.

[0105] In some embodiments, if there is a downed server node, the identification information of the downed server node is obtained to determine whether the identification information of the downed server node is the target identification information. If the identification information of the downed server node is the target identification information, the downed server node is the main server node selected by this server node.

[0106] Step 250: If the downed server node is the primary server node selected by the server node, the server node corresponding to the next identification information of the target identification information in the sorting result is determined as the primary server node newly selected by the server node.

[0107] In some implementations, the server node stores the sorting result. After the main server node crashes, the server node corresponding to the next identification information of the target identification information in the sorting result is determined as the main server node newly selected by the server node.

[0108] For example, the sorting results are the identification information of server node A, the identification information of server node C, the identification information of server node D, and the identification information of server node B. The main server node selected by this server node is server node C. After server node C crashes, server node D is determined as the newly selected main server node by the previous server node.

[0109] It is understandable that this server node stores the sorting results. When the selected master server node crashes, there is no need to re-elect the master. A new master server node can be determined based on the sorting results, thereby improving the efficiency of master node election.

[0110] In some implementations, if the server node is a master server node and is a downed server node, the server node stops executing the current task, and other server nodes in the server cluster re-determine the master server node.

[0111] In order to execute the corresponding steps in the above embodiments and various possible methods, a method for implementing a server cluster master selection device is given below. Figure 7, FIG. 1 is a functional module diagram of a server cluster master node election device provided by an embodiment of the present invention. It should be noted that the basic principle and technical effect of the server cluster master node election device provided by this embodiment are the same as those of the above-mentioned embodiments. For the sake of brief description, for the parts not mentioned in this embodiment, please refer to the corresponding contents in the above-mentioned embodiments. The server cluster master node election device 200 includes: an election request generation module 210, an election request acquisition module 220, a sorting module 230 and a master election module 240, wherein:

[0112] The election request generation module 210 is used to generate a first election request according to the identification information of the server node, and send the first election request to the remaining server nodes in the server cluster.

[0113] The election request acquisition module 220 is used to acquire the second election requests generated by the remaining server nodes in the server cluster; each second election request includes the ballot data and identification information of the corresponding server node.

[0114] The sorting module 230 is used to sort all identification information according to all ballot data to obtain a sorting result.

[0115] The master selection module 240 is used to determine the target identification information according to the sorting result and a preset rule, and determine the server node corresponding to the target identification information as the master server node selected by the server node.

[0116] Furthermore, the election request generation module 210 is specifically used to obtain the current election round of the server node and generate a random number of preset digits; generate ballot data based on the random number and the identification information of the server node; and generate a first election request based on the current election round, the identification information of the server node and the ballot data of the server node.

[0117] Furthermore, the election request generation module 210 is specifically configured to add a random number to the identification information of the server node to generate the ballot data of the server node.

[0118] Furthermore, the sorting module 230 is specifically used to perform reverse processing on each ballot data; convert each ballot data after reverse processing into a preset format; and sort all identification information according to all ballot data converted into the preset format to obtain a sorting result.

[0119] Furthermore, before each ballot data is processed in reverse order, the sorting module 230 is specifically used to determine whether the length of each ballot data exceeds the preset character length; if the length of the ballot data exceeds the preset character length, data with the preset character length is selected from the corresponding ballot data, and the selected data is determined as the new ballot data.

[0120] Furthermore, the server cluster master election device 200 further includes: a master election confirmation module, wherein:

[0121] After the server node corresponding to the target identification information is determined as the main server node selected by this server node, the main selection confirmation module is used to receive the selection result confirmation requests sent by the remaining server nodes; each selection result confirmation request includes the identification information of the main server node selected by the corresponding server node; if the identification information included in each selection result confirmation request is the same as the target identification information, then the master selection is confirmed to be successful.

[0122] Furthermore, the server cluster master selection device 200 further includes: a checking module, wherein:

[0123] The checking module is used to periodically send keep-alive information to the remaining server nodes; receive response information sent by the remaining servers according to the keep-alive information; find out whether there is a server node that has crashed according to the response information; if there is a server node that has crashed, determine whether the server node that has crashed is the main server node selected by this server node; if the server node that has crashed is the main server node selected by this server node, determine the server node corresponding to the next identification information of the target identification information in the sorting result as the main server node newly selected by this server node.

[0124] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.

[0125] In several embodiments provided by the present invention, the coupling between modules may be electrical, mechanical or other forms of coupling.

[0126] In addition, each functional module in each embodiment of the present invention may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of software functional modules.

[0127] Please refer to Figure 8 , is a block diagram of a server node 100 provided in an embodiment of the present invention. The server node 100 includes a memory 110, a processor 120, and a communication module 130. The memory 110, the processor 120, and the communication module 130 are electrically connected to each other directly or indirectly to achieve data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines.

[0128] The memory 110 is used to store programs or data. The memory 110 may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), etc.

[0129] The processor 120 is used to read / write data or programs stored in the memory and execute corresponding functions. For example, when the computer program stored in the memory 110 is executed by the processor 120, the server cluster master election method disclosed in the above embodiments can be implemented.

[0130] The communication module 130 is used to establish communication connections between multiple server nodes 100 through the network, and to send and receive data through the network.

[0131] It should be understood that Figure 8 The structure shown is only a schematic diagram of the server node. The server node may also include Figure 8 More or fewer components may be shown. Figure 8 Each component shown in the figure can be implemented by hardware, software or a combination thereof.

[0132] An embodiment of the present invention further provides a computer-readable storage medium, in which a computer program is stored. When the computer program can be executed by a processor, the server cluster master election method described in the above method embodiment is implemented.

[0133] The computer-readable storage medium may be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read-only memory), an EPROM, a hard disk, or a ROM. Optionally, the computer-readable storage medium includes a non-transitory computer-readable storage medium. The computer-readable storage medium has storage space for program codes that execute any of the method steps in the above method. These program codes can be read from or written to one or more computer program products. The program code can be compressed, for example, in an appropriate form.

[0134] In several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and a module, a program segment or a part of the code contains one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0135] If the function is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.

[0136] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for selecting a master node in a server cluster, characterized in that: Applied to any server node in a server cluster, the method comprises: Generate a first election request according to the identification information of the server node, and send the first election request to the remaining server nodes in the server cluster; Obtaining second election requests generated by the remaining server nodes in the server cluster; each of the second election requests includes vote data and identification information of the corresponding server node; Sorting all the identification information according to all the ballot data to obtain a sorting result; The target identification information is determined according to the sorting result and a preset rule, and the server node corresponding to the target identification information is determined as the main server node selected by the server node.

2. The method according to claim 1, characterized in that The step of generating a first election request according to the identification information of the server node includes: Get the current master election round of this server node and generate a random number with a preset number of digits; Generate ballot data according to the random number and the identification information of the server node; The first election request is generated according to the current master election round, the identification information of the server node and the vote data of the server node.

3. The method according to claim 2, characterized in that The generating of ballot data according to the random number and the identification information of the server node includes: The random number is added to the identification information of the server node to generate the ballot data.

4. The method according to claim 1, characterized in that: The step of sorting all the identification information according to all the ballot data to obtain a sorting result includes: Processing each of the ballot data in reverse order; Convert each of the ballot data after reverse processing into a preset format; All the identification information is sorted according to all the ballot data converted into a preset format to obtain a sorting result.

5. The method according to claim 4, characterized in that Before the reverse processing of each of the ballot data, the method further includes: Determining whether the length of each of the ballot data exceeds a preset character length; If the length of the ballot data exceeds the preset character length, data of the preset character length is selected from the corresponding ballot data, and the selected data is determined as the new ballot data.

6. The method according to claim 1, characterized in that After determining the server node corresponding to the target identification information as the main server node selected by the server node, the method further includes: Receiving the selection result confirmation requests sent by the remaining server nodes; each of the selection result confirmation requests includes identification information of the main server node selected by the corresponding server node; If the identification information included in each of the selection result confirmation requests is the same as the target identification information, it is confirmed that the master selection is successful.

7. The method according to claim 1, characterized in that The method further comprises: Periodically sending keep-alive information to the remaining server nodes; Receiving response information sent by the remaining servers according to the keep-alive information; According to the response information, find out whether there is a downed server node; If there is a downed server node, determine whether the downed server node is the main server node selected by the current server node; If the downed server node is the main server node selected by the current server node, the server node corresponding to the next identification information of the target identification information in the sorting result is determined as the main server node newly selected by the current server node.

8. A server cluster master node election device, characterized in that: Applied to any server node in a server cluster, the device comprises: An election request generating module, configured to generate a first election request according to the identification information of the server node, and send the first election request to the remaining server nodes in the server cluster; An election request acquisition module, used to acquire second election requests generated by the remaining server nodes in the server cluster; each second election request includes vote data and identification information of the corresponding server node; A sorting module, used to sort all the identification information according to all the ballot data to obtain a sorting result; The master selection module is used to determine the target identification information according to the sorting result according to a preset rule, and determine the server node corresponding to the target identification information as the master server node selected by the server node.

9. A server node, characterized in that: It comprises a processor and a memory, wherein the memory stores a computer program executable by the processor, and the computer program executable by the processor is used to implement the server cluster master node election method described in any one of claims 1-7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the server cluster master node election method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Cluster election processing method and device, equipment and storage medium

    CN113014634A

  • Distributed election method, device and system and medium

    CN113760468A

  • Cluster election method and device, equipment and medium

    CN118200328A

  • Node Clustering Configuration

    US20210136146A1