Main node selection method and device in distributed system, electronic equipment and storage medium

By calculating the resource ratio and quantity threshold of each node in the distributed system and selecting the appropriate master node, the problems of insufficient resource utilization and node communication waste in the existing technology are solved, and more efficient resource utilization and system management are achieved.

CN120658739AActive Publication Date: 2025-09-16BEIJING BAIRONG RUIBO TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510951960.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-10
Publication Date
2025-09-16
Estimated Expiration
2045-07-10

AI Technical Summary

Technical Problem

Existing master node election methods in distributed systems may not effectively utilize system resources, and communication between nodes wastes system resources.

Method used

By determining the ratio of the remaining resources and the total resources of each valid node, the nodes with a first ratio higher than a threshold are selected as candidate nodes, and the main node is determined according to the total number and the number threshold, thereby reducing the communication between nodes.

Benefits of technology

It improves the resource utilization efficiency of the master node, saves system resources, and selects the appropriate master node to coordinate and manage the distributed system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120658739A_ABST
    Figure CN120658739A_ABST
Patent Text Reader

Abstract

The invention provides a main node selection method and device in a distributed system, electronic equipment and a storage medium. The method comprises the following steps: executing the following operations on effective nodes in a current distributed system: for each effective node in the current distributed system, determining a first proportion of the residual resource quantity of the effective node to the total resource quantity of the effective node; on the basis of the first proportion of each effective node, alternative nodes are determined from the effective nodes, and the first proportion of the alternative nodes is higher than a proportion threshold value; according to the total number of all the effective nodes and a number threshold value, whether the alternative nodes serve as main nodes or not is determined, when the total number is smaller than or equal to two times of the number threshold value, the alternative nodes serve as the main nodes, and the number threshold value is determined based on the number of divisible parts of the total residual resource quantity of all the effective nodes. According to the scheme, the selected main node can utilize more hardware resources, communication between the nodes is not needed, and system resources are further saved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of distributed computing technology, and in particular to a method for selecting a master node in a distributed system, a master node selection device in a distributed system, an electronic device, a storage medium, and a computer program product. Background Art

[0002] Nodes are the fundamental building blocks of distributed systems, typically independent computers or servers operating within a network. These nodes collaborate to complete tasks, enabling decentralization, parallelization, and fault tolerance. In a distributed system, the master node plays a key role, responsible for coordinating and managing other nodes.

[0003] In some distributed systems, the ZooKeeper Atomic Broadcast (ZAB) protocol is used to elect a master node. This method uses a majority voting mechanism to select the master node and ensures data consistency in the distributed system through transaction log synchronization and atomic broadcast.

[0004] In other distributed systems, a bully algorithm is used to elect a master node. In this algorithm, the master node is elected based on a unique identifier, such as a server ID or priority. A node with a higher identifier value has a higher priority and is more likely to be selected as the master node. In some cases, the node with the highest identifier value is selected as the master node.

[0005] On the one hand, the master node determined by the relevant distributed node election methods may not be the optimal solution, making it difficult to effectively utilize the resources of the distributed system. On the other hand, the execution process of the relevant distributed node election methods requires communication between the nodes in the distributed system, which wastes system resources. Summary of the Invention

[0006] The present invention has been made in view of the above-mentioned problems.

[0007] According to a first aspect of the present invention, a method for selecting a master node in a distributed system is provided. The method comprises: performing the following operations on valid nodes in the current distributed system: for each valid node in the current distributed system, determining a first ratio of the remaining resources of the valid node to the total resources of the valid node; determining an alternative node from the valid nodes based on the first ratio of each valid node, wherein the first ratio of the alternative node is higher than a ratio threshold; determining whether the alternative node is to be used as a master node based on the total number of all valid nodes and a number threshold, wherein when the total number is less than or equal to twice the number threshold, the alternative node is to be used as the master node, wherein the number threshold is determined based on the number of shares that can be divided into the total remaining resources of all valid nodes.

[0008] Exemplarily, determining the first ratio of the remaining resources of the valid node to the total resources of the valid node includes: determining the second ratio of the remaining storage space of the valid node to the total storage space, the third ratio of the remaining running memory to the total running memory and / or the fourth ratio of the remaining number of processor cores to the total number of processor cores; determining the first ratio based on the second ratio, the third ratio and / or the fourth ratio.

[0009] Exemplarily, determining the first ratio based on the second ratio, the third ratio and / or the fourth ratio includes: determining a first weight, a second weight and / or a third weight based on the type of task performed by the distributed system; determining the first ratio based on a first product, a second product and / or a third product, wherein the first product is the product of the second ratio and the first weight, the second product is the product of the third ratio and the second weight, and the third product is the product of the fourth ratio and the third weight.

[0010] Exemplarily, the type is I / O intensive or compute intensive, and the method further includes: when the type is I / O intensive, the first weight is the largest and the third weight is the smallest; when the type is compute intensive, the second weight is the largest and the first weight is the smallest.

[0011] Exemplarily, the method further includes: monitoring the valid nodes in the distributed system in real time; and when the valid nodes change, executing the operation again for the valid nodes in the current distributed system.

[0012] Exemplarily, before executing the operation again, or during executing the operation again and before determining whether the candidate node is the master node, the method further includes: updating the quantity threshold according to the changed valid nodes.

[0013] Exemplarily, the method of determining whether the alternative node serves as the main node based on the total number of all valid nodes and a number threshold also includes: when the total number is greater than twice the number threshold and is not equal to a second value, determining that the alternative node is not the main node and is an invalid node, wherein the second value is the sum of 2 raised to the Nth power and a first value, the first value is twice the number threshold, and N is an integer greater than or equal to 0.

[0014] Exemplarily, the determining whether the alternative node serves as the main node based on the total number of all valid nodes and a number threshold also includes: when the total number is equal to a second value, determining that the alternative node is not the main node and determining that the valid node with the lowest first ratio is an invalid node, wherein the second value is the sum of 2 raised to the Nth power and the first value, the first value is twice the number threshold, and N is an integer greater than or equal to 0.

[0015] Exemplarily, the method also includes: determining the number of divisible shares of the total remaining resources of the distributed system based on the remaining resources of each valid node; for each valid node, determining the fourth product between the first ratio corresponding to the valid node and the number of divisible shares of the total remaining resources; calculating the sum of the fourth products corresponding to each valid node and rounding up the sum to obtain the quantity threshold.

[0016] Exemplarily, the valid node with the highest first ratio is determined as the candidate node.

[0017] Exemplarily, the quantity threshold is a positive integer that is less than or equal to the maximum number of shares that can be divided into which the total remaining resource amount of all valid nodes can be divided.

[0018] According to a second aspect of the present invention, there is also provided a master node selection device in a distributed system, comprising:

[0019] a ratio determination module, configured to determine, for each valid node in the current distributed system, a first ratio of the remaining resources of the valid node to the total resources of the valid node;

[0020] A selection module, configured to determine candidate nodes from the valid nodes based on a first ratio of each valid node, wherein the first ratio of the candidate nodes is higher than a ratio threshold;

[0021] A judgment module is used to determine whether the alternative node is used as the main node based on the total number of all valid nodes and a number threshold, wherein when the total number is less than or equal to twice the number threshold, the alternative node is used as the main node, and the number threshold is determined based on the number of divisible shares of the total remaining resources of all valid nodes.

[0022] According to the third aspect of the present invention, an electronic device is also provided, comprising: a processor and a memory, wherein the memory stores computer program instructions, and the computer program instructions are used by the processor to execute the above-mentioned master node selection method in the distributed system when the processor is running.

[0023] According to a fourth aspect of the present invention, a storage medium is further provided, on which program instructions are stored. The program instructions are used to execute the above-mentioned method for selecting a master node in a distributed system when running.

[0024] According to a fifth aspect of the present invention, a computer program product is further provided, comprising computer program instructions, wherein the computer program instructions are used to execute the above-mentioned method for selecting a master node in a distributed system when running.

[0025] In the above technical solution, for each valid node in the current distributed system, a first ratio of the remaining resources of the valid node to the total resources of the valid node is determined. Then, valid nodes whose first ratio is higher than the ratio threshold are selected as candidate nodes. Finally, based on the total number of all valid nodes and the number threshold, it is determined whether the candidate node should be used as the master node. When the total number is less than or equal to twice the number threshold, the candidate node is selected as the master node. In this way, the resources of the valid nodes themselves can be utilized to select nodes with more available hardware resources from the valid nodes as master nodes. In addition, during the execution of the above master node selection method, the nodes in the distributed system communicate in an unordered manner, saving system resources.

[0026] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are specifically listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] The above and other objects, features, and advantages of the present invention will become more apparent through a more detailed description of the embodiments of the present invention with reference to the accompanying drawings. The accompanying drawings are provided to provide a further understanding of the embodiments of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and are not intended to limit the present invention. In the drawings, the same reference numerals generally represent the same components or steps.

[0028] Figure 1 A schematic flow chart of a method for selecting a master node in a distributed system according to an embodiment of the present invention is shown;

[0029] Figure 2 A schematic flow chart of determining a first ratio between the remaining amount of resources of a valid node and the total amount of resources of the valid node according to one embodiment of the present invention is shown;

[0030] Figure 3 shows a schematic flow chart of determining a first ratio according to one embodiment of the present invention;

[0031] Figure 4 A schematic flow chart of determining a quantity threshold according to an embodiment of the present invention is shown;

[0032] Figure 5 A schematic block diagram showing a master node selection apparatus of a distributed system according to an embodiment of the present invention; and

[0033] Figure 6 A schematic block diagram of an electronic device according to an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0034] In order to make the purpose, technical solutions and advantages of the present invention more apparent, exemplary embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments of the present invention, and it should be understood that the present invention is not limited to the exemplary embodiments described herein. Based on the embodiments of the present invention described in the present invention, all other embodiments obtained by those skilled in the art without creative work should fall within the scope of protection of the present invention.

[0035] In order to at least partially solve the above problems, a method for selecting a master node in a distributed system is proposed. The distributed system may include multiple valid nodes. By having multiple valid node systems work, the computing efficiency, reliability and scalability of the distributed system can be improved. One of the above multiple valid nodes can serve as the master node in the distributed system. The master node is used to coordinate and manage the operation of the entire distributed system. It can assign tasks to each valid node, monitor its status and maintain the overall consistency of the system. According to the method for selecting a master node in a distributed system in an embodiment of the present application, one can be selected from the current valid nodes of the distributed system as the master node to coordinate and manage the operation of the entire distributed system.

[0036] Figure 1 FIG1 shows a schematic flow chart of a method for selecting a master node in a distributed system according to an embodiment of the present invention. Figure 1 As shown, in the master node selection method in the distributed system, an operation is performed on a valid node in the current distributed system, and the operation includes at least steps S110 to S130.

[0037] In step S110 , for each valid node in the current distributed system, a first ratio of the remaining resources of the valid node to the total resources of the valid node is determined.

[0038] In a distributed system, each node can be in a state of shutdown, normal operation, or failure. When a distributed system executes a task, nodes in a normal operation state can cooperate with each other to perform the task. Nodes that are operating normally and can participate in task execution are considered active nodes. Nodes in a shutdown or failure state, however, are not used to execute tasks and are considered inactive nodes.

[0039] Each valid node in a distributed system has its own hardware resources. Hardware resources may include storage space, running memory, number of processor cores, number of data transmission channels, etc. The total amount of these hardware resources may be referred to as the total resource amount. The remaining resource amount is the amount of unused resources in the total resource amount. Taking the total storage space as an example, the remaining resource amount includes the remaining unused storage space. Similarly, the remaining resource amount may also include the remaining running memory, the remaining number of processor cores and / or the remaining number of data channels, etc. It can be understood that the role played by each hardware resource is different based on the different tasks. In order to save computing power, when executing the master node selection method according to the embodiment of the present application, one or more hardware resources in the valid node may be ignored.

[0040] For example, when the total resource amount includes any one of the resource amounts of hardware resources such as total storage space, total running memory, total number of processor cores or total number of data transmission channels, the ratio between the remaining resource amount of the valid node and the total resource amount of the valid node can be used as the first ratio.

[0041] For example, when the total resource amount includes multiple types of hardware resource amounts such as total storage space, total running memory, total number of processor cores, or total number of data transmission channels, for the total resource amount and remaining resource amount of each hardware resource, the ratio between the remaining resource amount and the total resource amount corresponding to the hardware resource can be determined. Then, based on the ratio corresponding to each hardware resource, the first ratio is calculated. For example, the total resource amount of node a includes total storage space b1 and total running memory b2. If the remaining storage space of node a is a1 and the remaining running memory of node a is a2, the first ratios of the remaining storage space and the remaining running memory can be calculated based on a1 / b1 and a2 / b2, respectively. The resource amounts of other types of hardware resources are similar and will not be described in detail here. It is understandable that the remaining resource amounts of different hardware resources may have the same or different effects on the overall performance of the node, so the weight corresponding to each hardware resource can be determined separately, and then the first ratio of each hardware resource can be calculated separately based on the ratio between the remaining resource amount and the total resource amount and the corresponding weight. The weight corresponding to each hardware resource may be a fixed value or may be determined according to the type of task executed by the distributed system.

[0042] In some embodiments, when a distributed system executes a task, the total resource amounts of different active nodes are typically set to be the same or similar. Therefore, the first ratio represents the overall performance of the active nodes for executing the task. The higher the first ratio, the higher the overall performance of the active nodes for executing the task, and vice versa.

[0043] In step S120 , candidate nodes are determined from the valid nodes based on the first proportion of each valid node, wherein the first proportion of the candidate nodes is higher than a proportion threshold.

[0044] The ratio threshold can be fixed, such as 50%, 30%, etc. The ratio threshold can also be determined based on the first ratio of all valid nodes. For example, when the first ratio of all valid nodes ranges from 30% to 50%, the ratio threshold can be a value within the range of 30% to 50% (e.g., 40%, 45%, etc.). The ratio threshold determined based on the first ratio of all valid nodes can more reasonably filter out candidate nodes from the valid nodes.

[0045] Taking the example of considering only storage space as an example of the hardware resources of an effective node, the maximum storage space of different effective nodes can usually be the same, and a portion of the storage space of each effective node can be used. When a distributed system executes a task and does not read or write data existing in the storage space, the remaining storage space is usually used to perform the task. In particular, the master node in a distributed system requires sufficient remaining storage space to coordinate and manage other nodes in the distributed system. The higher the first ratio of an effective node, the stronger its overall performance, and the more suitable it is as a backup node for the master node compared to other effective nodes. The master node can give priority to the backup node.

[0046] Similarly, when the total amount of resources includes hardware resources such as total running memory, total number of processor cores, and / or total number of data transmission channels, the higher the first ratio of the valid node, the stronger the overall performance, and the valid node is more suitable as a candidate node for the master node. When the first ratio of the valid node is higher than the ratio threshold, it means that the valid node has stronger overall performance and is more suitable as a master node. Valid nodes with a first ratio higher than the ratio threshold can be used as candidate nodes to determine whether they can be used as master nodes.

[0047] Exemplarily, one or more valid nodes whose first ratio is higher than a ratio threshold may be randomly selected as candidate nodes.

[0048] Alternatively, the valid node with the highest first ratio may be determined as the candidate node.

[0049] The valid nodes can be sorted according to their first ratio, or the first ratios of the valid nodes can be compared in sequence to determine the valid node with the highest first ratio and higher than the ratio threshold. When there are multiple valid nodes with the highest first ratio and higher than the ratio threshold, all of these valid nodes can be used as candidate nodes, or some nodes (for example, one) can be selected from them as candidate nodes. Among them, some nodes can be randomly selected as candidate nodes, or some nodes can be selected from these valid nodes as candidate nodes based on other information other than the hardware resources of these valid nodes with the highest first ratio, such as the number of valid nodes, startup time and other information. In this way, the number of determined candidate nodes can be reduced, and then the number of determined master nodes can be reduced, preventing the complexity of the master nodes from being over-reduced when cooperating to perform distributed tasks.

[0050] In step S130, whether the alternative node serves as the master node is determined based on the total number of all valid nodes and a quantity threshold, wherein when the total number is less than or equal to twice the quantity threshold, the alternative node is used as the master node, and the quantity threshold is determined based on the number of divisible shares of the total remaining resources of all valid nodes.

[0051] Assume that the goal of each valid node is to maximize its survival goal (also known as benefit, such as becoming a master node or avoiding becoming an invalid node), and based on this, try to allocate as many resources as possible to itself. The aforementioned candidate nodes can provide a resource allocation plan, and in order to become the master node, the candidate nodes will try to maximize the resources allocated to themselves while ensuring that they will not become an invalid node. All valid nodes can choose to support or oppose the proposal. When more than half of the valid nodes support the proposal put forward by the candidate nodes, if the proposal allocates the most resources to the candidate nodes, then the candidate nodes can become the master nodes. However, each valid node may hope to obtain more resources to avoid becoming an invalid node, so they may not necessarily support the resource allocation proposal put forward by the candidate nodes. The candidate nodes will also put forward resource allocation proposals based on this situation.

[0052] If the distributed system includes 5 active nodes, there are a total of 100 remaining resources that can be allocated. The 5 active nodes can include node 1, node 2, node 3, node 4, and node 5, with the first ratio of nodes 1-5 decreasing in descending order. The candidate nodes of the active nodes will propose resource allocation. If the current candidate node cannot make a suitable proposal, it will become an invalid node, and the new candidate node will propose resource allocation, and so on.

[0053] In the above example, suppose nodes 1 through 3 are each unable to submit a suitable proposal as a candidate node and become inactive. This leaves only nodes 4 and 5 as active nodes. If node 4, as a candidate, proposes a resource allocation proposal, node 5 will oppose it, attempting to monopolize all remaining resources. Since node 4 cannot secure a majority vote, it becomes inactive. Now, with node 5 remaining as the only candidate node, its next resource allocation proposal will receive no opposition and a majority vote, making it the primary node.

[0054] Suppose that nodes 1 and 2, each acting as a candidate, are unable to submit a suitable proposal and become inactive. When node 3, acting as a candidate, submits a proposal, node 4 can avoid becoming inactive by supporting node 3's proposal. Knowing this, node 3 proposes a "100, 0, 0" allocation plan, where the "100" represents 100 shares of resources for node 3, and the two "0s" represent 0 shares each for nodes 4 and 5. A node allocated 0 resources does not become inactive. Node 3 knows that node 4, despite not receiving any resources, will still vote in favor. With its own vote, its proposal will pass, preventing itself from becoming inactive. Because node 3 has taken the most resources, it will become the primary node.

[0055] Similarly, if Node 1 has become an invalid node and Node 2 has not become an invalid node, Nodes 2, 3, 4, and 5 are valid nodes. Node 2 can, as a backup node, propose a "98, 0, 1, 1" proposal, which allocates 98 resources to Node 2, 0 resources to Node 3, and 1 resource each to Nodes 4 and 5. Compared to Node 3's resource allocation plan, the plan proposed by Node 2 enables Nodes 4 and 5 to obtain more resources. In other words, the resource allocation plan proposed by Node 2 is more advantageous to Nodes 4 and 5 than the plan proposed by Node 3. Therefore, Nodes 4 and 5 will support Node 2, not wanting Node 2 to fail in the election and not wanting Node 3 to become the master node and allocate resources.

[0056] Based on the above election process, the plan proposed by Node 2 can be the final election plan. Node 2 will take away 98 resources, and because Node 2 takes away more resources than other nodes, Node 2 will become the master node.

[0057] Those skilled in the art will appreciate that the above example uses five active nodes. The analysis process is similar for other instances with different numbers of active nodes. In short, when a candidate node submits its proposal, other active nodes can choose to support or oppose it. Based on this rule, if there are X active nodes and the total remaining resources can be divided into A shares, the following situations may occur after the proposal is made:

[0058] (1) When X≤2A, the maximum system resource utilization of the candidate node in = represents rounding up, X and A are positive integers. The maximum system resource utilization Y represents the additional resources that can be allocated to the candidate node relative to other nodes. In this case, Y can usually be a positive number.

[0059] (2) If X = 2A + 2 N (N is an integer greater than or equal to 0), then in order to avoid becoming an invalid node, the candidate node will set its maximum system resource utilization Y to 0, so as to obtain the support of more than half of the valid nodes and avoid becoming an invalid node.

[0060] (3) When X>2A and X≠2A+2 N When the proposal of the candidate node is not supported by more than half of the nodes.

[0061] The quantity threshold for determining the master node in step S130 can be calculated based on the total remaining resources and the first ratio. The value of the quantity threshold can be an integer or a non-integer. For example, the quantity threshold can be determined based on the product of the total remaining resources and the first ratio. For example, the product can be determined as the quantity threshold. Alternatively, the product can be rounded, and the rounded result can be used as the quantity threshold.

[0062] Exemplarily, the quantity threshold may be a positive integer that is less than or equal to the maximum number of shares that can be divided from the total remaining resources of all valid nodes. It is understood that hardware resources can be divided among different valid nodes for use. However, hardware resources are not infinitely divisible; there is a minimum unit. Once divided to the minimum unit, it cannot be further divided among different valid nodes. Taking the number of processor cores as an example, a single processor core generally cannot be further divided. In other words, the number of processor cores is the maximum fraction into which it can be divided.

[0063] Optionally, the quantity threshold is a larger value within the aforementioned range of possible values. Optionally, the quantity threshold can be further determined based on the total number of currently valid nodes. The larger the total number, the larger the quantity threshold can be; otherwise, the opposite is true. Thus, for the aforementioned example with X valid nodes and A total remaining resources, the quantity threshold T can be equal to the maximum number of shares A into which the total remaining resources can be divided, i.e., T = A.

[0064] Based on the relationship between X and A and the equivalence between A and T, we can determine whether a candidate node can serve as a master node. When X ≤ 2T, the candidate node's maximum system resource utilization, Y, is greater than 0. In this case, the candidate node's proposal will be approved, and the candidate node will be allocated more resources than other valid nodes, with overall performance exceeding that of other valid nodes. Therefore, the candidate node can be designated as a master node. In this case, the candidate node can serve as a master node and resources can be allocated to all valid nodes based on the candidate node's proposal.

[0065] In the above technical solution, for each valid node in the current distributed system, a first ratio of the remaining resources of the valid node to the total resources of the valid node is determined, and then the valid nodes whose first ratio is higher than the ratio threshold are selected as candidate nodes. Finally, based on the total number of all valid nodes and the number threshold, it is determined whether the candidate node is used as the main node, wherein when the total number is less than or equal to twice the number threshold, the candidate node is used as the main node. In this way, the resources of the valid node itself can be utilized to select a node with more available hardware resources from the valid nodes as the main node. In addition, during the execution of the above master node selection method, whether the node can be used as a valid node can be directly determined based on the number threshold and the total number of valid nodes. Therefore, the candidate node does not need to communicate with each node in the distributed system, saving system resources.

[0066] Figure 2 FIG. 1 shows a schematic flow chart of determining a first ratio of the remaining resources of an effective node to the total resources of the effective node according to an embodiment of the present invention. Figure 2 As shown, the above step S110 may include steps S111 to S112.

[0067] In step S111 , a second ratio of the remaining storage space to the total storage space, a third ratio of the remaining running memory to the total running memory, and / or a fourth ratio of the remaining number of processor cores to the total number of processor cores of the valid node is determined.

[0068] The second ratio is the evaluation result of the storage space of the active node, which represents the storage performance of the active node that can be used to execute tasks in the distributed system. The third ratio is the evaluation result of the running memory of the active node, which represents the memory performance of the active node that can be used to execute tasks in the distributed system. The fourth ratio is the evaluation result of the number of processor cores of the active node, which represents the processor performance of the active node that can be used to execute tasks in the distributed system.

[0069] In step S112 , the first ratio is determined according to the second ratio, the third ratio and / or the fourth ratio.

[0070] For example, the determined second ratio, third ratio, and / or fourth ratio may be added together to obtain the first ratio.

[0071] For example, in complex situations, tasks executed by a distributed system may require varying degrees of storage space, RAM, and / or processor core count. Therefore, corresponding weights can be determined for the second, third, and / or fourth ratios. The second, third, and / or fourth ratios are then multiplied by their corresponding weights. The multiplication results are then added together to obtain the first ratio.

[0072] In the above technical solution, the second ratio of the remaining storage space and the total storage space of the effective node, the third ratio of the remaining running memory and the total running memory and / or the fourth ratio of the remaining number of processor cores and the total number of processor cores are determined, and then the first ratio is determined based on the second ratio, the third ratio and / or the fourth ratio. Storage space, running memory and the number of processor cores are very important for nodes to perform tasks. The first ratio determined based on these hardware resources can better reflect the ability of each effective node to participate in the execution of tasks of the distributed system, thereby ensuring that the selected master node is more ideal. In addition, combined with different types of hardware resources, the determined first ratio can better represent the performance of the effective node.

[0073] Figure 3 FIG. 5 shows a schematic flow chart of determining a first ratio according to an embodiment of the present invention. Figure 3 As shown, the above step S112 may include steps S112a to S112b.

[0074] In step S112a, a first weight, a second weight and / or a third weight are determined according to the type of task executed by the distributed system.

[0075] Distributed systems perform a variety of tasks, such as compute-intensive, I / O-intensive, and storage-intensive. These tasks may require different hardware resources from active nodes, including storage space, RAM, and processor core counts. The type of task a distributed system performs can be used to determine the hardware resource requirements for each task.

[0076] The first weight represents the degree to which the task requires storage space on the active node. The second weight represents the degree to which the task requires runtime memory on the active node. The third weight represents the degree to which the task requires processors on the active node.

[0077] Optionally, specific values ​​of the first weight, the second weight, and the third weight are set according to experience, and the sum of the first weight, the second weight, and the third weight may be equal to 1.

[0078] Optionally, the specific values ​​of the first weight, the second weight and the third weight are pre-set according to experience, and the sum of the first weight, the second weight and the third weight can be equal to a preset value. Among them, the preset value can be determined based on the proportion of hardware resources such as storage space, running memory and the number of processor cores in the hardware resources of the effective node. For example, when the hardware resources of the effective node also include the number of data channels, if the proportion of hardware resources such as storage space, running memory and the number of processor cores in the hardware resources of the effective node is 80%, then the sum of the first weight, the second weight and the third weight can be 80%. When the proportion of hardware resources such as storage space, running memory and the number of processor cores in the hardware resources of the effective node is other values, the same applies and will not be described in detail here. Among them, the proportion of hardware resources such as storage space, running memory and the number of processor cores in the hardware resources of the effective node can be a fixed value, or it can be determined according to the type of task performed by the distributed system.

[0079] Exemplarily, when the type of task executed by the distributed system is I / O intensive, the first weight is the largest and the third weight is the smallest.

[0080] When a distributed system performs I / O-intensive tasks, among the hardware resources such as storage space, running memory, and number of processor cores of the effective nodes, the demand for storage space is the greatest, while the demand for the number of processor cores is the least. Therefore, when the type of task performed by the distributed system is I / O-intensive, the first weight can be set to the maximum and the third weight to the minimum. This increases the impact of storage space on the first ratio and reduces the impact of the number of processor cores on the first ratio. For example, when the type of task performed by the distributed system is I / O-intensive, the first weight can be 50%, the second weight can be 30%, and the third weight can be 20%.

[0081] Exemplarily, when the type of task executed by the distributed system is computationally intensive, the second weight is the largest and the first weight is the smallest.

[0082] When a distributed system executes compute-intensive tasks, among hardware resources such as storage space, RAM, and the number of processor cores on active nodes, RAM is most in demand, while storage is least in demand. Therefore, for compute-intensive tasks, the first weight can be set to the minimum and the second weight to the maximum. This increases the impact of RAM on the first ratio and reduces the impact of storage on the first ratio.

[0083] For example, when the type of task executed by the distributed system is computationally intensive, the first weight may be 20%, the second weight may be 50%, and the third weight may be 30%.

[0084] In step S112b, a first ratio is determined based on the first product, the second product and / or the third product, wherein the first product is the product of the second ratio and the first weight, the second product is the product of the third ratio and the second weight, and the third product is the product of the fourth ratio and the third weight.

[0085] When the hardware resources to be considered include only one of the storage space, running memory, and number of processor cores of an effective node, the corresponding first product, second product, or third product can be used as the first ratio. When the hardware resources to be considered include multiple types of the storage space, running memory, and number of processor cores of an effective node, multiple corresponding first products, second products, and / or third products can be added together to obtain the first ratio.

[0086] For example, when the hardware resources to be considered include storage space, running memory, and number of processor cores of an effective node, the first proportion P corresponding to the effective node can be determined according to the following formula 1:

[0087] P=K1*C+ K2*E+ K3*F Formula 1

[0088] Among them, K1 represents the first weight, K2 represents the second weight, K3 represents the third weight, C represents the second ratio, E represents the third ratio, and F represents the fourth ratio.

[0089] In another example, when the hardware resources to be considered include any two of the storage space, running memory, and number of processor cores of the valid node, the first proportion P corresponding to the valid node can be determined according to the following formula 2:

[0090] P=K1*C+ K2*E Formula 2

[0091] Here, K1 represents one of the first, second, and third weights, K2 represents the other of the first, second, and third weights, C represents one of the second, third, and fourth ratios, and E represents the other of the second, third, and fourth ratios. K1 and C correspond to the same type of hardware resources, K2 and E correspond to the same type of hardware resources, and K1 and K2 correspond to different types of hardware resources. For example, when the hardware resources to be considered include storage space and runtime memory of valid nodes, in the above formula 2, K1 can represent the first weight, K2 can represent the second weight, C can represent the second ratio, and E can represent the third ratio.

[0092] In the above technical solution, the first weight, the second weight and / or the third weight are determined according to the type of task performed by the distributed system, and then the first ratio is determined according to the first product, the second product and / or the third product, wherein the first product is the product of the second ratio and the first weight, the second product is the product of the third ratio and the second weight, and the third product is the product of the fourth ratio and the third weight. In this way, the required resources and the first ratio of the required resources that are more suitable for the task type can be determined in combination with the tasks performed by the distributed system. Furthermore, it can be ensured that the master node selected based on the first ratio is more suitable for the task type.

[0093] Figure 4 FIG. 5 shows a schematic flow chart of determining a quantity threshold according to an embodiment of the present invention. Figure 4 As shown, the master node selection method in the distributed system may further include steps S130a to S130c for determining a quantity threshold.

[0094] In step S130a, the number of shares into which the total remaining resources of the distributed system can be divided is determined based on the remaining resources of each valid node.

[0095] The remaining resources of the same type of each valid node can be added together to determine the total available resources of each type of hardware resource. For example, the remaining storage space of each valid node can be added together to obtain the available storage space. For another example, the remaining running memory of the valid nodes can be added together to obtain the total available running memory. Similarly, for other types of hardware resources of valid nodes, the total available resources of that type of hardware resources are also determined. The total available resources of each type can then be divided into M parts, and one part of the total available resources of all types is added to one part of the total remaining resources to determine the total remaining resources, that is, the total remaining resources can be divided into M parts, and each part of the resources contains one part of the total available resources of all types. For example, for storage space and running memory, the storage space and running memory are divided into 10 parts respectively, each part of storage space is 10kb, and each part of running memory is 1kb, then each part of the resources can contain 10kb of storage space and 1kb of running memory.

[0096] In step S130b, for each valid node, a fourth product of the first proportion corresponding to the valid node and the number of divisible shares of the total remaining resource amount is determined.

[0097] The fourth product represents the amount of resources that can be allocated to the active node in the distributed system. The higher the fourth product, the more resources can be allocated to the active node. The lower the fourth product, the fewer resources can be allocated to the active node.

[0098] In step S130c, the sum of the fourth products corresponding to each valid node is calculated and rounded up to obtain a quantity threshold.

[0099] The quantity threshold, determined by summing the fourth product of all valid nodes, represents the combined remaining resource requirements of all currently valid nodes, i.e., the number of shares into which they are divided. The resource quantity corresponding to each share of the remaining resources can be set based on the tasks being performed by the distributed system. While ensuring that each valid node can be allocated a certain amount of resources, each share of the remaining resources can contain a specified amount of hardware resources. This determined quantity threshold generally ensures that each valid node can be allocated a certain amount of hardware resources, thereby ensuring that each valid node can successfully perform the tasks of the distributed system and does not become an inactive node.

[0100] In the above technical solution, the number of shares that can be divided into the total remaining resources is determined based on the remaining resources of each valid node, and then for each valid node, the fourth product between the first ratio corresponding to the valid node and the number of shares that can be divided into the total remaining resources is determined, and then the sum of the fourth products corresponding to each valid node is calculated and the sum is rounded up to obtain the quantity threshold. The quantity threshold is obtained by summing the fourth products corresponding to each valid node and rounding up the sum. The twice of the quantity threshold determined in this way must be greater than or equal to twice the total number of valid nodes. Therefore, according to the quantity threshold, it can be guaranteed that the valid node with the most remaining resources can be selected as the master node. And after the candidate node is determined to be the master node, each valid node will not be allocated less than one share of hardware resources due to the proposal of the master node, and can be allocated part of the hardware resources. The resource allocation scheme of the master node is more reasonable.

[0101] Optionally, the method for selecting a master node in a distributed system according to some embodiments of the present application may further include step S140 and step S150.

[0102] In step S140, valid nodes in the distributed system are monitored in real time.

[0103] Optionally, each valid node in the distributed system can periodically send a heartbeat signal to its monitoring center. The monitoring center can receive and record the heartbeat signal. If there is a valid node whose heartbeat signal is not received after a timeout, it means that the valid node has become a failed node. It can be understood that a failed node does not participate in the execution of tasks of the distributed system. A failed node can be a node that is in a faulty state or in a closed state. A failed node can also be a node that is in a normal operating state but does not participate in the execution of tasks of the distributed system. When a node becomes a failed node, it means that the valid nodes are reduced. When a heartbeat signal is received from a new node, it means that the valid nodes are increased. In this way, the valid nodes in the distributed system can be monitored in real time.

[0104] Optionally, the monitoring center can periodically send health check requests to the nodes. When the nodes return status information, the monitoring center can use this information to determine whether the nodes are valid and which nodes are considered valid. This allows for real-time monitoring of valid nodes in a distributed system.

[0105] Optionally, the valid nodes can send operation logs to a centralized log system, and then tools (such as ELK Stack) can be used to analyze the operation logs to determine whether the valid nodes in the distributed system have changed.

[0106] Other methods besides the above methods may also be used to monitor the valid nodes in the distributed system in real time, which is not limited here.

[0107] In step S150, when the valid nodes change, the above operations are performed again for the valid nodes in the current distributed system.

[0108] The change in the valid nodes may include a change in the number of valid nodes, a change in the remaining resources of the valid nodes, a change in the number of shares that can be divided into the total resources of the valid nodes, etc. After the valid nodes have changed, the currently determined master node may not be the most suitable master node. The operations in steps S110 to S130 above may be performed again to select the most suitable node from the current valid nodes as the master node.

[0109] For example, when the number of valid nodes increases, the performance of the increased valid nodes may be higher than the performance of the currently determined master node. Therefore, when the number of valid nodes increases, the operations in steps S110 to S130 above can be performed again based on the current valid nodes, that is, the master node can be re-determined.

[0110] Similarly, when the number of valid nodes decreases, the reduced number of valid nodes will affect the overall performance of the distributed system. In particular, when the reduced node is a master node, according to some embodiments of the present application, a new master node can be selected in a timely manner. Therefore, when the number of valid nodes decreases, the operations in steps S110 to S130 above can be performed again based on the current valid nodes, that is, the master node can be re-determined.

[0111] The same applies when the remaining resources of the valid node change, the number of shares that can be divided into the total resources of the valid node changes, or other changes occur in the valid node, which will not be detailed here.

[0112] In the above technical solution, the active nodes in the distributed system are monitored in real time. When the active nodes change, the above operation is performed again for the active nodes in the current distributed system. In this way, when the active nodes change, the appropriate master node can be re-selected in a timely manner, effectively utilizing system resources.

[0113] For example, when the task executed by the distributed system changes, the above operation may be performed again for the valid nodes in the current distributed system, and a master node that is more suitable for the current task may be selected from the valid nodes.

[0114] Exemplarily, before executing the operation again, or in the process of executing the operation again and before determining whether the candidate node is the master node, the method further includes step S160: updating the quantity threshold according to the changed valid nodes.

[0115] During the real-time monitoring of active nodes in a distributed system, the number of active nodes may change. According to some embodiments of the present application, different total numbers of active nodes may correspond to different quantity thresholds. The corresponding quantity threshold may be determined based on the total number of active nodes after an increase or decrease, to accommodate situations with different total numbers of active nodes. For example, as the total number of active nodes increases, the quantity threshold may be increased, and vice versa.

[0116] For changed valid nodes, the total remaining resources and remaining resources corresponding to the valid nodes may change. The quantity threshold and the first ratio of each valid node can be updated synchronously based on the total remaining resources and remaining resources corresponding to the valid nodes. For example, when the number of shares that can be divided into shares for the total resources corresponding to the valid nodes increases, the quantity threshold can be increased accordingly, and vice versa.

[0117] It can be understood that by updating the quantity threshold, the rationality of the master node selection can be guaranteed when the valid nodes change.

[0118] Then, as described above, in the above steps 110 to S130, candidate nodes are first determined according to the first ratio, and then when the total number of valid nodes is less than or equal to twice the number threshold, the candidate nodes are used as master nodes.

[0119] For example, when the total number of valid nodes is greater than twice the number threshold, it is determined that the master node selection has failed and an alarm signal is output. When the user receives the alarm signal, he or she can adjust the number threshold to perform step S130 again to select the master node.

[0120] Alternatively, when the total number of valid nodes is greater than twice the quantity threshold, it is determined that the master node selection has failed, and the quantity threshold can be automatically adjusted in a certain step size to execute step S130 again to select the master node. By way of example, the step size can be fixed, or it can be determined based on the quantity threshold, or it can be determined based on the total number of current valid nodes. For example, each time it is determined that the master node selection has failed, the current quantity threshold can be reduced by a fixed value such as 1, 5, or 10. For another example, each time it is determined that the master node selection has failed, the quantity threshold can be reduced in proportion, where the proportion can be 1 / 2, 1 / 3, etc. By way of example, after determining that the master node selection has failed, the quantity threshold can be adjusted, where the adjusted quantity threshold is not less than half of the total number of current valid nodes.

[0121] Illustratively, step S130 may further include step S131: when the total number is greater than twice the number threshold and is not equal to a second value, determining that the candidate node is not the primary node and is an invalid node. The second value is the sum of 2 raised to the Nth power and the first value, the first value is twice the number threshold, and N is an integer greater than or equal to 0.

[0122] According to the above description of the total number of valid nodes and the number threshold, when the total number of valid nodes is greater than twice the number threshold and is not equal to the second value, that is, when X>2A and X≠2A+2 N When the candidate node's proposal cannot be supported by more than half of the nodes, the candidate node can be determined as an invalid node.

[0123] It is understandable that when it is determined that the candidate node is not the master node and is an invalid node, the valid nodes will be reduced. At this time, the processing process of steps S140 to S150 can be performed to try to determine the master node again from the current valid nodes.

[0124] In the above technical solution, when the total number of valid nodes is greater than twice the threshold number and not equal to the second value, the candidate node is directly determined to be an invalid node, and then the master node is re-determined based on the reduced number of valid nodes. This further ensures that the selected master node can utilize more hardware resources and is a more ideal master node.

[0125] Exemplarily, the above-mentioned step S130 may further include step S132: when the total number is equal to a second value, determining that the alternative node is not the main node and determining that the valid node with the lowest first ratio is an invalid node, wherein the second value is the sum of 2 raised to the Nth power and the first value, the first value is 2 times the quantity threshold, and N is an integer greater than or equal to 0.

[0126] According to the above description of the total number of valid nodes and the number threshold, when the total number is equal to the second value, that is, when X=2A+2N When a candidate node's proposal receives support from more than half of the active nodes, its maximum system resource utilization Y is 0, making it unsuitable for primary status. For example, in a distributed system with three active nodes, c1, c2, and c3, if the number threshold is 1 and c1 is a candidate node, to secure support from more than half of the active nodes, c1 can propose a "0,1,0" solution. In this solution, c1 and c3 receive 0 resources, while c2 receives 1 hardware resource. In this case, although c1's solution receives support from c2 and c3, it receives no additional resources compared to c2 and c3, making it unsuitable for primary status. To prevent c1 from being designated as a candidate node again, c1 can be declared an invalid node.

[0127] When it is determined that the candidate node is not the master node and is an invalid node, and the valid nodes are reduced, the processing process of the above steps S140 to S150 can be executed to try to determine the master node again from the current valid nodes.

[0128] In the above technical solution, when the total number of valid nodes equals the second value, the candidate node is determined to be not an invalid node, and the valid node with the lowest first ratio is eliminated. Then, the master node is re-determined based on the reduced number of valid nodes. This further ensures that the selected master node can utilize more hardware resources and is a more ideal master node.

[0129] Figure 5 FIG. 1 shows a schematic block diagram of a master node selection device for a distributed system according to an embodiment of the present invention. Figure 5 As shown, the master node selection device of the distributed system includes a ratio determination module 510 , a selection module 520 , and a judgment module 530 .

[0130] The ratio determination module 510 is configured to determine, for each valid node in the current distributed system, a first ratio of the remaining resources of the valid node to the total resources of the valid node.

[0131] The selection module 520 is configured to determine candidate nodes from the valid nodes based on the first ratio of each valid node being the highest, wherein the first ratio of the candidate nodes is higher than a ratio threshold.

[0132] The judgment module 530 is used to determine whether the alternative node is used as the main node based on the total number of all valid nodes and the number threshold, wherein when the total number is less than or equal to twice the number threshold, the alternative node is used as the main node, and the number threshold is determined based on a positive integer of the maximum number of divisible shares that is less than or equal to the total remaining resource amount of all valid nodes.

[0133] Exemplarily, the ratio determination module 510 may include a first determination submodule and a second determination submodule. The first determination submodule is configured to determine a second ratio of the remaining storage space to the total storage space, a third ratio of the remaining running memory to the total running memory, and / or a fourth ratio of the remaining number of processor cores to the total number of processor cores of the active node. The second determination submodule is configured to determine the first ratio based on the second ratio, the third ratio, and / or the fourth ratio.

[0134] Exemplarily, the second determination submodule includes a weight determination submodule and a third determination submodule. The weight determination submodule is configured to determine a first weight, a second weight, and / or a third weight based on the type of task executed by the distributed system. The third determination submodule is configured to determine a first ratio based on the first product, the second product, and / or the third product, wherein the first product is the product of the second ratio and the first weight, the second product is the product of the third ratio and the second weight, and the third product is the product of the fourth ratio and the third weight.

[0135] For example, the type is I / O intensive or computation intensive. When the type is I / O intensive, the first weight is the largest and the third weight is the smallest; when the type is computation intensive, the second weight is the largest and the first weight is the smallest.

[0136] Exemplarily, the master node selection apparatus in the distributed system further includes a monitoring module. The monitoring module is configured to monitor the active nodes in the distributed system in real time. The ratio determination module 510, the selection module 520, and the judgment module 530 are further configured to perform respective operations on the active nodes in the current distributed system when the active nodes change.

[0137] Exemplarily, the master node selection apparatus in the distributed system further includes an updating module configured to update the quantity threshold according to the changed valid nodes before re-performing the operation or during re-performing the operation and before determining whether the candidate node is the master node.

[0138] Illustratively, the judgment module 530 may further include a first judgment submodule. The first judgment submodule is configured to determine that the candidate node is not a primary node and is an invalid node when the total number is greater than twice a number threshold and is not equal to a second value, where the second value is the sum of 2 raised to the Nth power and the first value, the first value is twice the number threshold, and N is an integer greater than or equal to 0.

[0139] Illustratively, the judgment module 530 may further include a second judgment submodule. The second judgment submodule is configured to, when the total number is equal to a second value, determine that the candidate node is not the primary node and determine that the valid node with the lowest first ratio is an invalid node, wherein the second value is the sum of 2 raised to the Nth power and the first value, the first value is twice the number threshold, and N is an integer greater than or equal to 0.

[0140] Exemplarily, the master node selection device in the above-mentioned distributed system further includes a resource statistics submodule, a resource conversion calculation submodule, and a numerical value generation submodule. The resource statistics submodule is configured to determine the number of divisible shares of the total remaining resource amount of the distributed system based on the remaining resource amount of each valid node. The resource conversion calculation submodule is configured to determine, for each valid node, a fourth product between the first ratio corresponding to the valid node and the number of divisible shares of the total remaining resource amount. The numerical value generation submodule is configured to calculate the sum of the fourth products corresponding to each valid node and round the sum upward to obtain a quantity threshold.

[0141] Exemplarily, the selection module 520 includes a screening submodule configured to determine the valid node with the highest first ratio as the candidate node.

[0142] Exemplarily, the quantity threshold is a positive integer that is less than or equal to the maximum number of shares that can be divided into which the total remaining resource amount of all valid nodes can be divided.

[0143] According to another aspect of the present invention, an electronic device is provided. Figure 6 FIG. 1 shows a schematic block diagram of an electronic device according to an embodiment of the present invention. Figure 6 As shown, the electronic device includes a processor and a memory, wherein the memory stores computer program instructions, and the computer program instructions are used by the processor to execute the master node selection method in the distributed system as described above when the processor is running.

[0144] In addition, according to another aspect of the present invention, a storage medium is also provided, on which program instructions are stored, and when the program instructions are executed by a computer or processor, the computer or processor is caused to perform the corresponding steps of the master node selection method in the above-mentioned distributed system according to an embodiment of the present invention, and is used to implement the corresponding modules in the master node selection device in the above-mentioned distributed system according to an embodiment of the present invention. The storage medium may, for example, include a storage component of a tablet computer, a hard disk of a personal computer, a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a portable compact disk read-only memory (CD-ROM), a USB memory, or any combination of the above storage media. The computer-readable storage medium may be any combination of one or more computer-readable storage media.

[0145] According to another aspect of the present invention, a computer program product is provided, comprising computer program instructions, wherein the computer program instructions are used to execute the above-mentioned method for selecting a master node in a distributed system when running.

[0146] A person skilled in the art can understand the specific implementation and beneficial effects of the master node selection device, electronic device, storage medium and computer program product in the above-mentioned distributed system by reading the above-mentioned detailed description of the master node selection method in the distributed system. For the sake of brevity, they will not go into details here.

[0147] Although example embodiments have been described herein with reference to the accompanying drawings, it should be understood that the above example embodiments are merely illustrative and are not intended to limit the scope of the present invention. Various changes and modifications may be made therein by those skilled in the art without departing from the scope and spirit of the present invention. All such changes and modifications are intended to be included within the scope of the present invention as claimed in the appended claims.

[0148] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present invention.

[0149] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units described is merely a logical function division. In actual implementation, other division methods may be used, such as combining or integrating multiple units or components into another device, or ignoring or not performing some features.

[0150] In the description provided herein, numerous specific details are described. However, it is understood that embodiments of the present invention may be practiced without these specific details. In some instances, well-known methods, structures, and techniques are not shown in detail so as not to obscure the understanding of this description.

[0151] Similarly, it should be understood that in order to streamline the present invention and aid in understanding one or more of the various inventive aspects, in the description of exemplary embodiments of the present invention, the various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, this approach to the present invention should not be interpreted as reflecting the intention that the claimed invention requires more features than those explicitly recited in each claim. More precisely, as reflected in the corresponding claims, the inventive point is that the corresponding technical problem can be solved with fewer features than all the features of a single disclosed embodiment. Therefore, the claims following the detailed description are hereby expressly incorporated into the detailed description, with each claim itself serving as a separate embodiment of the present invention.

[0152] It will be understood by those skilled in the art that, except where mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstract, and drawings) and all processes or units of any method or apparatus disclosed herein may be combined in any combination. Unless expressly stated otherwise, each feature disclosed in this specification (including the accompanying claims, abstract, and drawings) may be replaced by an alternative feature providing the same, equivalent, or similar purpose.

[0153] Furthermore, those skilled in the art will appreciate that although some embodiments described herein include certain features included in other embodiments but not other features, combinations of features from different embodiments are intended to be within the scope of the present invention and to form different embodiments. For example, in the claims, any of the claimed embodiments may be used in any combination.

[0154] The various component embodiments of the present invention can be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It should be understood by those skilled in the art that a microprocessor or a digital signal processor (DSP) can be used in practice to implement some or all of the functions of some modules in the master node selection device in the distributed system according to an embodiment of the present invention. The present invention can also be implemented as a device program (e.g., a computer program and a computer program product) for executing part or all of the methods described herein. Such a program for implementing the present invention can be stored on a computer-readable medium, or can have the form of one or more signals. Such a signal can be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.

[0155] It should be noted that the above embodiments illustrate rather than limit the invention, and that those skilled in the art may devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between brackets should not be construed as limiting the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present invention may be implemented by means of hardware comprising several different elements and by means of appropriately programmed computers. In a unit claim enumerating several means, several of these means may be embodied by the same item of hardware. The use of the words first, second, and third etc. does not indicate any order. These words may be interpreted as names.

[0156] The foregoing description is merely a specific embodiment of the present invention or an illustration of a specific embodiment. The scope of protection of the present invention is not limited thereto. Any modifications or substitutions that can be readily conceived by a person skilled in the art within the technical scope disclosed in the present invention are intended to be encompassed by the scope of protection of the present invention. The scope of protection of the present invention shall be subject to the scope of protection of the claims.

Claims

1. A method for selecting a master node in a distributed system, characterized in that: The method comprises: performing the following operations on a valid node in the current distributed system: For each valid node in the current distributed system, determining a first ratio of a remaining amount of resources of the valid node to a total amount of resources of the valid node; Determining candidate nodes from the valid nodes based on a first ratio of each valid node, wherein the first ratio of the candidate nodes is higher than a ratio threshold; Determine whether the candidate node serves as the master node based on the total number of all valid nodes and a quantity threshold, wherein when the total number is less than or equal to twice the quantity threshold, the candidate node is used as the master node, and the quantity threshold is determined based on the number of divisible shares of the total remaining resources of all valid nodes.

2. The method according to claim 1, characterized in that The determining of a first ratio between the remaining amount of resources of the valid node and the total amount of resources of the valid node includes: Determining a second ratio of the remaining storage space to the total storage space, a third ratio of the remaining running memory to the total running memory, and / or a fourth ratio of the remaining number of processor cores to the total number of processor cores of the valid node; The first ratio is determined according to the second ratio, the third ratio and / or the fourth ratio.

3. The method according to claim 2, characterized in that Determining the first ratio according to the second ratio, the third ratio and / or the fourth ratio includes: Determining a first weight, a second weight, and / or a third weight according to a type of task performed by the distributed system; The first ratio is determined based on a first product, a second product and / or a third product, wherein the first product is the product of the second ratio and the first weight, the second product is the product of the third ratio and the second weight, and the third product is the product of the fourth ratio and the third weight.

4. The method according to claim 3, characterized in that The type is I / O intensive or computation intensive, and the method further comprises: When the type is the I / O intensive type, the first weight is the largest and the third weight is the smallest; When the type is the computationally intensive type, the second weight is the largest and the first weight is the smallest.

5. The method according to any one of claims 1 to 4, characterized in that The method further comprises: Real-time monitoring of valid nodes in distributed systems; When the valid nodes change, the operation is performed again for the valid nodes in the current distributed system.

6. The method according to claim 5, characterized in that Before executing the operation again, or during executing the operation again and before determining whether the candidate node is the master node, the method further includes: The quantity threshold is updated according to the changed valid nodes.

7. The method according to claim 5, characterized in that The determining, based on the total number of all valid nodes and the number threshold, whether the candidate node serves as the master node further includes: When the total number is greater than twice the number threshold and is not equal to a second value, it is determined that the alternative node is not a master node and is an invalid node, wherein the second value is the sum of 2 to the Nth power and a first value, the first value is twice the number threshold, and N is an integer greater than or equal to 0.

8. The method according to claim 5, characterized in that The determining, based on the total number of all valid nodes and the number threshold, whether the candidate node serves as the master node further includes: When the total number is equal to a second value, it is determined that the alternative node is not the main node and the valid node with the lowest first ratio is determined to be an invalid node, wherein the second value is the sum of 2 to the Nth power and the first value, the first value is 2 times the number threshold, and N is an integer greater than or equal to 0.

9. The method according to claim 1, characterized in that The method further comprises: Determining the number of shares into which the total remaining resources of the distributed system can be divided according to the remaining resources of each valid node; For each valid node, determining a fourth product of the first ratio corresponding to the valid node and the number of shares into which the total remaining resource amount can be divided; The sum of the fourth products corresponding to each valid node is calculated and rounded up to obtain the quantity threshold.

10. The method according to claim 1, characterized in that The quantity threshold is a positive integer that is less than or equal to the maximum number of shares that can be divided into which the total remaining resource amount of all valid nodes can be divided.

11. A master node selection device in a distributed system, characterized in that: include: a ratio determination module, configured to determine, for each valid node in the current distributed system, a first ratio of the remaining resources of the valid node to the total resources of the valid node; A selection module, configured to select the valid node with the highest first ratio as a candidate node; A judgment module is used to determine whether the alternative node is used as the main node based on the total number of all valid nodes and a number threshold, wherein when the total number is less than or equal to twice the number threshold, the alternative node is used as the main node, and the number threshold is a positive integer that is less than or equal to the maximum number of shares that can be divided into the total remaining resources of all valid nodes.

12. An electronic device comprising a processor and a memory, characterized in that: The memory stores computer program instructions, which are used by the processor to execute the method for selecting a master node in a distributed system according to any one of claims 1 to 10 when the processor is running the computer program instructions.

13. A storage medium having program instructions stored thereon, characterized in that: The program instructions are used to execute the master node selection method in a distributed system according to any one of claims 1 to 10 when running.

14. A computer program product comprising computer program instructions, characterized in that The computer program instructions are used to execute the master node selection method in a distributed system according to any one of claims 1 to 10 when running.

Citation Information

Patent Citations

  • Server cluster system and load balancing implementation method thereof

    CN104283948A

  • Cloud computing resource scheduling method and device, electronic equipment and storage medium

    CN117499493A

  • Container scheduling method and device, electronic equipment and computer readable medium

    CN117742875A

  • Multi-node network master node selection method and device, equipment and storage medium

    CN118200123A

  • Resource management system and resource management method

    US20220141140A1