Main node switching method and device, equipment, storage medium and program product
By determining the weight value based on node information and switching candidate nodes in the ZooKeeper cluster, the problem of inflexible master node switching in the cluster is solved, the stability and reliability of the cluster are improved, and all nodes have the opportunity to serve as the master node.
Patent Information
- Application Number
- CN202410624651.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-17
- Publication Date
- 2024-09-17
AI Technical Summary
After the existing ZooKeeper cluster runs smoothly, the master node can only switch back and forth between the two nodes with the largest myid value, resulting in reduced cluster stability and reliability. It cannot effectively prevent the cluster from always being served by a very small number of nodes as the master node. situation.
By determining the weight value of each node based on the cluster node information, selecting nodes that meet the weight conditions as candidate nodes, and switching them to the master node when a node switch is requested, ensuring that the weight value changes after the switch, and avoiding the long-term use of only a few nodes. Act as the master node.
It improves the stability and reliability of the cluster, ensures that all nodes except a very small number of nodes have the opportunity to serve as the master node, and avoids operational risks when a node that has not served as the master node for a long time suddenly becomes the master node under special circumstances.
Smart Images

Figure CN118656171A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a master node switching method, device, equipment, storage medium and program product. Background Art
[0002] With the rapid development of computer technology, more and more clusters use the master-slave mode to deploy servers, such as ZooKeeper clusters. Usually, clusters cannot avoid the problem of master node switching during the operation of the master-slave mode.
[0003] However, most current node switching methods allow the master node to switch back and forth between only a few nodes. For example, in a ZooKeeper cluster, the master node is determined in the order of the node's Epoch value, transaction id value, and myid value. After the ZooKeeper cluster runs smoothly, if there is no large network or data synchronization delay, the master node may only be able to switch back and forth between the two nodes with the largest myid values, and cannot switch to other nodes. Obviously, this situation will reduce the stability and reliability of the cluster. Summary of the invention
[0004] Based on this, it is necessary to provide a master node switching method, device, computer equipment, computer-readable storage medium and computer program product that can improve the stability and reliability of the cluster in response to the above technical problems.
[0005] In a first aspect, the present application provides a master node switching method. The method comprises:
[0006] Based on the node information of the nodes in the cluster, determine the weight value of each node;
[0007] The first node corresponding to the weight value that meets the weight condition is taken as a candidate node;
[0008] In response to the node switching request, the candidate node is switched to be the master node of the first cycle.
[0009] In a second aspect, the present application also provides a master node switching device. The device comprises:
[0010] A first determination module, used to determine a weight value of each node based on node information of the nodes in the cluster;
[0011] A second determination module, configured to select a first node corresponding to a weight value satisfying the weight condition as a candidate node;
[0012] The switching module is used to switch the candidate node to the master node of the first cycle in response to the node switching request.
[0013] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0014] Based on the node information of the nodes in the cluster, determine the weight value of each node;
[0015] The first node corresponding to the weight value that meets the weight condition is taken as a candidate node;
[0016] In response to the node switching request, the candidate node is switched to be the master node of the first cycle.
[0017] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0018] Based on the node information of the nodes in the cluster, determine the weight value of each node;
[0019] The first node corresponding to the weight value that meets the weight condition is taken as a candidate node;
[0020] In response to the node switching request, the candidate node is switched to be the master node of the first cycle.
[0021] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0022] Based on the node information of the nodes in the cluster, determine the weight value of each node;
[0023] The first node corresponding to the weight value that meets the weight condition is taken as a candidate node;
[0024] In response to the node switching request, the candidate node is switched to be the master node of the first cycle.
[0025] The above-mentioned master node switching method, device, computer equipment, storage medium and computer program product determine the weight value of each node based on the node information of the nodes in the cluster. Since the node information of each node is different, the weight value of each node is also different. The first node corresponding to the weight value that meets the weight condition is used as a candidate node. When responding to a node switching request, the candidate node is switched to the master node of the first cycle, so that the node corresponding to the weight value that meets the weight condition can serve as the master node of the next cycle, thereby serving as the master node of the next cycle. In subsequent cycles, changes in node information will also cause changes in weight values, thereby avoiding the situation where only one of two nodes in the cluster can always serve as the master node, thereby improving the stability and reliability of the cluster. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] FIG1 is an application environment diagram of a master node switching method in one embodiment;
[0027] FIG2 is a schematic diagram of a process flow of a master node switching method in one embodiment;
[0028] FIG3 is an application environment diagram of a master node switching method in another embodiment;
[0029] FIG4 is a structural block diagram of a master node switching device in one embodiment;
[0030] FIG5 is a structural block diagram of a master node switching device in another embodiment;
[0031] FIG6 is a diagram showing the internal structure of a computer device in one embodiment;
[0032] FIG. 7 is a diagram showing the internal structure of a computer device in another embodiment. DETAILED DESCRIPTION
[0033] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0034] It should be noted that in the following description, the terms "first, second and third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first, second and third" can be interchanged in a specific order or sequence where permitted, so that the embodiments of the present application described here can be implemented in an order other than that illustrated or described here.
[0035] The master node switching method provided in the embodiment of the present application can be applied in the application environment shown in FIG1. The terminal 102 communicates with the server 104 through a network. The data storage system can store data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers.
[0036] The terminal 102 may be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, an IoT device, and a portable wearable device. The IoT device may be a smart speaker, a smart TV, a smart air conditioner, and a smart vehicle-mounted device, etc. The portable wearable device may be a smart watch, a smart bracelet, a head-mounted device, etc.
[0037] The server 104 may be an independent physical server or a service node in a blockchain system. A peer-to-peer (P2P) network is formed between the service nodes in the blockchain system. The P2P protocol is an application layer protocol running on the Transmission Control Protocol (TCP).
[0038] In addition, server 104 can also be a server cluster composed of multiple physical servers, and can be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), as well as big data and artificial intelligence platforms.
[0039] The terminal 102 and the server 104 may be connected via Bluetooth, USB (Universal Serial Bus) or a network or other communication connection method, and this application does not impose any limitation thereto.
[0040] Zookeeper clusters are widely used in computer services due to their superior performance and diverse functions. The working mode adopted by Zookeeper clusters is the master-slave mode. The cluster includes three types of node roles: master nodes, slave nodes, and observer nodes. Usually, the master node is generated by cluster voting, and the slave nodes participate in cluster voting, while the observer nodes do not participate in cluster voting. The original voting mechanism for Zookeeper clusters is to determine the master node according to the priority order of the Epoch value, transaction id value, and myid value of each node in the cluster. For example, when there is only one node with the maximum Epoch value, the node becomes the master node of the next cycle through voting; when there are more than two nodes with the maximum Epoch value, it is determined which node has the largest transaction id value among at least two nodes with the largest Epoch value, and the node becomes the master node of the next cycle through voting; when there are more than two nodes with the maximum Epoch value and the two or more nodes cannot determine the master node of the next cycle through the transaction id value, the process of determining the master node of the next cycle through the comparison of the myid values between the nodes and the voting election mechanism is the same, which will not be repeated here.
[0041] Based on the voting and master election mechanism of the existing Zookeeper cluster, after the existing Zookeeper cluster enters a stable working state, all nodes in the cluster except the master node keep data synchronization with the master node, so that the Epoch value and transaction id of each node are synchronized and the size is the same. If a new round of voting and master election is triggered, the node with the largest myid value in the cluster will serve as the master node. When the master node is switched, if there is no adverse situation of large network delay or large data synchronization delay, then obviously, the original voting and master election mechanism will only determine the master node of the next cycle between the two nodes with the largest myid value in the cluster. It can be seen that in the existing Zookeeper cluster, the original voting and master election mechanism cannot make all slave nodes except the master node of the current cycle have the opportunity to become the master node of the next cycle. If a cluster has only a few nodes serving as the master node for a long time, then in some special cases, it is actually a certain operation risk that other nodes that have not served as the master node for a long time will suddenly serve as the master node. It can be seen that this is not conducive to ensuring the stability and reliability of the Zookeeper cluster. It can be seen that in order to improve the stability and reliability of the cluster, it is necessary to avoid the situation where only one of the two nodes in the cluster can always serve as the master node.
[0042] Based on this, in one embodiment, as shown in FIG2 , the present application provides a master node switching method, which can be executed by the server or terminal in FIG1 , or executed by the server and the terminal in collaboration, and is described by taking the method executed by the server in FIG1 as an example, and includes the following steps:
[0043] Step 202: Determine the weight value of each node based on the node information of the nodes in the cluster.
[0044] The cluster refers to a cluster having multiple nodes, the node may refer to a server node, and further, the cluster may be a ZooKeeper cluster.
[0045] The server executing the method may be a node in the cluster or a node outside the cluster.
[0046] When the cluster is a ZooKeeper cluster, since the working mode adopted by the ZooKeeper cluster is the master-slave mode, that is, the ZooKeeper cluster has a master node and a slave node, this means that a cluster requires at least two nodes. However, if the number of nodes is an even number, then when the original voting mechanism of the ZooKeeper cluster needs to be used, there may be a situation where the two nodes have a tie. Therefore, the number of nodes can be set to an odd number, that is, the cluster should include at least 3 nodes.
[0047] The cluster is a multi-computer room cluster. Further, the cluster may be a ZooKeeper multi-computer room cluster. The number of computer rooms in the cluster and the number of nodes included in each computer room satisfy the condition that the number of nodes in any two computer rooms reaches more than half of the number of all nodes.
[0048] For example, a cluster may have three computer rooms, and the three computer rooms have a total of seven nodes, so the three computer rooms may have three nodes, three nodes, and one node, respectively. It should be noted that the number of computer rooms and the number of nodes included in each computer room provided in this embodiment are only used as a feasible example. In a specific implementation, the number of computer rooms in a cluster and the number of nodes included in each computer room only need to meet the condition that the number of nodes in any two computer rooms reaches more than half of the number of all nodes. The number of computer rooms in a cluster and the number of nodes included in each computer room are not limited here.
[0049] Node information may include node deployment area, node role type, node synchronization information, node attribute information, and other information. Weight value is used for each node to select the master node.
[0050] In one embodiment, before determining the weight value of each node based on the node information of the nodes in the cluster, the method further includes: acquiring the node information of each node in the cluster.
[0051] In one embodiment, the server determines the weight value of each node for master node selection in the form of weighted summation based on various information included in the node information of each node in the cluster and the weights corresponding to various information.
[0052] In one embodiment, the server determines the weight value of each node for master node selection based on the node information and weight value formula of each node in the cluster.
[0053] Among them, when the weight value of each node is determined based on the node information of each node in the cluster and the weight value formula, the weight value formula can be set according to the actual master election requirements. For example, the weight value formula can be set so that the weight value of the first node corresponding to the weight value that meets the weight condition is reduced in the first cycle; it can also be set so that the weight value of the first node and the nodes located in the same computer room as the first node in the first cycle are reduced, and it can also be set so that the weight value of other nodes corresponding to the weight value that does not meet the weight condition is increased in the first cycle.
[0054] Step 204: The first node corresponding to the weight value that meets the weight condition is taken as a candidate node.
[0055] Among them, satisfying the weight condition can be that the weight value is greater than or equal to a preset weight value, or it can be that the weight value has the maximum value among all weight values; when satisfying the weight condition is that the weight value has the maximum value among all weight values, the first node is a node with the largest weight value among all nodes.
[0056] The candidate node is used to be switched to the master node of the first cycle when the server responds to the node switching request for the first cycle. In other words, the candidate node is the node that the cluster will serve as the master node in the first cycle.
[0057] Step 206: In response to the node switching request, the candidate node is switched to be the master node of the first cycle.
[0058] The node switching request may be initiated by a user to the cluster in a client applied to a terminal, or may be initiated autonomously by the cluster when detecting that the master node of the current cycle (second cycle) is in an abnormal working state.
[0059] A cycle refers to a period of time when the same node serves as the master node. That is, when the master node changes, the cluster enters another cycle from one cycle. The first cycle can be the next cycle relative to the current cycle (second cycle).
[0060] The master nodes of adjacent cycles are different nodes, and the weight value of the master node in a first cycle is different from the weight value in a next cycle relative to the first cycle.
[0061] Since the weight value of each node is determined based on the node information of each node in the cluster, if the node information of the candidate node changes after it becomes the master node of the first cycle, the weight value of the candidate node will also change after it becomes the master node of the first cycle. In order to make each node in the cluster have the possibility of serving as the master node, the node information of the candidate node can be changed after it becomes the master node of the first cycle. The result of the change in the weight value after becoming the master node of the first cycle may be that the weight value of the master node of the first cycle no longer meets the weight condition, thereby avoiding the situation where only one of the two nodes in the cluster can serve as the master node, thereby improving the stability and reliability of the cluster.
[0062] For example, the master node switching method provided in the embodiment of the present application can be applied to the ZooKeeper cluster shown in Figure 3. The ZooKeeper cluster includes three computer rooms, namely computer room A, computer room B and computer room C. Computer room A includes A1, A2...AN, a total of N nodes, computer room B includes B1, B2...BN, a total of N nodes, and computer room C includes C1, C2...CN, a total of N nodes. The master node switching method provided in the embodiment of the present application makes it possible for any of the 3N nodes A1, A2...AN, B1, B2...BN, C1, C2...CN to be switched to the master node of a certain period.
[0063] In the above-mentioned master node switching method, the weight value of each node is determined based on the node information of the nodes in the cluster. Since the node information of each node is different, the weight value of each node is also different. The first node corresponding to the weight value that meets the weight condition is used as a candidate node. When responding to the node switching request, the candidate node is switched to the master node of the first cycle, so that the node corresponding to the weight value that meets the weight condition can serve as the master node of the next cycle. Among them, the node information of the candidate node changes after becoming the master node of the first cycle, so that the node serving as the master node of the next cycle in the subsequent cycle, the change of node information will also cause the weight value to change. At the same time, the weight values of other nodes that did not serve as the master node in the first cycle will also change in the subsequent cycles, which increases the possibility of other nodes serving as the master node in the subsequent cycles, thereby avoiding the situation where only one of the two nodes in the cluster can serve as the master node. By avoiding the undesirable situation that there are some nodes in the cluster that cannot be performance verified for a long time, the stability and reliability of the cluster are improved.
[0064] In some scenarios, if some nodes have not served as the master node of the cluster for a long time, then the suitability of these nodes for serving as the master node in terms of performance will not be verified for a long time. If the weight values of these nodes in a certain period meet the weight conditions and are determined as the master nodes after a long period of time, the stability and reliability of the cluster will be difficult to guarantee. It can be seen that in order to ensure the stability and reliability of the cluster and ensure that the stability and reliability of the cluster can be guaranteed in most cases regardless of which node serves as the master node, each node should be given the opportunity to serve as the master node of the cluster. Based on this, in one embodiment, the above method also includes:
[0065] Determine the interval time between each node and the last time it served as the master node, and generate the weight adjustment coefficient of each node based on the interval time;
[0066] The above determines the weight value of each node based on the node information of the nodes in the cluster, including:
[0067] Based on the node information of the nodes in the cluster and the weight adjustment coefficient of each node, the weight value of each node is determined.
[0068] Among them, there is a positive correlation between the interval time and the weight adjustment coefficient, so that the node with a longer interval from the last time it served as the master node can have a larger weight adjustment coefficient, and thus has a larger weight value, and its weight value is closer to meeting the weight condition and is more likely to become the master node of the first cycle.
[0069] In another embodiment, the server determines the time difference between the interval time of each node and the preset interval time. When the time difference is positive or greater than or equal to zero, a weight adjustment coefficient greater than 1 is generated according to the size of the time difference. There is a positive correlation between the time difference and the weight adjustment coefficient. When the time difference is negative or less than zero, the generated weight adjustment coefficient is 1.
[0070] In the above embodiment, when a node has not served as the master node of the cluster for a long time, the weight value of the node is made closer to satisfying the weight condition according to the weight adjustment coefficient, thereby increasing the possibility of each node in the cluster serving as the master node in the first cycle, avoiding the existence of some nodes in the cluster whose performance cannot be verified for a long time, and further avoiding the undesirable situation in which a node whose performance is difficult to guarantee serves as the master node in a certain cycle in the cluster, avoiding the safety hazard that the cluster may be in an abnormal state, and ensuring the stability and reliability of the cluster.
[0071] In one embodiment, the above-mentioned determining the weight value of each node based on the node information of the nodes in the cluster includes:
[0072] The weight parameter of each node is obtained based on the node information of the nodes in the cluster; wherein different node information of the same node corresponds to different weight parameters; and the weight value of each node is determined according to the weight parameter of each node.
[0073] Among them, different node information of the same node corresponds to different weight parameters. Therefore, since the same node corresponds to multiple different weight parameters, the server further determines the weight value of each node for master node selection based on the multiple different weight parameters of each node.
[0074] In one embodiment, the server can calculate the weight parameters of each node in real time in each cycle. That is to say, before obtaining the weight parameters of each node based on the node information of the nodes in the cluster, the weight parameters of each node have been calculated. Therefore, when responding to a node switching request, it is only necessary to obtain the weight parameters calculated in advance to determine the weight value of each node for master node selection.
[0075] In another embodiment, after the server switches the candidate node to the main node of the first cycle in response to the node switching request, the weight parameters of each node in the first cycle can be calculated in real time. Similarly, in each cycle, the weight parameters of each node can be recalculated in real time after the main node is switched.
[0076] In the above embodiment, different weight parameters of each node are obtained based on different node information of each node, and then the weight value of each node is determined according to multiple different weight parameters of each node, so that the determined weight value of each node is more accurate and reliable, thereby ensuring the stability and reliability of the cluster.
[0077] In one embodiment, the node information of the candidate node changes after the candidate node becomes the master node of the first cycle.
[0078] In this embodiment, since the weight value of each node is determined based on the node information of each node, if the node information of the candidate node changes after it becomes the master node of the first cycle, the weight value of the candidate node will change after it becomes the master node of the first cycle, thereby avoiding the undesirable situation in which a certain node in the cluster serves as the master node for a long time, thereby reducing the possibility of other nodes serving as the master node, thereby improving the stability and reliability of the cluster.
[0079] In one embodiment, the node information includes node deployment area, node role type, node synchronization information and node attribute information;
[0080] The above-mentioned process of obtaining the weight parameters of each node based on the node information of the nodes in the cluster includes:
[0081] According to the node deployment area, node role type, node synchronization information and node attribute information, obtain the first weight, second weight, third weight and node attribute weight of each node respectively;
[0082] The weight value of each node is determined according to the weight parameters of each node, including:
[0083] The weight value of each node is determined according to the first weight, the second weight, the third weight and the node attribute weight of each node.
[0084] The node deployment area may refer to the computer room where the node is located in the cluster. For example, if two nodes in the cluster are located in the same computer room, the node deployment areas of the two nodes are the same.
[0085] The number of deployment areas of the cluster and the number of nodes included in each deployment area may satisfy the condition that the number of nodes in any two deployment areas reaches more than half of the number of all nodes.
[0086] The node role type may refer to the node role played by the node in the cluster, and the node role type may include a master node, a slave node, and an observer node.
[0087] The node synchronization information can indicate whether the node is a synchronous node or an asynchronous node. A synchronous node refers to a node whose data is synchronized with the data of the master node. Similarly, an asynchronous node refers to a node whose data is not synchronized with the data of the master node.
[0088] If an asynchronous node serves as the master node of the cluster, the remaining nodes will obtain various types of data on the asynchronous node. Usually, the data of the asynchronous node is abnormal data, that is, the data should have been deleted or modified. At this time, the remaining nodes will also obtain abnormal data and cause the cluster to access the wrong business data. Therefore, usually, the node synchronization information of the node serving as the master node indicates that the node is a synchronous node. Therefore, in order to avoid the asynchronous node serving as the master node, the third weight of the asynchronous node can be set to a very small number to avoid the weight value of the asynchronous node meeting the weight condition. For example, the third weight of the asynchronous node can be less than or equal to the first preset weight, and the first preset weight can be 0 or other values.
[0089] In the above embodiment, the first weight, second weight, third weight and node attribute weight of each node are obtained respectively according to the node deployment area, node role type, node synchronization information and node attribute information, and the weight value of each node is determined according to the first weight, second weight, third weight and node attribute weight of each node, so that the weight value determination process has a basis, ensuring that the weight value of each node is accurate and credible, thereby ensuring the stability and reliability of the cluster.
[0090] In one embodiment, the method further includes:
[0091] Obtain the node deployment area of each node; assign a second preset weight to each node, and update the second preset weight according to the relationship between the node deployment area of each node and the deployment area condition to obtain the first weight of each node.
[0092] The deployment area condition may include at least one of the following conditions: the node and the master node of the current cycle (second cycle) are located in the same deployment area; the number of nodes in the deployment area where the node is located has the maximum value in the cluster. The second preset weight may be 1 or other values.
[0093] In one embodiment, the updating of the second preset weight to obtain the first weight of each node according to the relationship between the node deployment area of each node and the deployment area condition includes:
[0094] According to the number of deployment area conditions satisfied by the node deployment area of each node, the second preset weight is updated to obtain the first weight of each node.
[0095] Among them, the second preset weight is updated according to the number of deployment area conditions satisfied by the node deployment area of each node to obtain the first weight of each node. It can be that the second preset weight of each node is multiplied by half of the number of times for each deployment area condition satisfied by the node deployment area of each node.
[0096] For example, the second preset weight is 1, and the second preset weight of the node is multiplied by 0.5 every time the node deployment area in each stage meets one deployment area condition. Then, if a node and the master node of the current cycle (second cycle) are located in the same deployment area and the number of nodes in the deployment area has the maximum value in the cluster, the first weight of the node = 1*0.5*0.5=0.25.
[0097] The deployment area condition includes that the node and the master node of the current cycle (second cycle) are located in the same deployment area. This can avoid the undesirable situation that, under the special circumstance that the node deployment area of the master node of the current cycle (second cycle) needs to be maintained, the weight values of other nodes in the same area of the same deployment area meet the weight conditions and are determined as the master nodes of the first cycle. Therefore, by increasing the possibility of nodes in other deployment areas serving as master nodes, the stability and reliability of the cluster are improved.
[0098] In the above embodiment, the first weight of each node is obtained based on the relationship between the node deployment area of each node and the deployment area condition, thereby, by reducing the weight value of the same-area node located in the same deployment area as the master node of the current cycle, the possibility of nodes in other deployment areas serving as master nodes is increased. Similarly, the possibility of nodes in deployment areas with a smaller number of nodes serving as master nodes can also be increased, thereby avoiding the situation where the cluster can only be served by one node in two deployment areas as the master node, and also avoiding the situation where the cluster can only be served by the node in the deployment area with the largest number of nodes as the master node. By increasing the possibility of nodes in other deployment areas serving as master nodes, the stability and reliability of the cluster are improved.
[0099] In one embodiment, the node attribute information includes a node address, a master election number, a node transaction identifier, and a node identity identifier;
[0100] The first weight, second weight, third weight and node attribute weight of each node are obtained according to the node deployment area, node role type, node synchronization information and node attribute information, including:
[0101] According to the node deployment area, node role type and node synchronization information, the first weight, second weight and third weight of each node are obtained respectively; according to the node address, the number of master elections, the node transaction identifier and the node identity identifier, the fourth weight, fifth weight, sixth weight and seventh weight of each node are obtained respectively;
[0102] The above method of determining the weight value of each node according to the first weight, the second weight, the third weight and the node attribute weight of each node includes:
[0103] The weight value of each node is determined according to the first weight, the second weight, the third weight, the fourth weight, the fifth weight, the sixth weight and the seventh weight of each node.
[0104] For example, when the cluster is a ZooKeeper cluster, the node address refers to the node IP, the number of master elections refers to the Epoch value of the node, the node transaction identifier refers to the transaction ID value of the node, and the node identity identifier refers to the myid value of the node.
[0105] In one embodiment, the weight value is the sum of the first weight, the second weight, the third weight, the fourth weight, the fifth weight, the sixth weight and the seventh weight. That is, the weight value can satisfy the following formula: weight value = first weight + second weight + third weight + fourth weight + fifth weight + sixth weight + seventh weight.
[0106] In one embodiment, the weight value of each node is determined according to the first weight, the second weight, the third weight, the fourth weight, the fifth weight, the sixth weight and the seventh weight of each node, which may be that the first sum among the first weight, the second weight, the fifth weight, the sixth weight and the seventh weight is calculated first, then the first product between the first sum and the third weight is calculated, then the second sum between the first product and the fourth weight is calculated, and finally the second sum is determined as the weight value of each node. That is, the weight value may satisfy the following formula: weight value = (first weight + second weight + fifth weight + sixth weight + seventh weight) * third weight + fourth weight.
[0107] In the above embodiment, the weight value of each node is determined based on the node deployment area, node role type, node synchronization information, node address, number of master elections, node transaction identifier and node identity identifier of each node, so that the weight value determination process has a basis, ensuring the accuracy and credibility of the weight value of each node, and further ensuring the stability and reliability of the cluster.
[0108] In one embodiment, the method further includes:
[0109] The seventh weight of each node is determined according to the node identity of each node; wherein, the larger the node identity of the node is, the smaller the seventh weight of the node is.
[0110] Among them, the larger the node identity of the node, the smaller the seventh weight of the node. It can be that the higher the node identity size is ranked in the cluster, the smaller the seventh weight of the node; or the seventh weight of the node can be the reciprocal of the node identity.
[0111] In one embodiment, the seventh weight of each node is determined according to the node identity of each node, including:
[0112] The sorting sequence number of each node is determined according to the size of the node identity identifier of each node; the seventh weight of each node is determined based on the node identity identifier and gradient value of the node that is in reverse order with the sorting sequence number of each node.
[0113] The gradient value can be 0.1 or other values.
[0114] The server determines the sorting sequence of each node among all the nodes in the cluster according to the size of the node identity identifier of each node in the cluster.
[0115] For example, if the sorting sequence number of a node is first, then the sorting sequence number of the node whose sorting sequence number is reversed is the last one, and the same is true for other sorting sequences, which will not be repeated here.
[0116] For example, when the cluster is a ZooKeeper cluster, the node ID refers to the myid value of the node. Assuming that the node ID size of the node is ranked higher in the cluster, the seventh weight of the node is smaller, and the gradient value = 0.1. Assuming that there are 5 nodes in the cluster, the node IDs of the 5 nodes are 9, 6, 5, 2, and 1 respectively. Among them, the node with the node ID of 9 has the largest node ID in the cluster, that is, the ranking number is the first, then the seventh weight of the node = gradient value * node ID of the node with the last ranking number = 0.1*1=0.1; similarly, the node with the node ID of 6 has the second ranking number, then the seventh weight of the node = gradient value * node ID of the node with the second last ranking number = 0.1*2=0.2; similarly, based on the same calculation method, the seventh weight of the node with the node ID of 5 is 0.5, the seventh weight of the node with the node ID of 2 is 0.6, and the seventh weight of the node with the node ID of 1 is 0.9.
[0117] In the above embodiment, the seventh weight of each node is determined based on the node identity of each node, and the seventh weight of each node is negatively correlated with the node identity of the node, so that nodes with smaller node identities can have larger seventh weights. Therefore, the weights of nodes with smaller node identities that are usually difficult to be determined as master nodes are increased, and further, the possibility of these nodes serving as master nodes can also be increased, thereby improving the stability and reliability of the cluster.
[0118] In one embodiment, the method further includes:
[0119] According to the node synchronization information of each node, the synchronous nodes and the asynchronous nodes included in the cluster are determined; the synchronous node value of the synchronous node is obtained, and the third weight of the synchronous node is determined according to the synchronous node value; the asynchronous node value of the asynchronous node is obtained, and the third weight of the asynchronous node is determined according to the asynchronous node value; wherein the third weight of the synchronous node is greater than the third weight of the asynchronous node.
[0120] Among them, the synchronization node value and the third weight of the synchronization node can be the same, and the non-synchronization node value and the third weight of the non-synchronization node can be the same. Thus, the synchronization node value and the third weight of the synchronization node can both be 1, and the non-synchronization node value and the third weight of the non-synchronization node can both be 0.
[0121] For example, if the weight value = (first weight + second weight + fifth weight + sixth weight + seventh weight) * third weight + fourth weight, and the third weight of the asynchronous node is 0, then the weight value of the asynchronous node will be = the second weight. Obviously, in this case, the weight value of the asynchronous node is smaller than the weight value of the synchronous node, so that the asynchronous node is difficult to meet the weight condition, and then the asynchronous node is difficult to be determined as the master node of the first cycle or other cycles.
[0122] In the above embodiment, each node is characterized as a synchronous node or an asynchronous node through node synchronization information, and the third weight of the synchronous node is greater than the third weight of the asynchronous node. Therefore, it is difficult for the asynchronous node to meet the weight condition and be determined as the master node of the first cycle or other cycles, thereby ensuring that the master node of the cluster is a synchronous node and thus avoiding the undesirable situation that the cluster accesses the wrong business data, thereby improving the stability and reliability of the cluster.
[0123] In one embodiment, when the number of the first nodes is more than two, the method further includes:
[0124] The node switching mode of the node switching request is determined to be the third preset switching mode, and based on the node information of each node and the voting election mechanism of the third preset switching mode, the third node corresponding to the node information that meets the voting conditions is used as a candidate node.
[0125] Among them, the voting and election mechanism of the third preset switching method may refer to the initial voting and election mechanism adopted by the cluster before adopting the master node switching method provided by the embodiment of the present application. The voting and election mechanism of the third preset switching method may determine the master node in the order of priority of the number of master elections, node transaction identifier, and node identity identifier, that is, the node with the largest number of master elections is given priority as the candidate node. If the candidate node cannot be selected based on the number of master elections, the node with the largest node transaction identifier is given priority as the candidate node. If the candidate node still cannot be selected based on the node transaction identifier, the node with the largest node identity identifier is given priority as the candidate node; further, based on this, if the cluster does not have a large network delay or a large data synchronization delay, the number of master elections and the node transaction identifier of each node remain synchronized and the same size. Therefore, the third node corresponding to the node information that meets the voting conditions can be the node with the largest node identity identifier.
[0126] For example, when the cluster is a ZooKeeper cluster, the voting mechanism determines the master node according to the priority order of the Epoch value, transaction id value, and myid value of each node in the cluster; and when the cluster does not have a large network delay or a large data synchronization delay, the Epoch value and transaction id of each node remain synchronized and have the same size. Therefore, the third node can be the node with the largest myid value.
[0127] In the above embodiment, since the cluster can only have one master node, when the number of first nodes is more than two, in the special case, based on the node information of each node and the cluster's initial voting mechanism for selecting a master, the third node corresponding to the node information that meets the voting conditions is used as a candidate node to ensure that the cluster can always determine a master node, thereby avoiding the undesirable situation in which the cluster cannot determine the master node when the number of first nodes is more than one, thereby causing the cluster to be in an abnormal state, thereby ensuring the stability and reliability of the cluster.
[0128] In one embodiment, the method further includes:
[0129] Determine a node switching mode for a node switching request;
[0130] The above-mentioned switching of the candidate node to the master node of the first cycle includes:
[0131] When the node switching mode is the first preset switching mode, the candidate node is switched to the master node of the first cycle.
[0132] The first preset switching method is a node switching method in which the first node corresponding to the weight value that meets the weight condition is used as a candidate node, and the candidate node is switched to the main node of the first period.
[0133] In one embodiment, the method further includes:
[0134] When the node switching mode is the second preset switching mode, a second node specified by the node switching request is determined; and the second node is switched to be the master node of the first cycle.
[0135] The second preset switching mode is a node switching mode in which the pointing node serves as the master node. When the node switching mode is the second preset switching mode, the node switching request includes node designation information of the second node, so that the second node can be directly switched to the master node of the first cycle.
[0136] In the above embodiment, when the node switching mode is the first preset switching mode, the candidate node is switched to the master node of the first cycle; and when the node switching mode is the second preset switching mode, the second node specified by the node switching request is determined, and the second node is switched to the master node of the first cycle. Thus, the embodiment of the present application can not only determine the master node of the first cycle based on the weight value of each node, but also directly determine the designated node as the master node of the first cycle, realizing the selectivity of the master node switching mode, thereby improving the flexibility of the master node switching mode while also improving the stability and reliability of the cluster.
[0137] In one embodiment, the method further includes:
[0138] In response to a node switching request, the master node of the second cycle is switched to the target slave node of the first cycle; the second cycle is earlier than the first cycle; wherein the weight value of the target slave node of the first cycle is less than the weight value of the master node of the second cycle.
[0139] The master node of the second cycle and the target slave node of the first cycle are the same node in the cluster.
[0140] The weight value of the target slave node in the first cycle refers to the weight value of the target slave node when the master node switching action about to enter the first cycle occurs; similarly, the weight value of the master node in the second cycle refers to the weight value of the master node when the master node switching action about to enter the second cycle occurs.
[0141] The second cycle may be earlier than the first cycle and may also be a cycle connected to the first cycle, that is, the second cycle may refer to the current cycle.
[0142] The weight value of the target slave node in the first cycle is less than the weight value of the master node in the second cycle, so the weight value of the target slave node in the first cycle no longer meets the weight condition, and the target slave node in the first cycle can no longer be a candidate node in the first cycle, and other nodes whose weight values meet the weight condition will be used as candidate nodes and switched to the master node of the first cycle. For example, if the same node serves as the master node in the current cycle (the second cycle), after the node becomes the target slave node in the first cycle through the master node switch, the weight value of the node decreases, and the node will not be able to serve as the master node in the first cycle because the weight value does not meet the weight condition.
[0143] In the above embodiment, after the master node of the second cycle is switched to the target slave node of the first cycle in response to the node switching request, the weight value of the target slave node of the first cycle changes, so that the weight value of the target slave node of the first cycle is less than the weight value of the master node of the second cycle. The target slave node of the first cycle will not be able to serve as the master node of the first cycle because the weight value no longer meets the weight condition, thereby avoiding the situation where only one of the two nodes in the cluster can serve as the master node. At the same time, since the weight value of the same node will be reduced after serving as the master node, it is equivalent to providing other nodes in the cluster with the opportunity to serve as the master node, thereby improving the stability and reliability of the cluster.
[0144] In one embodiment, after the server switches the candidate node to the master node of the first cycle, the node information of the nodes in the same area that are located in the same deployment area as the master node of the first cycle changes.
[0145] The deployment area may refer to a computer room in the cluster, and thus, a node in the same area as the master node of the first cycle, which is located in the same deployment area, may refer to a node located in the same computer room as the master node of the first cycle.
[0146] Since the weight value of each node is determined based on the node information of each node, if the node information of the nodes in the same area as the main node of the first period changes, the weight value of the nodes in the same area as the main node of the first period will also change.
[0147] The change trend of the weight value of the node in the same region may be the same as that of the master node in the first cycle. For example, if the result of the change in the node information of the candidate node after becoming the master node in the first cycle is that the weight value of the master node in the first cycle is reduced, then the result of the change in the node information of the node in the same region is that the weight value of the node in the same region is reduced.
[0148] The changing trend of the weight values of the nodes in the same region may be such that it is more difficult for the weight values of the nodes in the same region to meet the weight condition. That is to say, if the weight condition is met when the weight value has the maximum value among all weight values, then the changing trend of the weight values caused by the change in the node information of the nodes in the same region is that the weight values of the nodes in the same region become smaller.
[0149] In one embodiment, the node information of the node in the same area that is located in the same deployment area as the master node in the first cycle changes, which means that the node deployment area of the node in the same area changes, and thus, the first weight of the node in the same area changes.
[0150] In another embodiment, the variation trend of the weight values of the nodes in the same region is that the first weights of the nodes in the same region decrease.
[0151] In the above embodiment, when the node information of the candidate node changes after becoming the master node of the first cycle, the node information of the nodes in the same region of the master node of the first cycle located in the same deployment area also changes. As a result, the weight value of the nodes in the same region of the master node of the first cycle will be more difficult to meet the weight condition and the possibility of serving as the master node is reduced. Therefore, the situation that the master node of the cluster only exists in a certain deployment area or can only switch back and forth between two deployment areas is avoided. This is equivalent to providing other regional nodes in the cluster that are located in different deployment areas from the master node of the first cycle with the opportunity to serve as the master node, thereby improving the stability and reliability of the cluster.
[0152] In one embodiment, the switching of the second node to the master node of the first cycle includes:
[0153] The weight value of the second node is adjusted so that the weight value of the second node meets the weight condition; and the second node is switched to be the master node of the first cycle.
[0154] In one embodiment, the above-mentioned adjusting the weight value of the second node includes:
[0155] The weight value of the second node is determined as the sixth preset weight; or the sum of the weight value of the first node and the seventh preset weight is determined as the weight value of the second node.
[0156] The sixth preset weight may be a value greater than or equal to the preset weight value, and the preset weight value may be a value much greater than the value range of the weight values of each node, that is, the weight value of the second node is determined as the sixth preset weight, the purpose of which is to make the weight value of the second node greater than the weight value of any other node in the cluster. In a specific implementation, the size of the sixth preset weight may be set according to the specific situation, and the sixth preset weight is not specifically limited here.
[0157] The seventh preset weight can be a positive value. For example, the seventh preset weight can be 1 or other values greater than zero, and the sum of the weight value of the first node and the seventh preset weight is determined as the weight value of the second node, with the purpose of making the weight value of the second node greater than the weight value of any other node in the cluster. In a specific implementation, as long as it is ensured that the sum of the weight value of the first node and the seventh preset weight is greater than the weight value of any other node in the cluster, the size of the seventh preset weight can be set according to the specific situation, and the seventh preset weight is not specifically limited here.
[0158] In the above embodiment, the weight value of the second node is adjusted by determining the weight value of the second node as the sixth preset weight, or determining the sum of the weight value of the first node and the seventh preset weight as the weight value of the second node, thereby making the weight value of the second node greater than the weight value of any other node in the cluster, that is, making the weight value of the second node meet the weight condition while the weight value of any other node does not meet the weight condition, and further, when the node switching mode is the second preset switching mode, it can ensure that the second node specified by the node switching request can serve as the master node, thereby improving the stability and reliability of the cluster.
[0159] In one embodiment, the adjusting the weight value of the second node so that the weight value of the second node satisfies the weight condition includes:
[0160] Adjusting the fourth weight of the second node so that the weight value of the second node satisfies the weight condition;
[0161] The above step of determining the weight value of the second node as the sixth preset weight includes:
[0162] The fourth weight of the second node is determined as a sixth preset weight.
[0163] For example, if the weight value = (first weight + second weight + fifth weight + sixth weight + seventh weight) * third weight + fourth weight, then when the sixth preset weight is much larger than the value range of the weight values of each node, the fourth weight of the second node will also be much larger than the weight values of each node, so that the weight value of the second node can meet the weight condition and serve as the main node.
[0164] In the above embodiment, by adjusting the fourth weight of the second node to a value that is much larger than the value range of the weight values of each node, the weight value of the second node becomes a node that meets the weight condition, and then the second node can be smoothly switched to the main node, thereby improving the stability and reliability of the cluster.
[0165] In one embodiment, the method further includes:
[0166] When the node role type of the second node is a non-election role, or when the second node is an asynchronous node, a node switching confirmation request is sent to the terminal; in response to a node switching confirmation instruction for the node switching confirmation request, the second node specified in the node switching request is used as the master node for node switching.
[0167] Among them, the non-elected role can refer to a node role that does not have the voting function in the cluster's initial voting mechanism. For example, in the initial voting mechanism of the ZooKeeper cluster, the master node and the slave node have the voting function, but the observer node does not have the voting function. Therefore, when the cluster is a ZooKeeper cluster, the non-elected role refers to the observer node.
[0168] The terminal may be a terminal used by a cluster management user; the node switching confirmation request is used to ask the user whether to confirm switching the second node whose node role type is a non-election role or a non-synchronous node to the master node.
[0169] In one embodiment, if the server cannot respond to a node switching confirmation instruction from the terminal for a node switching confirmation request, or responds to a node switching rejection instruction from the terminal for a node switching confirmation request, the second node will not be used as the main node for node switching.
[0170] In the above embodiment, when the node role type of the second node is a non-election role, or the second node is a non-synchronous node, that is, the second node does not normally serve as the master node or is not suitable to serve as the master node, a node switching confirmation request is sent to the terminal, and in response to the node switching confirmation instruction for the node switching confirmation request, the second node specified in the node switching request will be used as the master node for node switching, thereby avoiding the undesirable situation of mistakenly switching the second node that is normally not suitable to serve as the master node directly to the master node, thereby ensuring the stability and reliability of the cluster.
[0171] The following is a detailed example of an application process of the master node switching method. The master node switching method is applied to a server, and the application process is as follows:
[0172] (1) Obtaining node information of each node
[0173] The server obtains the node deployment area, node role type, node synchronization information, node address, master election times, node transaction identifier, and node identity identifier of each node in the cluster.
[0174] (2) Calculation of the weight value of each node
[0175] The server determines whether each node and the master node of the second cycle are located in the same deployment area according to the node deployment area of each node, and determines whether the number of nodes in the deployment area where each node is located has the maximum value in the cluster, thereby obtaining the first weight of each node according to the number of deployment area conditions satisfied by each node and the second preset weight. Specifically, if the number of deployment area conditions satisfied is 0, the first weight of the node is 1, if the number of deployment area conditions satisfied is 1, the first weight of the node is 0.5, and if the number of deployment area conditions satisfied is 2, the first weight of the node is 0.25.
[0176] The server replaces the number of times each node is elected as the master and the node transaction identifier with the node role type, and determines the second weight, fifth weight, and sixth weight of each node based on the node role type of each node. Specifically, in the second cycle, when the node role type of the node is a master node, the second weight, fifth weight, and sixth weight of the node are all 0.5, when the node role type of the node is a slave node, the second weight, fifth weight, and sixth weight of the node are all 1, and when the node role type of the node is an observer node, the second weight, fifth weight, and sixth weight of the node are all 0.
[0177] The server determines the synchronous nodes and the non-synchronous nodes included in the cluster according to the node synchronization information of each node, obtains the synchronous node value of the synchronous node, determines the third weight of the synchronous node according to the synchronous node value, and obtains the non-synchronous node value of the non-synchronous node, and determines the third weight of the non-synchronous node according to the non-synchronous node value. Specifically, the third weight of the synchronous node is 1, and the third weight of the non-synchronous node is 0.
[0178] The server determines the sorting sequence of each node according to the size of the node identification of each node, and determines the seventh weight of each node based on the node identification and gradient value of the node in reverse order of the sorting sequence of each node. Specifically, the larger the node identification, the smaller the seventh weight of the node.
[0179] The server obtains the first weight, the second weight, the third weight, the fourth weight, the fifth weight, the sixth weight and the seventh weight of each node according to the node deployment area, the node role type, the node synchronization information, the node address, the number of master elections, the node transaction identifier and the node identity identifier; determines the weight value of each node for master node selection according to the first weight, the second weight, the third weight, the fourth weight, the fifth weight, the sixth weight and the seventh weight of each node;
[0180] Since there is no need to designate a node to serve as the master node of the cluster, the server sets the fourth weight of each node to 0.
[0181] At this point, the server completes the calculation of various weight parameters of each node, and thus the server completes the calculation of the weight value of each node according to the following formula: weight value = (first weight + second weight + fifth weight + sixth weight + seventh weight) * third weight + fourth weight.
[0182] (3) Determination of candidate nodes
[0183] The server uses the first node corresponding to the weight value that meets the weight condition as a candidate node.
[0184] (4) Switching of the master node in the first cycle
[0185] In response to the node switching request, the server switches the candidate node to the master node of the first cycle; wherein the node information of the candidate node changes after becoming the master node of the first cycle.
[0186] In the above embodiment, based on a specific weight value calculation formula, it is obvious that a slave node having a different deployment area from the master node of the second cycle and having a smaller node identity can have a larger weight value and thus has a greater possibility of becoming the master node of the first cycle, and in the process from the second cycle to the first cycle, the weight value of each node will change due to changes in node information, so that in subsequent cycles, the weight value of each node in the cluster can have the possibility of serving as the master node due to dynamic changes, overcoming the defect in the prior art that only one of the two nodes can serve as the master node of the cluster, and significantly improving the stability and reliability of the cluster.
[0187] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0188] Based on the same inventive concept, the embodiment of the present application also provides a master node switching device for implementing the master node switching method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more master node switching device embodiments provided below can refer to the limitations on the master node switching method above, and will not be repeated here.
[0189] In one embodiment, as shown in FIG. 4 , a master node switching device is provided, including: a first determination module 402 , a second determination module 404 and a switching module 406 , wherein:
[0190] The first determination module 402 is used to determine the weight value of each node based on the node information of the nodes in the cluster.
[0191] The second determining module 404 is configured to take the first node corresponding to the weight value satisfying the weight condition as a candidate node.
[0192] The switching module 406 is configured to switch the candidate node to the master node of the first cycle in response to the node switching request.
[0193] In one embodiment, the first determination module 402 is also used to obtain the weight parameters of each node based on the node information of the nodes in the cluster; wherein different node information of the same node corresponds to different weight parameters; and the weight value of each node is determined according to the weight parameters of each node.
[0194] In one embodiment, the node information of the candidate node changes after the candidate node becomes the master node of the first cycle.
[0195] In one embodiment, the node information includes a node deployment area, a node role type, a node synchronization information, and a node attribute information; the first determination module 402 is further used to obtain a first weight, a second weight, a third weight, and a node attribute weight of each node according to the node deployment area, the node role type, the node synchronization information, and the node attribute information;
[0196] The first determination module 402 is further configured to determine the weight value of each node according to the first weight, the second weight, the third weight and the node attribute weight of each node.
[0197] In one embodiment, the node attribute information includes a node address, a master election number, a node transaction identifier, and a node identity identifier; the first determination module 402 is further used to obtain a first weight, a second weight, and a third weight of each node according to the node deployment area, the node role type, and the node synchronization information; and obtain a fourth weight, a fifth weight, a sixth weight, and a seventh weight of each node according to the node address, the master election number, the node transaction identifier, and the node identity identifier;
[0198] The first determination module 402 is further configured to determine a weight value of each node according to the first weight, the second weight, the third weight, the fourth weight, the fifth weight, the sixth weight and the seventh weight of each node.
[0199] In one embodiment, as shown in FIG. 5 , the apparatus further includes a third determination module 502, which is used to determine the seventh weight of each node according to the node identity of each node; wherein, the larger the node identity, the smaller the seventh weight of the node.
[0200] In one embodiment, as shown in Figure 5, the above-mentioned device also includes a fourth determination module 504, which is used to determine the synchronous nodes and asynchronous nodes included in the cluster based on the node synchronization information of each node; obtain the synchronous node value of the synchronous node, and determine the third weight of the synchronous node based on the synchronous node value; obtain the asynchronous node value of the asynchronous node, and determine the third weight of the asynchronous node based on the asynchronous node value.
[0201] In one embodiment, as shown in FIG5 , the switching module 406 includes a first switching unit 506 , and the first switching unit 506 is used to determine a node switching mode of a node switching request;
[0202] The switching module 406 is further configured to switch the candidate node to the master node of the first period when the node switching mode is the first preset switching mode.
[0203] In one embodiment, as shown in FIG. 5 , the switching module 406 includes a second switching unit 508 , which is used to determine the second node specified by the node switching request when the node switching mode is the second preset switching mode; and switch the second node to the master node of the first cycle.
[0204] In one embodiment, as shown in Figure 5, the above-mentioned switching module 406 includes a third switching unit 510, which is used to switch the master node of the second cycle to the target slave node of the first cycle in response to a node switching request; the second cycle is earlier than the first cycle; wherein the weight value of the target slave node of the first cycle is less than the weight value of the master node of the second cycle.
[0205] Each module in the above master node switching device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0206] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be shown in FIG6. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface is connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store node information. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a master node switching method is implemented.
[0207] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be shown in FIG7. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit, and an input device. The processor, the memory, and the input / output interface are connected via a system bus, and the communication interface, the display unit, and the input device are connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a master node switching method is implemented. The display unit of the computer device is used to form a visually visible image, and can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer covered on the display screen, or a button, trackball or touchpad set on the computer device casing, or an external keyboard, touchpad or mouse, etc.
[0208] Those skilled in the art will understand that the structure shown in FIG. 7 is merely a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0209] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0210] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0211] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0212] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0213] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0214] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0215] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A master node switching method, characterized in that: The method comprises: Determine the weight value of each node based on the node information of the nodes in the cluster; Taking the first node corresponding to the weight value that satisfies the weight condition as a candidate node; In response to the node switching request, the candidate node is switched to be the master node of the first cycle.
2. The method according to claim 1, characterized in that The determining the weight value of each node based on the node information of the nodes in the cluster includes: Obtaining a weight parameter of each node based on the node information of the nodes in the cluster; wherein different node information of the same node corresponds to different weight parameters; The weight value of each node is determined according to the weight parameter of each node.
3. The method according to claim 1, characterized in that The node information of the candidate node changes after the candidate node becomes the master node of the first cycle.
4. The method according to claim 2, characterized in that: The node information includes node deployment area, node role type, node synchronization information and node attribute information; The obtaining of the weight parameter of each node based on the node information of the nodes in the cluster includes: According to the node deployment area, the node role type, the node synchronization information and the node attribute information, respectively obtain a first weight, a second weight, a third weight and a node attribute weight of each node; Determining the weight value of each node according to the weight parameter of each node includes: The weight value of each node is determined according to the first weight, the second weight, the third weight and the node attribute weight of each node.
5. The method according to claim 4, characterized in that The node attribute information includes the node address, the number of times the master is elected, the node transaction identifier, and the node identity identifier; The acquiring, according to the node deployment area, the node role type, the node synchronization information and the node attribute information, the first weight, the second weight, the third weight and the node attribute weight of each node respectively includes: According to the node deployment area, the node role type and the node synchronization information, respectively obtain a first weight, a second weight and a third weight of each of the nodes; According to the node address, the number of master elections, the node transaction identifier, and the node identity identifier, respectively obtain the fourth weight, the fifth weight, the sixth weight, and the seventh weight of each of the nodes; Determining the weight value of each node according to the first weight, the second weight, the third weight and the node attribute weight of each node includes: The weight value of each of the nodes is determined according to the first weight, the second weight, the third weight, the fourth weight, the fifth weight, the sixth weight and the seventh weight of each of the nodes.
6. The method according to claim 5, characterized in that The method further comprises: Determining a seventh weight of each of the nodes according to the node identity of each of the nodes; The larger the node identity of the node is, the smaller the seventh weight of the node is.
7. The method according to claim 4, characterized in that The method further comprises: Determining the synchronous nodes and the asynchronous nodes included in the cluster according to the node synchronization information of each of the nodes; Acquire a synchronization node value of the synchronization node, and determine a third weight of the synchronization node according to the synchronization node value; Acquire an asynchronous node value of the asynchronous node, and determine a third weight of the asynchronous node according to the asynchronous node value; The third weight of the synchronous node is greater than the third weight of the asynchronous node.
8. The method according to claim 1, characterized in that The method further comprises: Determining a node switching mode of the node switching request; The step of switching the candidate node to be the master node of the first cycle includes: When the node switching mode is the first preset switching mode, the candidate node is switched to the master node of the first cycle.
9. The method according to claim 8, characterized in that The method further comprises: When the node switching mode is a second preset switching mode, determining a second node specified by the node switching request; The second node is switched to be the master node of the first cycle.
10. The method according to any one of claims 1 to 9, characterized in that: The method further comprises: In response to the node switching request, switching the master node of the second cycle to the target slave node of the first cycle; the second cycle is earlier than the first cycle; The weight value of the target slave node in the first cycle is smaller than the weight value of the master node in the second cycle.
11. A master node switching device, characterized in that: The device comprises: A first determination module, configured to determine a weight value of each node based on node information of the nodes in the cluster; A second determination module, configured to select a first node corresponding to the weight value satisfying the weight condition as a candidate node; The switching module is used to switch the candidate node to the master node of the first cycle in response to the node switching request.
12. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 10 are implemented.
13. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 10 are implemented.
14. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 10 are implemented.
Citation Information
Cited By
Cluster master selection method and device, computer equipment, medium and product
CN119484229A
Cluster master election method and apparatus, computer device, medium, and product
CN119484229B
Scheduling processing method and device, computer equipment, readable storage medium and program product
CN119652896A
Scheduling processing method and apparatus, computer device, readable storage medium, and program product
WO2026118846A1
