CN111355600A - Method and device for determining main node - Google Patents

Method and device for determining main node Download PDF

Info

Publication number
CN111355600A
CN111355600A CN201811569603.8A CN201811569603A CN111355600A CN 111355600 A CN111355600 A CN 111355600A CN 201811569603 A CN201811569603 A CN 201811569603A CN 111355600 A CN111355600 A CN 111355600A
Authority
CN
China
Prior art keywords
node
cluster
determining
master
current
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.)
Granted
Application number
CN201811569603.8A
Other languages
Chinese (zh)
Other versions
CN111355600B (en
Inventor
田园
王朝辉
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hangzhou Hikvision Digital Technology Co Ltd
Original Assignee
Hangzhou Hikvision Digital Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Hangzhou Hikvision Digital Technology Co Ltd filed Critical Hangzhou Hikvision Digital Technology Co Ltd
Priority to CN201811569603.8A priority Critical patent/CN111355600B/en
Publication of CN111355600A publication Critical patent/CN111355600A/en
Application granted granted Critical
Publication of CN111355600B publication Critical patent/CN111355600B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/06Management of faults, events, alarms or notifications
    • H04L41/0654Management of faults, events, alarms or notifications using network fault recovery
    • H04L41/0668Management of faults, events, alarms or notifications using network fault recovery by dynamic selection of recovery network elements, e.g. replacement by the most appropriate element after failure
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/30Decision processes by autonomous network management units using voting and bidding
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Hardware Redundancy (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The embodiment of the application provides a master node determining method and device, aiming at one node in a cluster, when the master node of the cluster needs to be determined again, the node can determine a current control node from the nodes included in the cluster, and based on the control node, the current master node of the cluster is determined from the nodes included in the cluster. Based on the master node determining method of the embodiment, when the master node of the cluster needs to be determined again, the node in the cluster does not need to modify the node identifier of the master node recorded in the cluster file system, and it can be understood that even if the cluster file system is in an unreadable state, the node in the cluster can determine the master node, and thus the probability of cluster network service interruption can be reduced.

Description

Method and device for determining main node
Technical Field
The present application relates to the field of computer network technologies, and in particular, to a method and an apparatus for determining a master node.
Background
A cluster is a distributed system with high reliability and scalability, and a cluster may generally be composed of a plurality of independent servers, and the servers in the cluster may be referred to as nodes. During the cluster operation process, one node needs to be determined from a plurality of nodes in the cluster as a Master (Master), which may be called a Master node. The master node and the other nodes are jointly responsible for the network traffic processing of the cluster.
In the prior art, the master node may be generally determined according to a cluster file system. The cluster file system may be composed of storage space provided by each node in the cluster, and each node may manage data stored in the cluster file system. The method for determining the main node according to the cluster file system can comprise the following steps: the cluster file system may record a node identifier of a master node, and if the current master node fails, the master node needs to be determined again, and each node in the cluster may initiate a process of modifying the node identifier.
However, when a node in the cluster fails, the cluster file system may be in an unreadable state, and if the current master node fails, the node that has not failed in the cluster cannot re-determine the master node through the cluster file system, which may cause interruption of network services of the cluster.
Disclosure of Invention
The embodiment of the application aims to provide a method and a device for determining a master node, which can reduce the probability of cluster network service interruption. The specific technical scheme is as follows:
in a first aspect, in order to achieve the above object, an embodiment of the present application discloses a master node determining method, where the method is applied to each node in a cluster, and for a node in the cluster, the method executed by the node includes:
when the master node of the cluster needs to be determined again, determining a current control node from nodes included in the cluster, wherein the control node is a node used for controlling the data consistency of the cluster;
and determining the current main node of the cluster from the nodes included in the cluster based on the control node.
Optionally, when the master node of the cluster needs to be re-determined, determining a current control node from nodes included in the cluster, including:
when detecting that a main node of the cluster fails, determining a joining sequence of nodes which do not fail in the cluster to join the cluster;
and determining the node positioned at the first preset position in the adding sequence as the current control node.
Optionally, when the master node of the cluster needs to be re-determined, determining a current control node from nodes included in the cluster, including:
when detecting that a main node of the cluster fails, sending a control node election message to other nodes which do not fail currently in the cluster, wherein the control node election message carries a node identifier of the node and a transaction identifier for identifying the control node election message sent by the node this time;
and determining the current control node according to the size of the node identifier and the size of the transaction identifier carried in the received control node election message sent by other nodes.
Optionally, the determining, based on the control node, a current master node of the cluster from nodes included in the cluster includes:
and determining the control node as the current master node of the cluster.
Optionally, the determining, based on the control node, a current master node of the cluster from nodes included in the cluster includes:
if the node is not the control node, sending a master node election message to the control node; when receiving a message for determining election sent by the control node, determining that the node is the current main node of the cluster; when the election determining message sent by the control node is not received and the main node determining message sent by the control node is received, determining the node to which the node identifier carried in the main node determining message belongs as the current main node of the cluster;
if the node is the control node, according to the received sending sequence of the master node election messages, determining the node which sends the master node election messages located at the second preset position in the sending sequence as the current master node of the cluster, sending the determined election messages to the current master node of the cluster, and sending the master node determination messages carrying the node identification of the current master node of the cluster to nodes except the current master node of the cluster.
Optionally, the determining, according to the received sending sequence of the master node election message, a node that sends a master node election message located at a second preset position in the sending sequence as the current master node of the cluster includes:
and determining the node which is the first node to send the master node election message as the current master node of the cluster according to the sending sequence of the received master node election messages.
In a second aspect, in order to achieve the above object, an embodiment of the present application discloses a master node determining apparatus, where the apparatus is applied to each node in a cluster, and for a node in the cluster, the apparatus applied to the node includes:
a first determining module, configured to determine a current control node from nodes included in the cluster when a master node of the cluster needs to be re-determined, where the control node is a node used for controlling data consistency of the cluster;
and the second determining module is used for determining the current main node of the cluster from the nodes included in the cluster based on the control node.
Optionally, the first determining module is specifically configured to determine, when it is detected that a master node of the cluster fails, a join order in which a node that does not currently fail in the cluster joins the cluster;
and determining the node positioned at the first preset position in the adding sequence as the current control node.
Optionally, the first determining module is specifically configured to, when it is detected that a master node of the cluster fails, send a control node election message to other nodes in the cluster that do not currently fail, where the control node election message carries a node identifier of the node and a transaction identifier used to identify the control node election message sent by the node this time;
and determining the current control node according to the size of the node identifier and the size of the transaction identifier carried in the received control node election message sent by other nodes.
Optionally, the second determining module is specifically configured to determine the control node as the current master node of the cluster.
Optionally, the second determining module is specifically configured to send a master node election message to the control node if the node is not the control node; when receiving a message for determining election sent by the control node, determining that the node is the current main node of the cluster; when the election determining message sent by the control node is not received and the main node determining message sent by the control node is received, determining the node to which the node identifier carried in the main node determining message belongs as the current main node of the cluster;
if the node is the control node, according to the received sending sequence of the master node election messages, determining the node which sends the master node election messages located at the second preset position in the sending sequence as the current master node of the cluster, sending the determined election messages to the current master node of the cluster, and sending the master node determination messages carrying the node identification of the current master node of the cluster to nodes except the current master node of the cluster.
Optionally, the second determining module is specifically configured to determine, according to the sending sequence of the received master node election message, a first node that sends the master node election message as the current master node of the cluster.
In another aspect of this application, in order to achieve the above object, an embodiment of this application further discloses an electronic device, where the electronic device includes a processor, a communication interface, a memory, and a communication bus, where the processor, the communication interface, and the memory complete communication with each other through the communication bus;
the memory is used for storing a computer program;
the processor is configured to implement the master node determining method according to the first aspect when executing the program stored in the memory.
In yet another aspect of this embodiment, there is also provided a computer-readable storage medium having stored therein instructions which, when run on a computer, implement the master node determination method according to the first aspect described above.
In another aspect of this embodiment, a computer program product containing instructions is provided, which when executed on a computer, causes the computer to execute the master node determining method according to the first aspect.
The embodiment of the application provides a master node determining method, aiming at one node in a cluster, when the master node of the cluster needs to be determined again, the node can determine a current control node from the nodes included in the cluster, and based on the control node, the current master node of the cluster is determined from the nodes included in the cluster. Based on the master node determining method, when the master node of the cluster needs to be determined again, the nodes in the cluster do not need to modify the node identifiers of the master nodes recorded in the cluster file system, and it can be understood that even if the cluster file system is in an unreadable state, the nodes in the cluster can also determine the master nodes, so that the probability of cluster network service interruption can be reduced.
Of course, not all advantages described above need to be achieved at the same time in the practice of any one product or method of the present application.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present application, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a flowchart of a method for determining a master node according to an embodiment of the present disclosure;
fig. 2 is a flowchart of an example of a method for determining a master node according to an embodiment of the present disclosure;
fig. 3 is a flowchart of an example of a method for determining a master node according to an embodiment of the present application;
fig. 4 is a flowchart of an example of a method for determining a master node according to an embodiment of the present application;
fig. 5 is a block diagram of a master node determining apparatus according to an embodiment of the present disclosure;
fig. 6 is a block diagram of an electronic device according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
In the prior art, a node in a cluster may generally determine a master node according to a cluster file system, however, when the node in the cluster fails, the cluster file system may be in an unreadable state, and if the master node in the cluster fails, the node which has not failed in the cluster cannot determine the master node again through the cluster file system, which may cause interruption of network services of the cluster.
In order to solve the above problem, an embodiment of the present application provides a method for determining a master node, where the method may be applied to each node in a cluster, that is, each node in the cluster may determine a master node according to the method for determining a master node in the present application, and the determined master nodes are the same node. For a node in the cluster, when the master node needs to be determined again, the node may determine a current control node from the nodes included in the cluster, and determine a current master node of the cluster from the nodes included in the cluster based on the control node.
Therefore, when the master node of the cluster needs to be determined again, the node in the cluster does not need to modify the node identifier of the master node recorded in the cluster file system, and it can be understood that even if the cluster file system is in an unreadable state, the node in the cluster can determine the master node, and further the probability of cluster network service interruption can be reduced.
Referring to fig. 1, fig. 1 is a flowchart of a master node determination method provided in an embodiment of the present application, where the method may be applied to each node in a cluster, and for one node (may be referred to as a first node), the method may include the following steps:
s101: when the master node of the cluster needs to be determined again, the current control node is determined from the nodes included in the cluster.
The control node may be a node for controlling data consistency of the cluster. Typically, the control node may be a Leader node in the cluster. The control node and the master node may or may not be the same node.
In the application embodiment, when the master node of the cluster needs to be determined again, the first node may determine the current control node from the nodes included in the cluster, and similarly, other nodes in the cluster may also determine the current control node, and the control nodes determined by the nodes in the cluster are the same node.
It will be appreciated that if the control node of the cluster is not the same node as the master node of the cluster, the first node may directly determine the current control node when it is necessary to re-determine the master node of the cluster.
If the control node of the cluster is the same node as the master node of the cluster, when the master node of the cluster needs to be re-determined, the first node may re-determine the control node of the cluster by adopting the following method:
the method comprises the following steps:
step one, when the main node of the cluster is detected to be failed, determining the adding sequence of the nodes which are not failed currently in the cluster to the cluster.
In the application embodiment, when the first node detects that the master node of the cluster fails, the first node may determine a node (which may be referred to as a normal node) that does not currently fail in the cluster, and then the first node may obtain a join order in which the normal node joins the cluster.
In this step, the first node may detect whether the master node fails according to a heartbeat packet sent by the master node of the cluster. Illustratively, when the first node determines that the heartbeat message sent by the master node is not received again within a first preset time period after the first node receives the heartbeat message of the master node last time, the first node may determine that the master node of the cluster fails.
Or, the first node may also actively acquire the state information of the master node to determine whether the master node fails. Illustratively, the first node may actively acquire the state information of the master node every second preset time interval, and may further determine whether the master node fails.
The first preset time period and the second preset time period may be set by a technician according to experience. The embodiment of the present application is not limited to a method for detecting whether a master node fails by a first node.
In addition, each node in the cluster may locally store a node list including node information of all nodes in the cluster, and the node list may record node identifiers of all nodes in the cluster, fault identifiers of the nodes, and a joining order of the nodes. For example, the list of nodes can be seen in table (1).
Watch (1)
Node identification Fault identification Order of addition
Node 1 Whether or not 1
Node 2 Whether or not 2
Node 3 Is that 3
Node 4 Whether or not 4
Node 5 Whether or not 5
The node identifier includes a node 1, a node 2, a node 3, a node 4, and a node 5, that is, there are currently 5 nodes in the cluster, and specifically, the node identifier of each node may be represented by an IP (Internet Protocol) address of the node. The fault flag of a certain node is "yes", which may indicate that the node is currently in fault, and the fault flag of a certain node is "no", which may indicate that the node is not currently in fault, i.e., is a normal node. In table (1), the adding sequence of node 1 is 1, which may indicate that node 1 is the first node to join the cluster, and similarly, node 2 is the second node to join the cluster, node 3 is the third node to join the cluster, node 4 is the fourth node to join the cluster, and node 5 is the fifth node to join the cluster.
For example, for table (1), if node 1 is the control node of the master node of the cluster, when node 1 fails, all of nodes 2, 4, and 5 may detect that node 1 fails, and then all of nodes 2, 4, and 5 may determine that the current normal nodes in the cluster include: node 2, node 4 and node 5, and the adding sequence of the normal nodes is: node 2, node 4, node 5.
And step two, determining the node at the first preset position in the adding sequence as the current control node.
The first preset position may be set by a technician according to experience, and for example, the node located at the first preset position may be a first node in the joining sequence, and the node located at the first preset position may also be a last node in the joining sequence, but is not limited thereto.
In the application embodiment, after obtaining the adding sequence of the normal nodes, the first node may determine the node located at the first preset position in the adding sequence as the current control node, and similarly, the other normal nodes except the first node may also determine the node located at the first preset position in the adding sequence as the current control node.
Illustratively, for the example in step one, the join order of the normal nodes is: node 2, node 4, node 5. If the node located at the first preset position is the first node in the joining sequence, the node 2, the node 4 and the node 5 can all determine that the current control node is the node 2; if the node located at the first preset position is the last node in the joining order, then node 2, node 4 and node 5 can all determine that the current control node is node 5.
Therefore, based on the master node determining method of the embodiment, the nodes in the cluster can directly determine the current control node of the cluster according to the adding sequence of the normal nodes without election, so that the time for determining the master node can be shortened, and the efficiency for determining the master node is improved.
The method II can comprise the following steps:
step one, when detecting that the main node of the cluster fails, sending a control node election message to other nodes which do not fail currently in the cluster.
The control node election message sent by the first node may carry a node identifier of the first node and a transaction identifier for identifying the control node election message sent by the first node this time. The node ID may be a node ID (Identity) of the first node, the transaction ID may be a transaction ID, and the transaction ID may be a 64-bit number and is uniformly assigned by the control node.
In the application embodiment, when the first node detects that the master node of the cluster fails, the first node may initiate election of the control node, and the first node may send a control node election message carrying the node identifier and the transaction identifier of the first node to other normal nodes in the cluster. Similarly, when detecting that the master node of the cluster fails, the other normal nodes may send control node election messages to the normal nodes other than the normal nodes.
In this step, since the master node and the control node are the same node, if the master node of the cluster fails, that is, the control node also fails, the first node may use itself as the control node, generate a transaction identifier for indicating the control node election message sent this time, and send the control node election message carrying the generated transaction ID and its own node ID to other normal nodes, where the processing methods of the other normal nodes are similar to those of the first node, and are not described here again.
And step two, determining the current control node according to the size of the node identifier and the size of the transaction identifier carried in the received control node election message sent by other nodes.
In the application embodiment, since other normal nodes may also send the control node election message carrying the transaction identifier and the node identifier to normal nodes other than the normal nodes, the first node may receive the control node election message sent by other normal nodes, and then the first node may determine the current control node according to the size of the node identifier and the size of the transaction identifier carried in the received control node election message. It can be understood that, since the first node also needs to participate in the election of the control node, the node identifier and the transaction identifier according to which the first node determines the control node include the node identifier of the first node and the transaction identifier carried in the election message of the control node sent by the first node.
Generally, for a plurality of received control node election messages, the first node may compare transaction IDs carried in the control node election messages, and determine a node corresponding to the control node election message with the largest carried transaction ID as a control node.
In addition, if the transaction IDs carried in the multiple control node election messages are the same, the first node may compare the node IDs carried in the multiple control node election messages, and the first node may determine the node with the largest node ID as the control node.
For example, for table (1), if node 1 is the master node and the control node of the cluster, when node 1 fails, node 2 may send a control node election message (which may be referred to as a first control node election message) to nodes 4 and 5, where the control node election message carries the node identifier (which may be node ID2) and the transaction identifier (transaction ID2) of node 2; the node 4 may send a control node election message (which may be referred to as a second control node election message) carrying the node identifier (which may be the node ID4) and the transaction identifier (transaction ID4) of the node 4 to the nodes 2 and 5; node 5 may send a control node election message (which may be referred to as a third control node election message) to nodes 2 and 4 carrying the node identification of node 5 (which may be node ID5) and the transaction identification (transaction ID 5).
For node 2, node 2 may receive the second control node election message and the third control node election message, and may further obtain node ID4, node ID5, transaction ID4, and transaction ID5, then node 2 may compare the sizes of transaction ID2, transaction ID4, and transaction ID5, if transaction ID2 and transaction ID4 are the same and greater than transaction ID5, node 2 may compare the sizes of node ID2 and node ID4, and if node ID2 is greater than node ID4, node 2 may determine that node 2 is the current control node.
Similarly, node 4 and node 5 may determine node 2 as the current control node according to the sizes of node ID2, node ID4, node ID5, transaction ID2, transaction ID4, and transaction ID 5.
Therefore, based on the method, if the control node of the cluster fails, the node in the cluster can elect the control node to determine the current control node of the cluster, and then the master node can be determined according to the control node, so that the probability of cluster network service interruption is reduced.
S102: based on the control node, a current master node of the cluster is determined from the nodes comprised by the cluster.
In an embodiment of the application, after determining the current control node of the cluster, the first node may determine the current master node of the cluster from the nodes included in the cluster based on the control node.
In one implementation, the first node may directly determine the determined control node as the current master node of the cluster.
In the embodiment of the application, if the control node of the cluster is the same as the master node of the cluster, when the master node (i.e., the control node) of the cluster fails, the first node may re-determine the control node of the cluster according to the first mode and the second mode in S101, and then the first node may use the determined control node as the current master node of the cluster. Similarly, the control node determined by the other normal nodes is the same as the control node determined by the first node, and the other normal nodes can also use the determined control node as the current master node of the cluster.
For example, for table (1), if node 1 is the master node and the control node of the cluster, when node 1 fails, if nodes 2, 4, and 5 determine that the current control node is node 5 according to the joining sequence of normal nodes, then nodes 2, 4, and 5 may determine that node 5 is the current master node.
If the node 1 is a master node and a control node of a cluster, and when the node 1 fails, if the nodes 2, 4, and 5 determine that the current control node is the node 2 according to the received control node election message, the nodes 2, 4, and 5 may determine that the node 2 is the current master node.
Therefore, based on the master node determination method of the embodiment, the determined control node can be directly used as the master node of the cluster, the time for determining the master node can be shortened, and the efficiency for determining the master node can be improved.
In addition, the normal node in the cluster may also elect to generate the master node of the cluster according to the determined control node, and S102 may include the following steps:
step one, if the node is not a control node, a main node election message is sent to the control node; when receiving a message for determining election sent by a control node, determining that the node is the current main node of the cluster; and when the election determining message sent by the control node is not received and the main node determining message sent by the control node is received, determining the node to which the node identifier carried in the main node determining message belongs as the current main node of the cluster.
In the application embodiment, when the first node detects that the master node of the cluster fails, the first node may determine a current control node of the cluster, and if the first node is not a control node, the first node may send a master node election message to the control node. In addition, even if the first node is a control node, the first node can send a main node election message through the interaction of the internal process of the first node, so that the first node elects the first node as a main node.
After receiving the master node election messages sent by the normal nodes (including the control node), the control node may determine the current master node of the cluster according to the sequence in which the normal nodes send the master node election messages, and then the control node may send a determined election message to the determined master node.
Correspondingly, if the first node receives the election determining message sent by the control node, the first node may determine that the first node is the current master node of the cluster; if the first node does not receive the election determining message sent by the control node and receives the master node determining message sent by the control node, the first node may determine the node to which the node identifier carried in the master node determining message belongs as the current master node of the cluster.
In this step, the first node sends a host node election message to the control node, and may send, to the control node, a write request for writing target data representing the host node in a local storage space, where the target data may be an IP address of the first node, for the first node. The first node writes the IP address of the first node in the local storage space, which may indicate that the first node elects to be the master node itself.
The first node sends a master node election message to the control node, that is, the first node, as a Follower (Follower) in the cluster, initiates a Proposal (promosal) for electing itself as the master node, and correspondingly, the control node may notify all followers in the cluster to vote for the Proposal, and the followers may send the voting result to the control node. If the control node determines that the proposal initiated by the first node is established according to the voting result, the control node can send a message of determining election to the first node.
After receiving the election determining message, the first node may write its own IP address in a local storage space to elect its own master node as a cluster.
The control node may further send a master node determination message to other normal nodes (which may be referred to as second nodes) except the first node, and after receiving the master node determination message, the second node may perform data synchronization, for example, the second node may write an IP address of the first node in a local storage space to confirm that the first node is the master node.
And step two, if the node is a control node, determining the node which sends the master node election message at the second preset position in the sending sequence as the current master node of the cluster according to the sending sequence of the received master node election message, sending the determined election message to the current master node of the cluster, and sending the master node determination message carrying the node identification of the current master node of the cluster to the nodes except the current master node of the cluster.
The second preset position may be set by a technician according to experience, and for example, the node that sends the master node election message located at the second preset position in the sending sequence may be the first node that sends the master node election message to the control node, or the last node that sends the master node election message to the control node, but the node is not limited thereto.
In the application embodiment, if the first node is a control node, the first node may receive a master node election message sent by each normal node (including the control node), and then, according to a sending sequence of the received master node election message, the first node may determine a node (which may be referred to as a third node) that sends a master node election message located at a second preset position in the sending sequence as a current master node of the cluster. The first node may send the election determining message to the third node, and send the master node determining message carrying the node identifier of the third node to a node (which may be referred to as a fourth node) other than the third node.
Correspondingly, the third node may receive the election determining message sent by the first node, and further may determine that the third node is the current master node of the cluster. The fourth node may receive the master node determination message carrying the node identifier of the third node, and then the fourth node may determine that the third node is the current master node of the cluster. After receiving the master node determination message, the fourth node may write the IP address of the third node in the local storage space to record that the third node is the current master node.
Optionally, the control node may determine, according to the transmission sequence of the received master node election message, the node that transmits the master node election message first as the current master node of the cluster.
In the embodiment of the application, after detecting that the master node fails, the control node may determine, according to the transmission sequence of the received master node election messages, the first node that transmits the master node election message as the current master node of the cluster.
Therefore, based on the master node determination method in the embodiment of the application, the control node can determine the first node sending the master node election message as the current master node of the cluster, so that the time for determining the master node can be shortened, and the master node determination efficiency can be improved.
Based on the description of the above embodiments, it can be understood that, if a control node of a cluster is not the same node as a master node of the cluster, when the master node of the cluster fails, a node in the cluster may be elected according to the control node to determine the master node; if the control node of the cluster is the same node as the master node of the cluster, when the master node of the cluster fails, that is, the control node of the cluster fails, at this time, the control node may be determined according to the method introduced in S101 or other methods for determining the control node in the prior art, and then master node election may be performed according to the control node to determine the master node.
Referring to fig. 2, fig. 2 is a flowchart of an example of a master node determining method provided in an embodiment of the present application, in which a master node and a control node of a cluster are the same node in this scenario, and for a node in the cluster, the method may include the following steps:
s201: and when the main node of the cluster is detected to be failed, sending a control node election message to other nodes which are not failed currently in the cluster.
S202: and determining the current control node according to the size of the node identifier and the size of the transaction identifier carried in the received control node election message sent by other nodes.
S203: and determining the control node as the current main node of the cluster.
Referring to fig. 3, fig. 3 is a flowchart of an example of a master node determining method provided in an embodiment of the present application, in which a master node and a control node of a cluster are the same node in this scenario, and for a node in the cluster, the method may include the following steps:
s301: when the main node of the cluster is detected to be failed, determining the adding sequence of the nodes which are not failed currently in the cluster to the cluster.
S302: and determining the node positioned at the first preset position in the joining sequence as the current control node.
S303: and determining the control node as the current main node of the cluster.
Referring to fig. 4, fig. 4 is a flowchart of an example of a master node determining method provided in an embodiment of the present application, in which a master node of a cluster and a control node are not the same node in the scene, and for a node in the cluster, the method may include the following steps:
s401: when detecting that the main node of the cluster fails, judging whether the main node is a control node, if the main node is the control node, executing S402-S403, and if the main node is not the control node, executing S404-S407.
S402: and determining the node which sends the master node election message positioned at the second preset position in the sending sequence as the current master node of the cluster according to the sending sequence of the received master node election message.
S403: and sending a selection determining message to the current master node of the cluster, and sending a master node determining message carrying the node identification of the current master node of the cluster to nodes except the current master node of the cluster.
S404: and sending a master node election message to the control node.
S405: and judging whether a definite election message sent by the control node is received, if the definite election message sent by the control node is received, executing S406, and if the definite election message sent by the control node is not received, executing S407.
S406: and determining the self as the current main node of the cluster.
S407: and when receiving a master node determination message sent by the control node, determining the node to which the node identifier carried in the master node determination message belongs as the current master node of the cluster.
Corresponding to the method embodiment of fig. 1, referring to fig. 5, fig. 5 is a main node determining apparatus provided in an embodiment of the present application, where the apparatus is applied to each node in a cluster, and for a node in the cluster, the apparatus applied to the node includes:
a first determining module 501, configured to determine a current control node from nodes included in the cluster when a master node of the cluster needs to be determined again, where the control node is a node used for controlling data consistency of the cluster;
a second determining module 502, configured to determine, based on the control node, a current master node of the cluster from nodes included in the cluster.
Optionally, the first determining module 501 is specifically configured to determine, when it is detected that a master node of the cluster fails, a join order in which nodes that do not currently fail join the cluster are joined to the cluster;
and determining the node positioned at the first preset position in the adding sequence as the current control node.
Optionally, the first determining module 501 is specifically configured to, when it is detected that a master node of the cluster fails, send a control node election message to other nodes in the cluster that do not currently fail, where the control node election message carries a node identifier of the node and a transaction identifier used to identify the control node election message sent by the node this time;
and determining the current control node according to the size of the node identifier and the size of the transaction identifier carried in the received control node election message sent by other nodes.
Optionally, the second determining module 502 is specifically configured to determine the control node as the current master node of the cluster.
Optionally, the second determining module 502 is specifically configured to send a master node election message to the control node if the node is not the control node; when receiving a message for determining election sent by the control node, determining that the node is the current main node of the cluster; when the election determining message sent by the control node is not received and the main node determining message sent by the control node is received, determining the node to which the node identifier carried in the main node determining message belongs as the current main node of the cluster;
if the node is the control node, according to the received sending sequence of the master node election messages, determining the node which sends the master node election messages located at the second preset position in the sending sequence as the current master node of the cluster, sending the determined election messages to the current master node of the cluster, and sending the master node determination messages carrying the node identification of the current master node of the cluster to nodes except the current master node of the cluster.
Optionally, the second determining module 502 is specifically configured to determine, according to the sending sequence of the received master node election message, a first node that sends the master node election message as the current master node of the cluster.
Based on the master node determining apparatus provided in the embodiment of the present application, for a node in a cluster, when the master node of the cluster needs to be determined again, the node may determine a current control node from nodes included in the cluster, and determine the current master node of the cluster according to the control node. That is, when the master node of the cluster needs to be determined again, the node in the cluster does not need to modify the node identifier of the master node recorded in the cluster file system, and it can be understood that even if the cluster file system is in an unreadable state, the node in the cluster can determine the master node, and thus the probability of cluster network service interruption can be reduced.
The embodiment of the present application further provides an electronic device, as shown in fig. 6, which includes a processor 601, a communication interface 602, a memory 603, and a communication bus 604, where the processor 601, the communication interface 602, and the memory 603 complete mutual communication through the communication bus 604,
a memory 603 for storing a computer program;
the processor 601 is configured to implement the following steps when executing the program stored in the memory 603:
when the master node of the cluster needs to be determined again, determining a current control node from nodes included in the cluster, wherein the control node is a node used for controlling the data consistency of the cluster;
and determining the current main node of the cluster from the nodes included in the cluster based on the control node.
The communication bus mentioned in the electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the electronic equipment and other equipment.
The Memory may include a Random Access Memory (RAM) or a non-volatile Memory (non-volatile Memory), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The Processor may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; the device can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, a discrete Gate or transistor logic device, or a discrete hardware component.
Based on the electronic device provided by the embodiment of the application, when the master node of the cluster needs to be determined again, the node in the cluster does not need to modify the node identifier of the master node recorded in the cluster file system, and it can be understood that even if the cluster file system is in an unreadable state, the node in the cluster can determine the master node, so that the probability of cluster network service interruption can be reduced.
An embodiment of the present application further provides a computer-readable storage medium, where instructions are stored in the computer-readable storage medium, and when the instructions are executed on a computer, the computer is caused to execute the master node determination method provided in the embodiment of the present application.
Specifically, the method for determining the master node includes:
when the master node of the cluster needs to be determined again, determining a current control node from nodes included in the cluster, wherein the control node is a node used for controlling the data consistency of the cluster;
and determining the current main node of the cluster from the nodes included in the cluster based on the control node.
It should be noted that other implementation manners of the master node determining method are the same as those of the foregoing method embodiment, and are not described herein again.
By operating the instruction stored in the computer-readable storage medium provided in the embodiment of the present application, when the master node of the cluster needs to be determined again, the node in the cluster does not need to modify the node identifier of the master node recorded in the cluster file system, and it can be understood that even if the cluster file system is in an unreadable state, the node in the cluster can determine the master node, and thus the probability of cluster network service interruption can be reduced.
Embodiments of the present application further provide another computer program product containing instructions, which when run on a computer, cause the computer to execute the master node determination method provided in the embodiments of the present application.
Specifically, the method for determining the master node includes:
when the master node of the cluster needs to be determined again, determining a current control node from nodes included in the cluster, wherein the control node is a node used for controlling the data consistency of the cluster;
and determining the current main node of the cluster from the nodes included in the cluster based on the control node.
It should be noted that other implementation manners of the master node determining method are the same as those of the foregoing method embodiment, and are not described herein again.
By operating the computer program product provided by the embodiment of the present application, when the master node of the cluster needs to be determined again, the node in the cluster does not need to modify the node identifier of the master node recorded in the cluster file system, and it can be understood that even if the cluster file system is in an unreadable state, the node in the cluster can determine the master node, and thus the probability of cluster network service interruption can be reduced.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the application to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, from one website site, computer, server, or data center to another website site, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that incorporates one or more of the available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the apparatus, the electronic device, the computer-readable storage medium, and the computer program product embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and for the relevant points, reference may be made to the partial description of the method embodiments.
The above description is only for the preferred embodiment of the present application, and is not intended to limit the scope of the present application. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the present application are included in the protection scope of the present application.

Claims (14)

1. A master node determination method applied to each node in a cluster, wherein for a node in the cluster, the node performs the method comprising:
when the master node of the cluster needs to be determined again, determining a current control node from nodes included in the cluster, wherein the control node is a node used for controlling the data consistency of the cluster;
and determining the current main node of the cluster from the nodes included in the cluster based on the control node.
2. The method of claim 1, wherein determining a current control node from the nodes included in the cluster when the master node of the cluster needs to be re-determined comprises:
when detecting that a main node of the cluster fails, determining a joining sequence of nodes which do not fail in the cluster to join the cluster;
and determining the node positioned at the first preset position in the adding sequence as the current control node.
3. The method of claim 1, wherein determining a current control node from the nodes included in the cluster when the master node of the cluster needs to be re-determined comprises:
when detecting that a main node of the cluster fails, sending a control node election message to other nodes which do not fail currently in the cluster, wherein the control node election message carries a node identifier of the node and a transaction identifier for identifying the control node election message sent by the node this time;
and determining the current control node according to the size of the node identifier and the size of the transaction identifier carried in the received control node election message sent by other nodes.
4. The method according to any of claims 1-3, wherein said determining a current master node of the cluster from the nodes comprised by the cluster based on the control node comprises:
and determining the control node as the current master node of the cluster.
5. The method of claim 1, wherein determining a current master node of the cluster from the nodes included in the cluster based on the control node comprises:
if the node is not the control node, sending a master node election message to the control node; when receiving a message for determining election sent by the control node, determining that the node is the current main node of the cluster; when the election determining message sent by the control node is not received and the main node determining message sent by the control node is received, determining the node to which the node identifier carried in the main node determining message belongs as the current main node of the cluster;
if the node is the control node, according to the received sending sequence of the master node election messages, determining the node which sends the master node election messages located at the second preset position in the sending sequence as the current master node of the cluster, sending the determined election messages to the current master node of the cluster, and sending the master node determination messages carrying the node identification of the current master node of the cluster to nodes except the current master node of the cluster.
6. The method according to claim 5, wherein the determining, according to the received transmission sequence of the master node election message, a node that transmits a master node election message located at a second preset position in the transmission sequence as the current master node of the cluster, comprises:
and determining the node which is the first node to send the master node election message as the current master node of the cluster according to the sending sequence of the received master node election messages.
7. A master node determination apparatus, the apparatus being applied to each node in a cluster, and for a node in the cluster, the apparatus applied to the node comprising:
a first determining module, configured to determine a current control node from nodes included in the cluster when a master node of the cluster needs to be re-determined, where the control node is a node used for controlling data consistency of the cluster;
and the second determining module is used for determining the current main node of the cluster from the nodes included in the cluster based on the control node.
8. The apparatus according to claim 7, wherein the first determining module is specifically configured to, when it is detected that a master node of the cluster fails, determine a join order in which nodes that do not currently fail in the cluster join the cluster;
and determining the node positioned at the first preset position in the adding sequence as the current control node.
9. The apparatus according to claim 7, wherein the first determining module is specifically configured to, when it is detected that a master node of the cluster fails, send a control node election message to other nodes in the cluster that do not currently fail, where the control node election message carries a node identifier of the node and a transaction identifier for identifying the control node election message sent by the node this time;
and determining the current control node according to the size of the node identifier and the size of the transaction identifier carried in the received control node election message sent by other nodes.
10. The apparatus according to any of claims 7 to 9, wherein the second determining module is specifically configured to determine the control node as a current master node of the cluster.
11. The apparatus of claim 7, wherein the second determining module is specifically configured to send a master node election message to the control node if the node is not the control node; when receiving a message for determining election sent by the control node, determining that the node is the current main node of the cluster; when the election determining message sent by the control node is not received and the main node determining message sent by the control node is received, determining the node to which the node identifier carried in the main node determining message belongs as the current main node of the cluster;
if the node is the control node, according to the received sending sequence of the master node election messages, determining the node which sends the master node election messages located at the second preset position in the sending sequence as the current master node of the cluster, sending the determined election messages to the current master node of the cluster, and sending the master node determination messages carrying the node identification of the current master node of the cluster to nodes except the current master node of the cluster.
12. The apparatus of claim 11, wherein the second determining module is specifically configured to determine, according to a sending sequence of the received master node election messages, a first node that sends the master node election message as the current master node of the cluster.
13. An electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;
the memory is used for storing a computer program;
the processor, when executing the program stored in the memory, implementing the method steps of any of claims 1-6.
14. A computer-readable storage medium, characterized in that a computer program is stored in the computer-readable storage medium, which computer program, when being executed by a processor, carries out the method steps of any one of claims 1 to 6.
CN201811569603.8A 2018-12-21 2018-12-21 Main node determining method and device Active CN111355600B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811569603.8A CN111355600B (en) 2018-12-21 2018-12-21 Main node determining method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811569603.8A CN111355600B (en) 2018-12-21 2018-12-21 Main node determining method and device

Publications (2)

Publication Number Publication Date
CN111355600A true CN111355600A (en) 2020-06-30
CN111355600B CN111355600B (en) 2023-05-02

Family

ID=71195309

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811569603.8A Active CN111355600B (en) 2018-12-21 2018-12-21 Main node determining method and device

Country Status (1)

Country Link
CN (1) CN111355600B (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113364871A (en) * 2021-06-07 2021-09-07 杭州溪塔科技有限公司 Node election method and device based on intelligent contract and electronic equipment
CN115240379A (en) * 2022-07-19 2022-10-25 安徽远航交通科技有限公司 Linkage alarm system based on intelligent road cone
WO2023124663A1 (en) * 2021-12-28 2023-07-06 华为技术有限公司 Cluster quorum implementation method, network device, and system
US20230251976A1 (en) * 2022-01-26 2023-08-10 Capital One Services, Llc Systems and methods for leader node election in cluster server configurations

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120179798A1 (en) * 2011-01-11 2012-07-12 Ibm Corporation Autonomous primary node election within a virtual input/output server cluster
CN103607297A (en) * 2013-11-07 2014-02-26 上海爱数软件有限公司 Fault processing method of computer cluster system
CN106331098A (en) * 2016-08-23 2017-01-11 东方网力科技股份有限公司 Server cluster system
CN106878382A (en) * 2016-12-29 2017-06-20 北京华为数字技术有限公司 Dynamically change the method and device of cluster scale in a kind of distributed arbitration program cluster
CN108810100A (en) * 2018-05-22 2018-11-13 郑州云海信息技术有限公司 A kind of electoral machinery of host node, device and equipment
CN108900331A (en) * 2018-06-26 2018-11-27 郑州云海信息技术有限公司 A kind of distributed type assemblies management method and distributed type assemblies
CN109005045A (en) * 2017-06-06 2018-12-14 北京金山云网络技术有限公司 Active and standby service system and host node fault recovery method

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120179798A1 (en) * 2011-01-11 2012-07-12 Ibm Corporation Autonomous primary node election within a virtual input/output server cluster
CN103607297A (en) * 2013-11-07 2014-02-26 上海爱数软件有限公司 Fault processing method of computer cluster system
CN106331098A (en) * 2016-08-23 2017-01-11 东方网力科技股份有限公司 Server cluster system
CN106878382A (en) * 2016-12-29 2017-06-20 北京华为数字技术有限公司 Dynamically change the method and device of cluster scale in a kind of distributed arbitration program cluster
CN109005045A (en) * 2017-06-06 2018-12-14 北京金山云网络技术有限公司 Active and standby service system and host node fault recovery method
CN108810100A (en) * 2018-05-22 2018-11-13 郑州云海信息技术有限公司 A kind of electoral machinery of host node, device and equipment
CN108900331A (en) * 2018-06-26 2018-11-27 郑州云海信息技术有限公司 A kind of distributed type assemblies management method and distributed type assemblies

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113364871A (en) * 2021-06-07 2021-09-07 杭州溪塔科技有限公司 Node election method and device based on intelligent contract and electronic equipment
WO2023124663A1 (en) * 2021-12-28 2023-07-06 华为技术有限公司 Cluster quorum implementation method, network device, and system
US20230251976A1 (en) * 2022-01-26 2023-08-10 Capital One Services, Llc Systems and methods for leader node election in cluster server configurations
US11907137B2 (en) * 2022-01-26 2024-02-20 Capital One Services, Llc Systems and methods for leader node election in cluster server configurations
CN115240379A (en) * 2022-07-19 2022-10-25 安徽远航交通科技有限公司 Linkage alarm system based on intelligent road cone

Also Published As

Publication number Publication date
CN111355600B (en) 2023-05-02

Similar Documents

Publication Publication Date Title
CN111355600B (en) Main node determining method and device
CN103460203B (en) cluster unique identifier
US20220075698A1 (en) Method and Apparatus for Redundancy in Active-Active Cluster System
KR102167613B1 (en) Message push method and device
CN109327544B (en) Leader node determination method and device
US11445013B2 (en) Method for changing member in distributed system and distributed system
CN111064786B (en) Account identifier management method and device
CN113496004A (en) Message sending method and device
CN108509296B (en) Method and system for processing equipment fault
CN110740064A (en) Distributed cluster node fault processing method, device, equipment and storage medium
CN113810216A (en) Cluster fault switching method and device and electronic equipment
CN112486718A (en) Database fault automatic switching method and device and computer storage medium
CN115037653B (en) Service flow monitoring method, device, electronic equipment and storage medium
CN111629054B (en) Message processing method, device and system, electronic equipment and readable storage medium
CN111400327B (en) Data synchronization method and device, electronic equipment and storage medium
CN110502460B (en) Data processing method and node
CN110290215B (en) Signal transmission method and device
US11223709B2 (en) Exchange, communication system, registration method, and program
CN111639089B (en) Transaction processing method, transaction processing device, electronic equipment and computer readable storage medium
CN113391759A (en) Communication method and device
CN112702735A (en) Registration information service method, equipment and computer readable storage medium
US20240106793A1 (en) Traffic scheduling method, apparatus and system, terminal device and readable storage medium
CN116032889B (en) IP address allocation method and device
CN110071868B (en) Link aggregation method, device and network equipment
US20230161601A1 (en) System and method for facilitating management of edge computing nodes of an edge computing network

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