CN114422521B - Method and device for determining master node, electronic equipment and storage medium - Google Patents
Method and device for determining master node, electronic equipment and storage medium Download PDFInfo
- Publication number
- CN114422521B CN114422521B CN202210033330.5A CN202210033330A CN114422521B CN 114422521 B CN114422521 B CN 114422521B CN 202210033330 A CN202210033330 A CN 202210033330A CN 114422521 B CN114422521 B CN 114422521B
- Authority
- CN
- China
- Prior art keywords
- node
- main
- state
- determining
- master
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 44
- 230000000694 effects Effects 0.000 abstract description 3
- 238000010586 diagram Methods 0.000 description 13
- 230000003287 optical effect Effects 0.000 description 6
- 230000006870 function Effects 0.000 description 4
- 230000006399 behavior Effects 0.000 description 2
- 239000013307 optical fiber Substances 0.000 description 2
- 230000002093 peripheral effect Effects 0.000 description 2
- 230000000644 propagated effect Effects 0.000 description 2
- 238000003491 array Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000008901 benefit Effects 0.000 description 1
- 238000004891 communication Methods 0.000 description 1
- 238000004590 computer program Methods 0.000 description 1
- 230000008878 coupling Effects 0.000 description 1
- 238000010168 coupling process Methods 0.000 description 1
- 238000005859 coupling reaction Methods 0.000 description 1
- 238000005259 measurement Methods 0.000 description 1
- 230000008569 process Effects 0.000 description 1
- 230000008707 rearrangement Effects 0.000 description 1
- 230000004044 response Effects 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
- 230000001960 triggered effect Effects 0.000 description 1
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
- H04L67/104—Peer-to-peer [P2P] networks
- H04L67/1044—Group management mechanisms
- H04L67/1051—Group master selection mechanisms
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
- H04L67/104—Peer-to-peer [P2P] networks
- H04L67/1061—Peer-to-peer [P2P] networks using node-based peer discovery mechanisms
- H04L67/1065—Discovery involving distributed pre-established resource-based relationships among peers, e.g. based on distributed hash tables [DHT]
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/14—Session management
- H04L67/143—Termination or inactivation of sessions, e.g. event-controlled end of session
- H04L67/145—Termination or inactivation of sessions, e.g. event-controlled end of session avoiding end of session, e.g. keep-alive, heartbeats, resumption message or wake-up for inactive or interrupted session
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D30/00—Reducing energy consumption in communication networks
- Y02D30/70—Reducing energy consumption in communication networks in wireless communication networks
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Physics & Mathematics (AREA)
- Computing Systems (AREA)
- Mathematical Physics (AREA)
- Theoretical Computer Science (AREA)
- Health & Medical Sciences (AREA)
- Cardiology (AREA)
- General Health & Medical Sciences (AREA)
- Hardware Redundancy (AREA)
- Mobile Radio Communication Systems (AREA)
Abstract
The invention discloses a method, a device, electronic equipment and a storage medium for determining a master node, wherein the method is applied to a distributed cluster and comprises the following steps: determining a main node to be selected, which is consistent with a preset node type, according to the node type of each node to be used; according to the attribute information of each main node to be selected, determining the theoretical waiting time length of the corresponding main node to be selected in each waiting state, and updating the state identification of the corresponding main node to be selected based on the theoretical waiting time length; and determining a target main node according to the state identification, broadcasting a main heartbeat message to each node to be used based on the target main node, so that each node to be used determines the target main node according to the received main heartbeat message, and updating the state identification of other main nodes to be selected into a standby state identification. The technical scheme of the embodiment of the invention improves the technical effects of determining the validity, convenience and universality of the master node.
Description
Technical Field
The embodiment of the invention relates to the technical field of computers, in particular to a method, a device, electronic equipment and a storage medium for determining a master node.
Background
Distributed systems typically require a master node to provide a write operation outside of the system, and when the master node goes offline, a new master node needs to be determined and provided with corresponding services, thereby ensuring the effectiveness of the system.
Currently, two main measures are determined to be taken by a main node, the first is to store main node information based on a distributed key-value in a redis (cache) database so as to call a corresponding key value pair from the cache database to determine the main node information; the second is determining the master node based on zookeeper distributed coordination, namely determining the final master node through voting results of the master node to be used.
The inventors found that when implementing the present technical solution based on the above-described mode, the following problems exist:
when determining the final used master node based on the master node information stored in the redis database, the redis database needs to be deployed separately, namely the complexity of determining the master node is increased; and moreover, all the distributed nodes can access the database, meanwhile, the instability of the redis database is very easy to cause the problem of database faults, and the dependence on the database is very high when the master node is determined, so that the master node which cannot determine the distributed cluster is very easy to cause, the distributed cluster cannot work normally, and the safety and convenience of the use of the distributed cluster are reduced.
In determining master nodes based on zookeeper distributed coordination, it is necessary to satisfy that the number of usable nodes exceeds half of the total number. Again, this is limited by the total number of nodes that can be used. Finally, the mode is also limited by the network environment, and when the network environment is changed greatly, the behavior of the election master node is greatly influenced, namely the problem of poor universality exists.
Disclosure of Invention
The invention provides a method, a device, electronic equipment and a storage medium for determining a master node, which are used for achieving the technical effects of improving convenience, generality and effectiveness of determining the master node.
In a first aspect, an embodiment of the present invention provides a method for determining a master node, where the method is applied to a distributed cluster, including:
determining a main node to be selected, which is consistent with a preset node type, according to the node type of each node to be used;
according to the attribute information of each main node to be selected, determining the theoretical waiting time length of the corresponding main node to be selected in each waiting state, and updating the state identification of the corresponding main node to be selected based on the theoretical waiting time length;
and determining a target main node according to the state identification, broadcasting a main heartbeat message to each node to be used based on the target main node, so that each node to be used determines the target main node according to the received main heartbeat message, and updating the state identification of other main nodes to be selected into a standby state identification.
Further, the preset node type includes a master node type, and the determining, according to the node type of each node to be used, a master node to be selected that is consistent with the preset node type includes:
acquiring node types of nodes to be used; the node types comprise a main node type and a non-main node type;
and taking the node to be used which is consistent with the type of the master node as the master node to be selected.
Further, the method further comprises: if the distributed cluster is in the starting stage, determining a node inconsistent with a preset node type from the nodes to be used, and updating the state identifier of the node from an initial identifier to a standby state identifier; if the distributed cluster is in the operation stage, the state identification of the node to be used, which is inconsistent with the preset node type, is kept unchanged.
Further, the waiting states include a candidate state and a main silence state, the theoretical waiting time length includes a candidate waiting time length in the candidate state and a silence waiting time length in the main silence state, and the determining the theoretical waiting time length of the corresponding main node to be selected in each waiting state according to the attribute information of each main node to be selected includes:
And determining the candidate waiting duration of the corresponding main node to be selected in the candidate state and the silence waiting duration of the main silence state according to the node priority in the attribute information.
Further, the determining, according to the node priority in the attribute information, the candidate waiting duration of the corresponding master node to be selected in the candidate state and the silence waiting duration of the master silence state, includes:
for each main node to be selected, when the state identifier of the current main node to be selected is detected to be updated to be a candidate state identifier, determining the candidate waiting time of the current main node to be selected in a candidate state according to the node priority of the current main node to be selected, the target time information updated to be the candidate state identifier and the heartbeat time information;
and for each main node to be selected, when the state identifier of the current main node to be selected is detected to be updated into the main silence state identifier by the candidate state identifier, determining the silence waiting time of the current main node to be selected in the main silence state according to the node priority of the current main node to be selected and a preset value.
Further, the updating the state identifier of the corresponding master node to be selected based on the theoretical waiting duration includes:
For each main node to be selected, if the current main node to be selected is detected to enter a candidate state, updating the state identifier of the main node to be selected into a candidate state identifier, and when the actual duration of the current main node to be selected in the candidate state is detected to reach the candidate waiting duration, entering the main silence state, and updating the state identifier of the current main node to be selected from the candidate state identifier into a main silence state identifier;
and if the fact that the actual silence duration of the current main node to be selected in the main silence state reaches the silence waiting duration is detected, updating the state identifier of the current main node to be selected from the main silence state identifier to the main state identifier.
Further, the determining the target master node according to the state identifier includes:
and the master node to be selected, of which the state identifier is updated to the master state identifier preferentially, is taken as a target master node.
Further, the determining the target master node according to the state identifier, and broadcasting a master heartbeat message to each node to be used based on the target master node includes:
if at least two state identifiers are detected to be updated to be the main state identifiers at the same time, determining a target main node from main nodes to be selected corresponding to the at least two state identifiers by adopting a random algorithm;
And broadcasting a main heartbeat message to other nodes to be used based on the target main node.
Further, the method further comprises:
when the target main node is detected to be offline, determining main nodes to be selected, which are consistent with the preset node types, from all the nodes to be used of the standby state identification, re-determining the target main node according to the attribute information of all the main nodes to be selected, and keeping the state identification of the nodes to be used, which are inconsistent with the preset node types, unchanged as the standby state identification.
Further, after determining the target master node, the method further includes:
and if the newly added node to be used is detected, and the node to be used receives the main heartbeat message sent by the target main node, updating the state identifier of the node to be used into a standby state identifier.
In a second aspect, an embodiment of the present invention further provides an apparatus for determining a master node, where the apparatus is configured in a distributed cluster, including:
the to-be-selected main node determining module is used for determining to-be-selected main nodes consistent with the preset node types according to the node types of the to-be-used nodes;
the state information determining module is used for determining the theoretical waiting time length of the corresponding main node to be selected in each waiting state according to the attribute information of each main node to be selected, and updating the state identification of the corresponding main node to be selected based on the theoretical waiting time length;
And the target main node determining module is used for determining a target main node according to the state identification, broadcasting a main heartbeat message to each node to be used based on the target main node, so that each node to be used determines the target main node according to the received main heartbeat message, and updating the state identification of other main nodes to be selected into a standby state identification.
In a third aspect, an embodiment of the present invention further provides an electronic device, including:
one or more processors;
storage means for storing one or more programs,
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement a method of determining a master node as described in any of the embodiments of the present invention.
In a fourth aspect, embodiments of the present invention also provide a storage medium containing computer-executable instructions which, when executed by a computer processor, are used to perform a method of determining a master node according to any of the embodiments of the present invention.
According to the technical scheme, the waiting time of the main node to be selected, which is consistent with the preset node type, is determined from the nodes to be used, the waiting time of the main node to be selected in each state is determined according to the attribute information of the main node to be selected, and then the state identification of the corresponding main node to be selected is adjusted based on the waiting time, so that the target main node is determined from a plurality of main nodes to be selected according to the state identification; meanwhile, the problem that the determination of the master node is limited by the number of available nodes and the complexity of the distributed cluster and the universality is poor is solved, the effectiveness, convenience and universality of the determination of the master node are improved, and the use safety and the universality of the distributed cluster are further improved.
Drawings
In order to more clearly illustrate the technical solution of the exemplary embodiments of the present invention, a brief description is given below of the drawings required for describing the embodiments. It is obvious that the drawings presented are only drawings of some of the embodiments of the invention to be described, and not all the drawings, and that other drawings can be made according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a flowchart of a method for determining a master node according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of entering each waiting state after initializing a node according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of each node in each waiting state according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of each node in each waiting state according to an embodiment of the present invention;
FIG. 5 is a flowchart of a method for determining a master node according to an embodiment of the present invention;
FIG. 6 is a schematic diagram of a newly added node to be used in each waiting state after the newly added node to be used is newly added according to an embodiment of the present invention;
fig. 7 is a schematic diagram of a newly added node to be used after receiving heartbeat message information of a target master node according to an embodiment of the present invention;
FIG. 8 is a flowchart of a method for determining a master node according to an embodiment of the present invention;
FIG. 9 is a schematic diagram of a target host node down line according to an embodiment of the present invention;
FIG. 10 is a schematic diagram of a candidate state entered by each node to be selected for standby state identification when a target master node is down line according to an embodiment of the present invention;
FIG. 11 is a schematic diagram of a node to be selected being changed to a standby state after determining a target master node according to an embodiment of the present invention;
fig. 12 is a schematic structural diagram of an apparatus for determining a target master node according to an embodiment of the present invention;
fig. 13 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The invention is described in further detail below with reference to the drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting thereof. It should be further noted that, for convenience of description, only some, but not all of the structures related to the present invention are shown in the drawings.
Fig. 1 is a schematic flow chart of a method for determining a master node according to an embodiment of the present invention, where the method is applicable to determining a master node of a distributed cluster, and the method is applied to the distributed cluster, and may be performed by a device for determining a master node, where the device may be implemented in software and/or hardware, and the hardware may be an electronic device, for example, a mobile terminal or a PC end.
Before the technical solution of the present embodiment is described, an application scenario may be described in an exemplary manner. The distributed type has become an internet architecture trend, in a distributed cluster, only one node is usually a master node at the same time, the master node is externally displayed in a readable and writable state, and operations which can be performed include updating a database, enqueuing or dequeuing a message queue and the like. If multi-node read-write is adopted, the concurrency of distributed nodes can be caused, and the reliability and the safety of the system are reduced. When determining a master node based on zookeeper distributed coordination, the number of usable nodes is limited, namely, the number of usable nodes must exceed half of the total number to determine the master node. Further, the complexity of the distributed clusters is also limited, for example, it is assumed that only 3 nodes of a certain distributed cluster exist, and at this time, the master node cannot be determined based on zookeeper distributed coordination, that is, the problem of poor universality exists in this way. And if the number of usable nodes is even, the number of possible determined main nodes is two, and the election determination main nodes need to be triggered again at the moment, namely the problem of unstable system caused by the fact that multiple elections are easily caused to determine the main nodes. Finally, the mode is also limited by the network environment, and when the network environment is changed greatly, the behavior of the election master node is greatly influenced, namely the problem of poor universality exists.
The technical scheme of the embodiment is mainly used for determining the situation of the master node in the distributed cluster and can be applied to the distributed cluster. A distributed cluster is made up of multiple servers, each of which can act as a node in the distributed cluster, all of which are subsequently described as nodes.
The distributed node comprises two types of nodes, one is a master node and a standby node, and the other is an arbitration node. The master node and the slave node can be used as a read node or a write node. The master node of the final use is determined from the master and slave nodes. The arbitration node can only act as a read node.
Meanwhile, the distributed cluster also comprises two stable states and three unstable states. The stable state refers to a state in which the current situation can be stably maintained under the condition that the network is stable and the cluster operates normally; the unstable state refers to a state that the state of the self can be actively modified under the condition that a certain time interval is exceeded and no task network message is received. It should be noted that two stable states include a main state and a standby state. If the current node is in the master state, it is stated that the current node may provide services within the cluster, typically including write operations that entail databases and message queues. That is, the current node is the master node of the distributed cluster. The standby state can be understood as that the current node can provide services to the cluster and generally bears the reading operation of the database and the message queue, namely, the current node is used as a common node, and the function of the current node is the same as that of the arbitration node. The three unstable states may be an initial state, a candidate state, and a primary silence state, respectively. The initial state is a state in which the node is automatically positioned when the cluster is started; the candidate state refers to a state in which the node serves as a candidate master node; the main silence state refers to a state that a node changes to a main node if the node does not receive a main heartbeat within a certain period of time.
In this embodiment, the master node and the slave node are used as the master node to be selected, and the arbitration node is used as the node to be used which is inconsistent with the master node type.
As shown in fig. 1, the method of this embodiment includes:
s110, determining a main node to be selected, which is consistent with the preset node type, according to the node type of each node to be used.
Wherein each server in the distributed cluster can be used as a node to be used. Each node to be used has a corresponding node type, e.g., a master node type and a non-master node type. The master node type is a type which can be used as a master node, namely, a node type which can provide read-write operation; the non-master node type refers to a type that cannot be used as a master node, i.e., a type that can only provide a read operation.
It should be noted that whether the server can be used as a master node or a slave node is related to the hardware performance of the server. The user can set the node type of each node in the distributed cluster according to the actual situation. The preset node type is a master node type that can be used as a master node. And taking the node to be used of the master node type as a master node to be selected. That is, the final determined master node is selected from the master nodes to be selected.
Specifically, each server in the distributed cluster may be used as a node to be used, and a node type of each node to be used is obtained. And taking the node to be used with the node type consistent with the preset node type as a main node to be selected.
In this embodiment, the preset node types include a master node type, and determining, according to the node types of the nodes to be used, a master node to be selected that is consistent with the preset node type includes: acquiring node types of nodes to be used; the node types comprise a main node type and a non-main node type; and taking the node to be used which is consistent with the type of the master node as the master node to be selected.
The node type of the node to be used is matched with the equipment performance corresponding to the node. If the device performance corresponding to the node is higher, the node type of the node can be set as a main node type, otherwise, the node type is set as a non-main node type.
Specifically, a node type of each node to be used in the distributed cluster may be obtained, for example, the node type is a master node type and a non-master node type, and the node to be used corresponding to the master node type is used as a master node to be selected.
In this embodiment, the stages of the distributed clusters are different, and the processing manners of the nodes to be used, which are inconsistent with the preset node types, are also different. Optionally, if the distributed cluster is in the starting stage, determining a node inconsistent with a preset node type from the nodes to be used, and updating the state identifier of the node from an initial identifier to a standby state identifier; if the distributed cluster is in the operation stage, the state identification of the node to be used, which is inconsistent with the preset node type, is kept unchanged. The startup phase may be understood as starting up each server in the distributed cluster, where each server is in an initial state, i.e. each node in the distributed cluster is in an initial state. The operation phase may be understood as that each node is in a normal use phase. The preset node type is a master node type. If the state identifier of the node is the standby state identifier, the node is mainly used for executing the reading operation of the message queue.
Specifically, if the distributed cluster is in the startup phase, the node status identifier of each distributed node is an initial status identifier, and the status identifier of the node to be used inconsistent with the main node type can be updated from the initial status identifier to a standby status identifier. If the distributed cluster is in the operation stage, the node to be used, the node type of which is not the main node type, is marked as the standby state identification, the standby state identification can be kept unchanged at the moment, the node to be used, which is consistent with the preset node type and is in the standby state identification, is taken as the main node to be selected.
Illustratively, assume that a distributed cluster includes five nodes to be used A, B, C, D, E. Wherein, the node types of the three nodes to be used of A, B, C are the main node type, the node types of the two nodes to be used of D, E are the non-main node type, and the node to be used D, E can be called an arbitration node. During the cluster startup phase, the node A, B, C, D, E to be used is in an initialized state. Referring to fig. 2, since the node type of the node D, E to be used is inconsistent with the preset master node type, the state identifier of the node D, E to be used may be marked as a standby state flag from the initial state, and then the heartbeat message starts to be broadcast to other nodes to enable the other nodes to determine that the node D, E to be used can perform a read operation. In the cluster operation stage, to redetermine the master node, the standby state identification of the node to be used D, E inconsistent with the preset node type (master node type) may be kept unchanged, that is, the standby state of the node to be used D, E is kept.
S120, determining theoretical waiting time length of the corresponding main node to be selected in each waiting state according to attribute information of the main node to be selected, and updating the state identification of the corresponding main node to be selected based on the theoretical waiting time length.
It should be noted that, if the to-be-selected master node is determined based on the startup phase, the to-be-selected master node may sequentially pass through the initial state, the candidate state, and the master mute state. If the primary node to be selected is determined based on the run phase, the primary node to be selected may pass through the candidate state and the primary mute state in sequence.
The attribute information may be information such as node priority of the master node to be selected, for example. The waiting state refers to a state that needs to be passed when the master node to be selected is taken as the master node, or each state that needs to be passed when the master node to be selected identified by the standby state is taken as the master node. The wait state includes at least one of an initial state, a candidate state, and a primary silence state. Each main node to be selected needs to last for a certain period of time in different waiting states, and the duration of time can be used as theoretical waiting duration. Namely, the waiting time determined from the attribute information is taken as the theoretical waiting time. The waiting state includes at least one of the above three states, and the theoretical waiting period includes a waiting period corresponding to the above three states, respectively.
It should be noted that, when the attribute information of each main node to be selected is different, the duration of each waiting state is also different; of course, even if the attribute information of each master node to be selected is the same, there may be a certain difference in the waiting time periods of the respective waiting states.
Specifically, for each main node to be selected, the waiting time length of the main node to be selected in the candidate state can be determined according to the node attribute information of the main node to be selected. And meanwhile, when the current main node to be selected is detected to enter the main silence state, determining the duration waiting time of the current main node in the main silence state. When the actual waiting time duration of the current main node to be selected in the main silence state is detected to reach the theoretical waiting time duration, the state identification of the current main node to be selected can be updated, and then the target main node is determined based on the updated state identification.
For example, the node A, B, C to be used is a master node to be selected, and when detecting that the master node to be selected reaches each waiting state, the theoretical waiting duration in each waiting state may be determined according to the attribute information of each master node to be selected.
In this embodiment, based on the above expression, it can be known that the waiting state includes a candidate state and a main silence state, and accordingly, the theoretical waiting duration information includes a candidate waiting duration in the candidate state and a silence waiting duration in the main silence state. Optionally, determining the theoretical waiting duration of the corresponding to-be-selected master node in each waiting state according to the attribute information of each to-be-selected master node includes: and determining the candidate waiting duration of the corresponding main node to be selected in the candidate state and the silence waiting duration of the main silence state according to the node priority in the attribute information.
Specifically, when it is detected that a certain to-be-selected master node is in a candidate state, the theoretical waiting duration of the to-be-selected master node in the candidate state can be determined according to the node priority of the to-be-selected master node, and optionally, the higher the priority level is, the shorter the theoretical waiting duration is. And establishing a corresponding relation between the node priority and the theoretical waiting time, wherein the corresponding relation comprises a plurality of node priorities, each node priority corresponds to one theoretical waiting time period, and the theoretical waiting time period with a time period which is waiting in a certain state can be randomly determined from the theoretical waiting time periods. Of course, when detecting that a certain to-be-selected master node is in the master silence state, the theoretical waiting duration of the to-be-selected master node in the master silence state, namely the master silence waiting duration, can still be determined according to the node priority.
In order to further improve the rationality of the determined theoretical waiting duration, in this embodiment, the waiting duration that each to-be-selected master node lasts in each path state may be determined in the following manner.
Optionally, for each main node to be selected, when detecting that the state identifier of the current main node to be selected is updated to be a candidate state identifier, determining a candidate waiting duration of the current main node to be selected in a candidate state according to the node priority of the current main node to be selected, the target time information of the updated candidate state identifier and the heartbeat duration information; and for each main node to be selected, when the state identifier of the current main node to be selected is detected to be updated into the main silence state identifier by the candidate state identifier, determining the silence waiting time of the current main node to be selected in the main silence state according to the node priority of the current main node to be selected and a preset value.
Wherein the node priority may be represented by a corresponding number, e.g. a number between 0 and 5. The priority identification of the node to be used of the non-master node type is 0, and the priority identification of the master node to be selected may be any number from 1 to 5. The user may be set according to the hardware performance of the server, wherein a larger number characterizes a higher node priority.
It will be appreciated that the candidate wait time duration for which the candidate state persists is determined based on node priority, target time information updated to the candidate state identification, and heartbeat time duration information. Correspondingly, the silence waiting time is determined according to the node priority of the main node to be selected and a preset value.
Specifically, a random algorithm is adopted to process the target time information, the heartbeat duration information and the identification of the node priority, and the candidate duration of the main node to be selected is obtained. For example, the formula level check (now-level-heart_time) is employed to determine candidate durations for each master node to be selected in a candidate state. The new represents the moment when the state identifier of the main node to be selected is updated to the candidate state identifier, namely, the target time information, the level represents the node priority identifier of the main node to be selected, and the heart_time represents the heartbeat duration information. Meanwhile, when the fact that the actual waiting time of a certain main node to be selected in the candidate state reaches the candidate waiting time is detected, the main silence state can be entered, namely, the state identifier of the main node to be selected is updated from the candidate state identifier to the main silence state identifier, and the silence waiting time in the main silence state can be determined according to a corresponding mode. For example, a random algorithm is used to determine the duration of the wait for the primary node to be selected to stay in the primary silence state. The random algorithm may be radom (3, 3+ (5-level)), where 3 and 5 may be preset values. Assuming that the node priority level is identified as 1, substituting the node priority level into a formula can obtain radom (3, 3+ (5-1)), and the silence waiting time can be any time length from 3ms to 7ms, and the specific time measurement unit can be set according to actual requirements.
S130, determining a target main node according to the state identification, broadcasting a main heartbeat message to each node to be used based on the target main node, so that each node to be used determines the target main node according to the received main heartbeat message, and updating the state identification of other main nodes to be selected into a standby state identification.
The target master node is a node which finally determines to provide the write operation. After determining the target master node, the master heartbeat message can be broadcast to all the nodes to be used (including all the nodes except the target master node) based on the target master node, so that after each other node to be used receives the master heartbeat message, the target master node can be determined according to the node identifier corresponding to the master heartbeat message, and meanwhile, the state identifier of each master node to be selected is updated to be the standby state identifier.
Specifically, when it is detected that the actual waiting duration of a certain to-be-selected master node in the master silence state reaches the silence waiting duration, and the state identifiers of other nodes are silence state identifiers corresponding to the master silence state or candidate state identifiers corresponding to the candidate state, the node can be used as the target master node.
In this embodiment, determining the target master node according to the state information may be: and the master node to be selected, of which the state identifier is updated to the master state identifier preferentially, is taken as a target master node.
The master state identifier refers to an identifier that the node can serve as a target master node.
Specifically, if the actual waiting duration of the to-be-selected master node in the master silence state reaches the silence waiting duration, the state identifier of the to-be-selected master node may be updated to be the master state identifier, and the to-be-selected master node is used as the target master node. Based on the above, only one node may be a master node in the distributed cluster at the same time, and therefore, the master node to be selected, which is preferentially put into the master state from the master silent state, is a target master node.
On the basis of the above exemplary embodiment, with continued reference to fig. 2, in the distributed cluster start-up phase, the priority levels of the master node A, B, C to be selected are in turn: a > B > C. When each main node to be selected is detected to enter the candidate state, the duration time in the candidate state can be determined according to the priority of each main node to be selected, for example, the higher the priority level is, the shorter the duration time in the candidate state is. At this time, the duration of the candidate state of the master node a to be selected may be the shortest, the waiting duration of the master node B to be selected may be the second, and the waiting duration of the master node C to be selected may be the longest. That is, the primary node a to be selected may enter the primary mute state preferentially, the primary node B to be selected is secondary, and the primary node C to be selected enters the primary mute state last. With continued reference to fig. 2, while the master node a to be selected is in the master silence state, B, C may enter the master silence state and may also be in the candidate state. That is, when the state identifier of the to-be-selected master node a is the master mute state identifier, the state identifier of the to-be-selected master node B, C may be the master mute state identifier or the candidate state identifier.
Referring to fig. 3, when detecting that the actual waiting time of the to-be-selected master node a in the master silence state reaches the silence waiting time, the to-be-selected master node a may enter the master state, i.e. the state identifier is updated from the silence state identifier to the master state identifier. The primary nodes B and C to be selected may be in a primary mute state or candidate state, i.e. the state identity is a mute state identity or candidate state identity. At this time, the master node a to be selected may be the target master node, i.e., the master node to be selected whose status identifier is changed from the master silent status identifier to the master status identifier preferentially. After determining the target master node a, the target master node a may send a master heartbeat message to the other four nodes to be used B, C, D, E, so that the other four nodes to be used determine that the master node is the node a to be used.
Referring to fig. 4, after the other four nodes B, C, D, E to be used receive the main heartbeat message, since the state identifier of the node D, E to be used is already the standby state identifier, only the state identifier of the main node B, C to be selected needs to be updated to the standby state identifier, that is, whether the main node to be selected is in the main silence state or the candidate state, the state identifier of the main node to be selected is updated to the standby state identifier as long as the main heartbeat message sent by the target main node is received, so that the corresponding read operation is performed.
According to the technical scheme, the waiting time of the main node to be selected, which is consistent with the preset node type, is determined from the nodes to be used, the waiting time of the main node to be selected in each state is determined according to the attribute information of the main node to be selected, and then the state identification of the corresponding main node to be selected is adjusted based on the waiting time, so that the target main node is determined from a plurality of main nodes to be selected according to the state identification; meanwhile, the problem that the determination of the master node is limited by the number of available nodes and the complexity of the distributed cluster and the universality is poor is solved, the effectiveness, convenience and universality of the determination of the master node are improved, and the use safety and the universality of the distributed cluster are further improved.
Fig. 5 is a schematic flow chart of a method for determining a target master node according to an embodiment of the present invention, and if at least one new node to be used is added under the condition that the target master node is determined, the node type of the node to be used may be the master node type or the non-master node type, and the node state of the newly added node to be used may be updated as follows. Wherein, the technical terms identical to or corresponding to the above embodiments are not repeated herein.
As shown in fig. 5, the method includes:
s210, determining a main node to be selected, which is consistent with the preset node type, according to the node type of each node to be used.
S220, determining theoretical waiting time length of the corresponding main node to be selected in each waiting state according to the attribute information of the main node to be selected, and updating the state identification of the corresponding main node to be selected based on the theoretical waiting time length.
In this embodiment, updating the state identifier of the corresponding master node to be selected based on the theoretical waiting duration may be: for each main node to be selected, if the current main node to be selected is detected to enter a candidate state, updating the state identifier of the main node to be selected into a candidate state identifier, and when the actual duration of the current main node to be selected in the candidate state is detected to reach the candidate waiting duration, entering the main silence state, and updating the state identifier of the current main node to be selected from the candidate state identifier into a main silence state identifier; and if the fact that the actual silence duration of the current main node to be selected in the main silence state reaches the silence waiting duration is detected, updating the state identifier of the current main node to be selected from the main silence state identifier to the main state identifier.
The candidate state identifier is an identifier corresponding to the candidate state. The primary silence state identification is a silence state identification corresponding to the primary silence state. The master state identifier refers to an identifier that a master node to be selected is a target master node.
S230, determining a target main node according to the state identification, broadcasting a main heartbeat message to each node to be used based on the target main node, so that each node to be used determines the target main node according to the received main heartbeat message, and updating the state identification of other main nodes to be selected into a standby state identification.
S240, if a newly added node to be used is detected, and the node to be used receives a main heartbeat message sent by the target main node, updating the state identifier of the node to be used into a standby state identifier.
Based on the above technical solution, if at least one node to be used is newly added, the newly added node to be used may be processed based on S210 to S230, so as to balance the distributed cluster.
In an exemplary embodiment, two nodes to be used are newly added in the cluster, where one node type of the nodes to be used is a master node type, denoted as F, and the other node type of the nodes to be used is a non-master node type, denoted as G. Referring to fig. 6, nodes F and G to be used in the initialized state are in the initialized state. Referring to fig. 7, after initializing the candidate state by using the node F, if a main heartbeat message broadcasted by the target main node a is received, the candidate state may be converted into a standby state identifier, that is, the candidate state is used as a read operation node. The node G to be used is an arbitration node, and can be directly converted into a standby state after initialization.
According to the technical scheme, when the node to be used is newly added under the condition that the target main node is determined, the main heartbeat message can be broadcast to the node to be used newly based on the target main node, so that after the node to be used newly receives the main heartbeat message, the state identifier of the node to be used newly is updated to be an alternative state identifier, corresponding reading operation is executed, the distributed cluster can still normally provide corresponding service under the condition of the node to be used newly added, and the technical effect of data processing safety is improved.
Fig. 8 is a schematic flow chart of a method for determining a target master node according to an embodiment of the present invention, on the basis of the foregoing embodiment, the target master node may not provide a corresponding service if a network outage or power outage occurs, and at this time, the target master node may be determined from a to-be-used node whose state is identified as a standby state and is consistent with a preset node type, and a detailed description of the embodiment will be described. Wherein, the technical terms identical to or corresponding to the above embodiments are not repeated herein.
As shown in fig. 8, the method includes:
S310, determining a main node to be selected, which is consistent with the preset node type, according to the node type of each node to be used.
S320, determining the theoretical waiting time length of the corresponding main node to be selected in each waiting state according to the attribute information of each main node to be selected, and updating the state identification of the corresponding main node to be selected based on the theoretical waiting time length.
S330, determining a target main node according to the state identification, broadcasting a main heartbeat message to each node to be used based on the target main node, so that each node to be used determines the target main node according to the received main heartbeat message, and updating the state identification of other main nodes to be selected into a standby state identification.
And S340, when the target main node is detected to be offline, determining the main node to be selected, which is consistent with the preset node type, from all the nodes to be used of the standby state identification, re-determining the target main node according to the attribute information of all the main nodes to be selected, and keeping the state identification of the nodes to be used, which is inconsistent with the preset node type, unchanged as the standby state identification.
Wherein, the offline can be understood that the target master node does not provide read-write operation. The nodes to be used of the standby state identification comprise a main node type and a non-main node type, the target main node can be determined from the nodes to be used of the main node type, and the specific determination mode can repeatedly execute S310 to S330.
Specifically, when the target master node is detected to be offline, a node consistent with a preset node type (master node type) can be determined from all the nodes to be used, the states of which are identified as standby states, and the node is used as the master node to be selected. When the main node to be selected enters the candidate state, the candidate waiting time length in the candidate state can be determined according to the priority, and the main silence state is entered when the actual waiting time length reaches the candidate waiting time length. Meanwhile, the silence waiting time length of the main node to be selected in the main silence state can still be determined according to the priority, and when the fact that the actual silence waiting time length of the main node to be selected reaches the silence waiting time length is detected, the state identifier of the main node to be selected is updated from the silence state identifier to the main state identifier. If the main node to be selected is the first main state identifier, the main node to be selected can be used as the target main node.
For example, referring to fig. 9, at a moment in time, a target master node a in the cluster goes offline, and a node to be used in the standby state identifier, which matches the master node type, includes a node B, C, F. When the node to be used B, C, F monitors that the primary heartbeat is time-out, that is, when the heartbeat message broadcast by the target primary node a is not received for a long time, the node to be used B, C, F may enter a candidate state as the primary node to be selected, see fig. 10, and repeatedly execute S310 to S330 to determine the target primary node from the primary nodes to be selected B, C, F. If the determined target master node is C, the status identifier of the master node B, F to be selected is updated to the standby status identifier to perform the read operation, see fig. 11. Meanwhile, the node to be used, which is inconsistent with the preset node type, in the standby state identification keeps the standby state identification unchanged, and corresponding reading operation is still executed.
It should be noted that, the candidate waiting duration and the silence waiting duration are determined by adopting a random algorithm, so that a node to be used becomes a target master node first, and when other master nodes to be selected receive a heartbeat message broadcast by the target master node, the node can be converted into a standby state.
It should be noted that, when a master node to be selected is a target master node, due to factors such as a network, a broadcast master heartbeat message is not received by a node in a master silence state, and at this time, the node in the master silence state becomes the master node. The method comprises the steps that when two main nodes receive heartbeat messages broadcasted by each other, the state identification of the main node with lower priority level can be updated to be the standby state identification, and the node identification with higher priority level is reserved as the main state identification, namely the main state identification is the target main node. Of course, if the priority levels of the two master nodes are the same, the measure to be taken may be to redetermine the target master node, or to update the status identifier of any one master node as the target master node and the status identifier of the other master node as the standby status identifier, and perform the read operation.
In other words, the technical scheme realizes the stability and reliability of the target master node in the cluster, does not depend on third-party middleware such as a database and the like, and reduces the complexity of the system. Further, the target master node is determined in the mode, so that the system has good compatibility, is easier to expand for a multi-language environment, and reduces the coupling with a third-party system. Furthermore, when the target master node is redetermined after the target master node is offline, the number, the parity and the like of the surviving nodes are not depended, and the requirement on the reliability of the system hardware is reduced. Finally, the existing small-sized distributed system is built by adopting a common network card mode more than three network results built by a management network, a storage network and a service network. When the traffic volume increases suddenly (such as under the condition that a certain website is active), the network disk IO can generate backlog, and the heartbeat messages between the nodes can possibly have delay, namely the main node is considered to be offline, at the moment, the prior art can possibly generate frequent main selection, so that the service is always unavailable, and the technical scheme does not depend on response messages of other nodes, so that the method has stronger advantage in performance.
According to the technical scheme, when the target main node is detected to be offline, the main node to be selected can be determined from the nodes to be used, which are consistent with the main node types, in the standby state identification, and the target main node is determined from the main nodes to be selected according to the attribute information of each main node to be selected, so that the target main node can be quickly and conveniently determined on the basis of being independent of other databases and the number of the nodes, and the convenience and the universality of determining the target main node are improved.
Fig. 12 is a schematic structural diagram of an apparatus for determining a master node according to an embodiment of the present invention, where the apparatus may be integrated in a distributed cluster, and the apparatus includes: a master node to be selected determination module 410, a status information determination module 420, and a target master node determination module 430.
The to-be-selected master node determining module 410 is configured to determine, according to the node types of the to-be-used nodes, a to-be-selected master node consistent with the preset node type; the state information determining module 420 is configured to determine a theoretical waiting duration of each waiting state of the corresponding to-be-selected master node according to attribute information of each to-be-selected master node, and update a state identifier of the corresponding to-be-selected master node based on the theoretical waiting duration; the target master node determining module 430 is configured to determine a target master node according to the state identifier, and broadcast a master heartbeat message to each node to be used based on the target master node, so that each node to be used determines the target master node according to the received master heartbeat message, and updates the state identifiers of other nodes to be selected to be standby state identifiers.
On the basis of the above technical solution, the preset node type includes a master node type, and the to-be-selected master node determining module includes:
a node type obtaining unit, configured to obtain a node type of each node to be used; the node types comprise a main node type and a non-main node type;
and the main node to be selected determining unit is used for taking the node to be used which is consistent with the main node type as the main node to be selected.
On the basis of the technical scheme, the device further comprises: a processing module, comprising:
the first processing unit is used for determining a node inconsistent with a preset node type from the nodes to be used and updating the state identifier of the node from an initial identifier to a standby state identifier if the distributed cluster is in a starting stage;
and the second processing unit is used for keeping the state identification of the node to be used inconsistent with the preset node type unchanged if the distributed cluster is in the operation stage.
On the basis of the technical scheme, the waiting states comprise candidate states and main silence states, the theoretical waiting time length comprises candidate waiting time lengths in the candidate states and silence waiting time lengths in the main silence states, and the state information determining module is further used for:
And determining the candidate waiting duration of the corresponding main node to be selected in the candidate state and the silence waiting duration of the main silence state according to the node priority in the attribute information.
On the basis of the technical scheme, the state information determining module comprises:
the candidate waiting time length determining unit is used for determining candidate waiting time length of the current main node to be selected in a candidate state according to node priority of the current main node to be selected, target time information updated as the candidate state identifier and heartbeat time length information when the state identifier of the current main node to be selected is detected to be updated as the candidate state identifier for each main node to be selected;
and the silence waiting time length determining unit is used for determining the silence waiting time length of the current main node to be selected in the main silence state according to the node priority and the preset value of the current main node to be selected when the state identifier of the current main node to be selected is updated to the main silence state identifier by the candidate state identifier according to each main node to be selected.
On the basis of the technical scheme, the target main node determining module comprises:
the first identifier updating unit is used for updating the state identifier of the main node to be selected into a candidate state identifier if the current main node to be selected is detected to enter the candidate state for each main node to be selected, entering the main silence state if the actual duration of the current main node to be selected in the candidate state reaches the candidate waiting duration, and updating the state identifier of the current main node to be selected from the candidate state identifier into the main silence state identifier;
And the second identifier updating unit is used for updating the state identifier of the current main node to be selected from the main silence state identifier to the main state identifier if the actual silence duration of the current main node to be selected in the main silence state is detected to reach the silence waiting duration.
On the basis of the technical scheme, the target master node determining module is further used for:
and the master node to be selected, of which the state identifier is updated to the master state identifier preferentially, is taken as a target master node.
On the basis of the technical scheme, the target main node determining module comprises:
the target master node determining unit is used for determining a target master node from the master nodes to be selected corresponding to at least two state identifiers by adopting a random algorithm if the fact that the at least two state identifiers are updated to be the master state identifiers at the same time is detected;
and the main heartbeat message broadcasting unit is used for broadcasting main heartbeat messages to other nodes to be used based on the target main node.
On the basis of the technical scheme, the device further comprises:
and the first target main node redetermining module is used for determining a main node to be selected which is consistent with the preset node type from all the nodes to be used of the standby state identification when the target main node is detected to be offline, redetermining the target main node according to the attribute information of all the main nodes to be selected, and keeping the state identification of the nodes to be used which are inconsistent with the preset node type unchanged.
On the basis of the technical scheme, the device further comprises:
and if the first target main node redetermining module detects a newly added node to be used, and the node to be used receives a main heartbeat message sent by the target main node, updating the state identifier of the node to be used into a standby state identifier.
According to the technical scheme, the waiting time of the main node to be selected, which is consistent with the preset node type, is determined from the nodes to be used, the waiting time of the main node to be selected in each state is determined according to the attribute information of the main node to be selected, and then the state identification of the corresponding main node to be selected is adjusted based on the waiting time, so that the target main node is determined from a plurality of main nodes to be selected according to the state identification; meanwhile, the problem that the determination of the master node is limited by the number of available nodes and the complexity of the distributed cluster and the universality is poor is solved, the effectiveness, convenience and universality of the determination of the master node are improved, and the use safety and the universality of the distributed cluster are further improved.
The device for determining the master node provided by the embodiment of the invention can execute the method for determining the master node provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method.
It should be noted that each unit and module included in the above apparatus are only divided according to the functional logic, but not limited to the above division, so long as the corresponding functions can be implemented; in addition, the specific names of the functional units are also only for distinguishing from each other, and are not used to limit the protection scope of the embodiments of the present invention.
Fig. 13 is a schematic structural diagram of an electronic device according to an embodiment of the present invention. Fig. 13 shows a block diagram of an exemplary electronic device 50 suitable for use in implementing the embodiments of the present invention. The electronic device 50 shown in fig. 13 is merely an example and should not be construed as limiting the functionality and scope of use of embodiments of the present invention.
As shown in fig. 13, the electronic device 50 is in the form of a general purpose computing device. Components of electronic device 50 may include, but are not limited to: one or more processors or processing units 501, a system memory 502, and a bus 503 that connects the various system components (including the system memory 502 and processing units 501).
Bus 503 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, or a local bus using any of a variety of bus architectures. By way of example, and not limitation, such architectures include Industry Standard Architecture (ISA) bus, micro channel architecture (MAC) bus, enhanced ISA bus, video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
Electronic device 50 typically includes a variety of computer system readable media. Such media can be any available media that is accessible by electronic device 50 and includes both volatile and nonvolatile media, removable and non-removable media.
The system memory 502 may include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM) 504 and/or cache memory 505. Electronic device 50 may further include other removable/non-removable, volatile/nonvolatile computer system storage media. By way of example only, storage system 506 may be used to read from or write to non-removable, nonvolatile magnetic media (not shown in FIG. 13, commonly referred to as a "hard disk drive"). Although not shown in fig. 13, a magnetic disk drive for reading from and writing to a removable non-volatile magnetic disk (e.g., a "floppy disk"), and an optical disk drive for reading from or writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In such cases, each drive may be coupled to bus 503 through one or more data medium interfaces. Memory 502 may include at least one program product having a set (e.g., at least one) of program modules configured to carry out the functions of embodiments of the invention.
A program/utility 508 having a set (at least one) of program modules 507 may be stored, for example, in memory 502, such program modules 507 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each or some combination of which may include an implementation of a network environment. Program modules 507 typically perform the functions and/or methods of the described embodiments of the invention.
The electronic device 50 may also communicate with one or more external devices 509 (e.g., keyboard, pointing device, display 510, etc.), one or more devices that enable a user to interact with the electronic device 50, and/or any device (e.g., network card, modem, etc.) that enables the electronic device 50 to communicate with one or more other computing devices. Such communication may occur through an input/output (I/O) interface 511. Also, the electronic device 50 may communicate with one or more networks such as a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network, such as the Internet, through a network adapter 512. As shown, the network adapter 512 communicates with other modules of the electronic device 50 over the bus 503. It should be appreciated that although not shown in fig. 13, other hardware and/or software modules may be used in connection with electronic device 50, including, but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, data backup storage systems, and the like.
The processing unit 501 executes various functional applications and data processing by running a program stored in the system memory 502, for example, implementing the method for determining a target master node provided by the embodiment of the present invention.
Embodiments of the present invention also provide a storage medium containing computer-executable instructions for performing a method of determining a target master node when executed by a computer processor.
The method comprises the following steps:
determining a main node to be selected, which is consistent with a preset node type, according to the node type of each node to be used;
according to the attribute information of each main node to be selected, determining the theoretical waiting time length of the corresponding main node to be selected in each waiting state, and updating the state identification of the corresponding main node to be selected based on the theoretical waiting time length;
and determining a target main node according to the state identification, broadcasting a main heartbeat message to each node to be used based on the target main node, so that each node to be used determines the target main node according to the received main heartbeat message, and updating the state identification of other main nodes to be selected into a standby state identification.
The computer storage media of embodiments of the invention may take the form of any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples (a non-exhaustive list) of the computer-readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for embodiments of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, smalltalk, C ++ and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computer (for example, through the Internet using an Internet service provider).
Note that the above is only a preferred embodiment of the present invention and the technical principle applied. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, while the invention has been described in connection with the above embodiments, the invention is not limited to the embodiments, but may be embodied in many other equivalent forms without departing from the spirit or scope of the invention, which is set forth in the following claims.
Claims (12)
1. A method for determining a master node, for use in a distributed cluster, comprising:
determining a main node to be selected, which is consistent with a preset node type, according to the node type of each node to be used;
according to the attribute information of each main node to be selected, determining the theoretical waiting time length of the corresponding main node to be selected in each waiting state, and updating the state identification of the corresponding main node to be selected based on the theoretical waiting time length;
determining a target main node according to the state identification, broadcasting a main heartbeat message to each node to be used based on the target main node, so that each node to be used determines the target main node according to the received main heartbeat message, and updating the state identifications of other main nodes to be selected into standby state identifications;
The waiting states comprise candidate states and main silence states, the theoretical waiting time length comprises candidate waiting time lengths in the candidate states and silence waiting time lengths in the main silence states, and the determining of the theoretical waiting time lengths of the corresponding main nodes to be selected in the waiting states according to the attribute information of the main nodes to be selected comprises the following steps:
and determining the candidate waiting duration of the corresponding main node to be selected in the candidate state and the silence waiting duration of the main silence state according to the node priority in the attribute information.
2. The method according to claim 1, wherein the preset node type includes a master node type, and the determining, according to the node type of each node to be used, the master node to be selected that is consistent with the preset node type includes:
acquiring node types of nodes to be used; the node types comprise a main node type and a non-main node type;
and taking the node to be used which is consistent with the type of the master node as the master node to be selected.
3. The method as recited in claim 2, further comprising:
if the distributed cluster is in the starting stage, determining a node inconsistent with a preset node type from the nodes to be used, and updating the state identifier of the node from an initial identifier to a standby state identifier;
If the distributed cluster is in the operation stage, the state identification of the node to be used, which is inconsistent with the preset node type, is kept unchanged.
4. The method according to claim 1, wherein the determining, according to the node priority in the attribute information, a candidate waiting duration for the corresponding master node to be selected to continue in the candidate state, and a silence waiting duration for the master silence state, includes:
for each main node to be selected, when the state identifier of the current main node to be selected is detected to be updated to be a candidate state identifier, determining the candidate waiting time of the current main node to be selected in a candidate state according to the node priority of the current main node to be selected, the target time information updated to be the candidate state identifier and the heartbeat time information;
and for each main node to be selected, when the state identifier of the current main node to be selected is detected to be updated into the main silence state identifier by the candidate state identifier, determining the silence waiting time of the current main node to be selected in the main silence state according to the node priority of the current main node to be selected and a preset value.
5. The method of claim 4, wherein updating the state identification of the corresponding master node to be selected based on the theoretical wait time period comprises:
For each main node to be selected, if the current main node to be selected is detected to enter a candidate state, updating the state identifier of the main node to be selected into a candidate state identifier, and when the actual duration of the current main node to be selected in the candidate state is detected to reach the candidate waiting duration, entering the main silence state, and updating the state identifier of the current main node to be selected from the candidate state identifier into a main silence state identifier;
and if the fact that the actual silence duration of the current main node to be selected in the main silence state reaches the silence waiting duration is detected, updating the state identifier of the current main node to be selected from the main silence state identifier to the main state identifier.
6. The method of claim 1, wherein said determining a target master node from said status identification comprises:
and the master node to be selected, of which the state identifier is updated to the master state identifier preferentially, is taken as a target master node.
7. The method according to claim 1, wherein the determining a target master node according to the status identifier, and broadcasting a master heartbeat message to each node to be used based on the target master node, includes:
If at least two state identifiers are detected to be updated to be the main state identifiers at the same time, determining a target main node from main nodes to be selected corresponding to the at least two state identifiers by adopting a random algorithm;
and broadcasting a main heartbeat message to other nodes to be used based on the target main node.
8. The method as recited in claim 1, further comprising:
when the target main node is detected to be offline, determining main nodes to be selected, which are consistent with the preset node types, from all the nodes to be used of the standby state identification, re-determining the target main node according to the attribute information of all the main nodes to be selected, and keeping the state identification of the nodes to be used, which are inconsistent with the preset node types, unchanged as the standby state identification.
9. The method of claim 1, further comprising, after determining the target master node:
and if the newly added node to be used is detected, and the node to be used receives the main heartbeat message sent by the target main node, updating the state identifier of the node to be used into a standby state identifier.
10. An apparatus for determining a master node, configured in a distributed cluster, comprising:
The to-be-selected main node determining module is used for determining to-be-selected main nodes consistent with the preset node types according to the node types of the to-be-used nodes;
the state information determining module is used for determining the theoretical waiting time length of the corresponding main node to be selected in each waiting state according to the attribute information of each main node to be selected, and updating the state identification of the corresponding main node to be selected based on the theoretical waiting time length;
the target master node determining module is used for determining a target master node according to the state identification, broadcasting a master heartbeat message to each node to be used based on the target master node, so that each node to be used determines the target master node according to the received master heartbeat message, and updating the state identification of other master nodes to be selected into a standby state identification;
the status information determining module includes:
the waiting states comprise candidate states and main silence states, the theoretical waiting time length comprises candidate waiting time lengths in the candidate states and silence waiting time lengths in the main silence states, and the candidate waiting time lengths for the corresponding main nodes to be selected to be continuously in the candidate states and the silence waiting time lengths for the corresponding main nodes to be selected to be continuously in the main silence states are determined according to node priorities in the attribute information.
11. An electronic device, the electronic device comprising:
one or more processors;
storage means for storing one or more programs,
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method of determining a master node of any of claims 1-9.
12. A storage medium containing computer executable instructions which, when executed by a computer processor, are for performing the method of determining a master node as claimed in any of claims 1 to 9.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210033330.5A CN114422521B (en) | 2022-01-12 | 2022-01-12 | Method and device for determining master node, electronic equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210033330.5A CN114422521B (en) | 2022-01-12 | 2022-01-12 | Method and device for determining master node, electronic equipment and storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN114422521A CN114422521A (en) | 2022-04-29 |
CN114422521B true CN114422521B (en) | 2024-04-05 |
Family
ID=81274235
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210033330.5A Active CN114422521B (en) | 2022-01-12 | 2022-01-12 | Method and device for determining master node, electronic equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114422521B (en) |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105554106A (en) * | 2015-12-15 | 2016-05-04 | 上海仪电(集团)有限公司 | Memcache distributed caching system |
CN111372272A (en) * | 2020-03-02 | 2020-07-03 | 普联技术有限公司 | Method and device for recovering abnormity of wireless bridging network |
CN111538763A (en) * | 2020-04-24 | 2020-08-14 | 咪咕文化科技有限公司 | Method for determining main node in cluster, electronic equipment and storage medium |
CN111641522A (en) * | 2020-05-25 | 2020-09-08 | 杭州安恒信息技术股份有限公司 | Method, system and computer equipment for node switching |
CN113489149A (en) * | 2021-07-01 | 2021-10-08 | 广东电网有限责任公司 | Power grid monitoring system service master node selection method based on real-time state perception |
Family Cites Families (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20060031429A1 (en) * | 2004-08-06 | 2006-02-09 | Sharp Laboratories Of America, Inc. | Central coordinator selection in ad hoc network |
US10346430B2 (en) * | 2010-12-23 | 2019-07-09 | Mongodb, Inc. | System and method for determining consensus within a distributed database |
US8560626B2 (en) * | 2011-01-13 | 2013-10-15 | Vmware, Inc. | Selecting a master node using a suitability value |
US10523498B2 (en) * | 2016-12-23 | 2019-12-31 | Sierra Nevada Corporation | Multi-broker messaging and telemedicine database replication |
CN109815049B (en) * | 2017-11-21 | 2021-03-26 | 北京金山云网络技术有限公司 | Node downtime recovery method and device, electronic equipment and storage medium |
-
2022
- 2022-01-12 CN CN202210033330.5A patent/CN114422521B/en active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105554106A (en) * | 2015-12-15 | 2016-05-04 | 上海仪电(集团)有限公司 | Memcache distributed caching system |
CN111372272A (en) * | 2020-03-02 | 2020-07-03 | 普联技术有限公司 | Method and device for recovering abnormity of wireless bridging network |
CN111538763A (en) * | 2020-04-24 | 2020-08-14 | 咪咕文化科技有限公司 | Method for determining main node in cluster, electronic equipment and storage medium |
CN111641522A (en) * | 2020-05-25 | 2020-09-08 | 杭州安恒信息技术股份有限公司 | Method, system and computer equipment for node switching |
CN113489149A (en) * | 2021-07-01 | 2021-10-08 | 广东电网有限责任公司 | Power grid monitoring system service master node selection method based on real-time state perception |
Non-Patent Citations (5)
Title |
---|
Facility networking with IP over RS485: Packet control for master-slave cascaded networks;Hideya Ochiai等;《2014 IEEE International Conference on Smart Grid Communications (SmartGridComm)》;全文 * |
Redis集群可靠性的研究与优化;李D;顾乃杰;黄增士;任开新;;计算机工程(05);全文 * |
分布式多机选举模型中负载均衡的应用;杨锐;;科技信息(学术研究)(36);全文 * |
增量同步约束条件下的多节点间主节点选举算法;谈兴秋;;现代电子技术(14);全文 * |
数据服务多节点主备切换设计方法;朱建红;陈柯;;指挥信息***与技术(06);全文 * |
Also Published As
Publication number | Publication date |
---|---|
CN114422521A (en) | 2022-04-29 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2019205371A1 (en) | Server, message allocation method, and storage medium | |
WO2019179026A1 (en) | Electronic device, method for automatically generating cluster access domain name, and storage medium | |
US8745362B2 (en) | Operating system aware branch predictor using a dynamically reconfigurable branch history table | |
CN103970520A (en) | Resource management method and device in MapReduce framework and framework system with device | |
US20200249969A1 (en) | Electronic device having multi-operating system and method for managing dynamic memory for same | |
KR20210083222A (en) | Method, apparatus, device and storage medium for processing voice data | |
CN112346834A (en) | Database request processing method and device, electronic equipment and medium | |
CN112925796A (en) | Write consistency control method, device, equipment and storage medium | |
CN114422521B (en) | Method and device for determining master node, electronic equipment and storage medium | |
CN108319470B (en) | Method, device and equipment for creating OS starting item and readable storage medium | |
CN113986135B (en) | Method, device, equipment and storage medium for processing request | |
CN107168776B (en) | Event statistical method, device, equipment and storage medium | |
CN115878333A (en) | Method, device and equipment for judging consistency between process groups | |
US20230096015A1 (en) | Method, electronic deviice, and computer program product for task scheduling | |
WO2023279875A1 (en) | Bootloader startup procedure monitoring method and apparatus, embedded device, and storage medium | |
CN110058866B (en) | Cluster component installation method and device | |
CN109460291B (en) | Electronic device, method for elastically controlling server cluster and storage medium | |
CN107704399B (en) | Method and device for storing data | |
CN106484536B (en) | IO scheduling method, device and equipment | |
CN110928582B (en) | Information processing apparatus and method of configuring target device of information processing apparatus | |
CN112817769B (en) | Game resource dynamic caching method and device, storage medium and electronic equipment | |
CN114281604B (en) | Data recovery method and device, electronic equipment and storage medium | |
CN114978895B (en) | Starting method, system, equipment and computer readable storage medium | |
CN117112249A (en) | Message processing method and device, medium and electronic equipment | |
US20160028592A1 (en) | Information Processing System, Information Processing Method and Medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |