WO2021184177A1 - 主节点选取方法、装置、电子设备以及存储介质 - Google Patents

主节点选取方法、装置、电子设备以及存储介质 Download PDF

Info

Publication number
WO2021184177A1
WO2021184177A1 PCT/CN2020/079574 CN2020079574W WO2021184177A1 WO 2021184177 A1 WO2021184177 A1 WO 2021184177A1 CN 2020079574 W CN2020079574 W CN 2020079574W WO 2021184177 A1 WO2021184177 A1 WO 2021184177A1
Authority
WO
WIPO (PCT)
Prior art keywords
node
slave
nodes
master node
temporary
Prior art date
Application number
PCT/CN2020/079574
Other languages
English (en)
French (fr)
Inventor
赖延辉
曾焕生
Original Assignee
深圳市欢太科技有限公司
Oppo广东移动通信有限公司
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 深圳市欢太科技有限公司, Oppo广东移动通信有限公司 filed Critical 深圳市欢太科技有限公司
Priority to PCT/CN2020/079574 priority Critical patent/WO2021184177A1/zh
Priority to CN202080095213.0A priority patent/CN115088235B/zh
Publication of WO2021184177A1 publication Critical patent/WO2021184177A1/zh

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

Definitions

  • This application relates to the field of computer technology, and more specifically, to a method, device, electronic device, and storage medium for selecting a master node.
  • the method of selecting masters based on zookeeper is to use zookeeper to perceive the information of each node in the cluster.
  • this application proposes a method, device, electronic equipment, and storage medium for selecting a master node to solve the above-mentioned problems.
  • an embodiment of the present application provides a method for selecting a master node.
  • the method includes: creating a plurality of temporary nodes in a zookeeper cluster, and determining a master node and a slave node from the plurality of temporary nodes;
  • the master node sends a survival message to the slave node; when the slave node does not receive the survival message sent by the master node, the slave node is used as the current master node.
  • an embodiment of the present application provides an apparatus for selecting a master node, and the apparatus includes:
  • the temporary node creation module is used to create multiple temporary nodes in the zookeeper cluster and determine the master node and the slave node from the multiple temporary nodes;
  • the survival message sending module is used to control the master node to the slave node Send a survival message;
  • the master node selection module is configured to use the slave node as the current master node when the slave node does not receive the survival message sent by the master node.
  • an embodiment of the present application provides an electronic device, including a memory and a processor, the memory is coupled to the processor, the memory stores instructions, and the instructions are executed when the instructions are executed by the processor.
  • the processor executes the above method.
  • an embodiment of the present application provides a computer readable storage medium, and the computer readable storage medium stores program code, and the program code can be invoked by a processor to execute the above method.
  • the method, device, electronic equipment, and storage medium for selecting the master node create multiple temporary nodes in the zookeeper cluster, determine the master node and the slave node from the multiple temporary nodes, and control the master node to send to the slave node Survival message, when the slave node does not receive the survival message sent by the master node, the slave node will act as the current master node, thereby controlling the master node to send the survival message to the slave node.
  • the slave node can immediately perceive its information , So as to quickly upgrade as the current master node to improve the service continuity and availability of the system.
  • FIG. 1 shows a schematic flowchart of a method for selecting a master node according to an embodiment of the present application
  • Figure 2 shows a schematic diagram of master node selection provided by an embodiment of the present application
  • FIG. 3 shows a schematic flowchart of a method for selecting a master node according to another embodiment of the present application
  • FIG. 4 shows a schematic flowchart of a method for selecting a master node according to another embodiment of the present application
  • FIG. 5 shows a schematic flowchart of step S320 of the method for selecting a master node shown in FIG. 4 of the present application
  • FIG. 6 shows a schematic flowchart of step S350 of the method for selecting a master node shown in FIG. 4 of the present application
  • FIG. 7 shows a schematic flowchart of step S370 of the method for selecting a master node shown in FIG. 4 of the present application
  • FIG. 8 shows a schematic flowchart of a method for selecting a master node according to another embodiment of the present application.
  • FIG. 9 shows a schematic flowchart of step S420 of the method for selecting a master node shown in FIG. 8 of the present application.
  • FIG. 10 shows a schematic flowchart of a method for selecting a master node according to another embodiment of the present application.
  • Fig. 11 shows a block diagram of a master node selection device provided by an embodiment of the present application.
  • FIG. 12 shows a block diagram of an electronic device used to execute the method for selecting a master node according to an embodiment of the present application
  • FIG. 13 shows a storage unit used to store or carry program code for implementing the method for selecting a master node according to an embodiment of the present application according to an embodiment of the present application.
  • the deployment architecture of clusters with multiple activities is generally adopted, and the failure of a node in the system does not affect the overall operation.
  • the multi-active approach cannot be adopted, but the master-slave approach can only be adopted to ensure the high availability of the system.
  • the master node fails, the slave node takes over the business.
  • the method of selecting the master based on zookeeper, a distributed application coordination system is to use the zookeeper server to perceive the information of each node.
  • the zookeeper cannot pull the information of the master node, so it will follow up from it.
  • the node is promoted to the master node to take over the business.
  • the inventor found in the research that when the master node stops service, zookeeper needs a longer time to perceive and determine the survival status of the master node. During this time, the entire zookeeper cluster stops serving externally, which greatly reduces the quality of service. Decrease the availability of the system.
  • the inventor has discovered through long-term research and proposed the method, device, electronic equipment, and storage medium for selecting the master node provided by the embodiments of this application.
  • the master node By controlling the master node to send survival messages to the slave nodes, when the master node stops serving , The slave node can immediately perceive its information, so as to quickly promote as the current master node to improve the service continuity and availability of the system.
  • the specific master node selection method will be described in detail in the subsequent embodiments.
  • FIG. 1 shows a schematic flowchart of a method for selecting a master node provided by an embodiment of the application.
  • the master node selection method is used to control the master node to send a survival message to the slave node.
  • the slave node can immediately perceive its information, so as to quickly promote the current master node to improve the service continuity and availability of the system .
  • the method for selecting a master node is applied to the electronic device 100 of the master node selection apparatus 200 shown in FIG. 11 (FIG. 12 ). The following will take an electronic device as an example to illustrate the specific process of this embodiment.
  • the electronic device applied in this embodiment can be regarded as a console for controlling each zookeeper server in the zookeeper cluster.
  • the electronic device can be one or more servers in the zookeeper cluster, or can be a smart phone, a tablet computer, a desktop computer, etc., which is not limited here.
  • the flow shown in Fig. 1 will be described in detail below.
  • the method for selecting the master node may specifically include the following steps:
  • Step S110 Create multiple temporary nodes in the zookeeper cluster, and determine the master node and the slave node from the multiple temporary nodes.
  • multiple temporary nodes can be created in the zookeeper cluster, and the master node and the slave node can be determined from the created multiple temporary nodes, where the number of the master node determined from the created multiple temporary nodes The number is one, and the number of slave nodes determined from the created multiple temporary nodes is one or more, which is not limited here.
  • the zookeeper node may include a zookeeper persistent node and a zookeeper temporary node.
  • the zookeeper persistent node after the zookeeper persistent node is created, it will always exist on the zookeeper server until there is a delete operation to actively delete the node. For example, until the delete command instructs to delete the node, the zookeeper persistent node can be used to save some application data , Even if the creator of the zookeeper persistent node crashes or disconnects, the data will not be lost.
  • the master-slave mode it is necessary to save the character assignment status of the slave nodes, and the master node that immediately assigns tasks has collapsed.
  • the generation cycle of the zookeeper temporary node is bound to the client session. If the client session fails, the node will be automatically cleared, that is, zookeeper conveys information about certain aspects of the application, and the information is only available when the creator is valid. It can be saved. For example, in the master-slave mode, when the master node creates a zookeeper temporary node, the existence of the zookeeper temporary node means that the master node exists, and the state of the master node is in normal operation. If the zookeeper temporary node disappears, it proves that the master node has crashed.
  • the creator of the registered zookeeper temporary node loses the connection, the zookeeper temporary node will be deleted by the zookeeper, and the process of node selection is based on this feature. Therefore, in this embodiment, it can be created in the zookeeper cluster Multiple temporary nodes, and select from multiple temporary nodes to determine the master node and the slave node.
  • the method of determining the master node and the slave node from a plurality of temporary nodes may include, but is not limited to: randomly selecting a temporary node from the plurality of temporary nodes as the master node, and combining the remaining temporary nodes in the plurality of temporary nodes.
  • the node is used as a slave node; the temporary node that is registered successfully from multiple temporary nodes is used as the master node, and the temporary node that is unsuccessfully registered from the multiple temporary nodes is used as the slave node; the temporary node created first from multiple temporary nodes As the master node, the temporary node created after the first temporary node in the multiple temporary nodes is used as the slave node; the master node and the slave node can be determined from the multiple temporary nodes according to preset rules; the slave node can be selected according to the user Determine the master node and the slave node among multiple temporary nodes.
  • Step S120 Control the master node to send a survival message to the slave node.
  • the master node after determining the master node and the slave node from a plurality of temporary nodes, the master node can be controlled to send a survival message to the slave node.
  • the survival message sent by the master node to the slave node may only be used to characterize that the master node is in a survival state, and the content, type, and form of the survival message are not limited here.
  • the master node can be controlled to send survival messages to the slave nodes in real time, the master node can be controlled to send survival messages to the slave nodes at a specified time interval, and the master node can be controlled to send survival messages to the slave nodes at a specified time.
  • the node sends survival messages to the slave node according to other specified rules.
  • the master node in order to improve the service continuity of the system, may be controlled to send live messages to the slave nodes in real time.
  • Step S130 When the slave node does not receive the survival message sent by the master node, the slave node is used as the current master node.
  • the slave node when the slave node receives the survival message sent by the master node, it can be determined that the master node is in a normal service state, and the originally determined master node and slave node can be kept unchanged.
  • the slave node when the slave node does not receive the survival message sent by the master node, it can be determined that the master node is in a state of out of service, then the master node can be deleted from the zookeeper cluster, and the slave node can be used as the current master node.
  • the zookeeper cluster can continue to provide external reading services, which improves the readability and writability of the entire system, ensures the high availability and serviceability of the system, and realizes the undifferentiated switching of the master node and the slave node, and at the same time , The whole selection process is clear and clear, which reduces the difficulty of system programming and improves development efficiency.
  • FIG. 2 shows a schematic diagram showing the selection of a master node provided by an embodiment of the present application.
  • the master node 1 can send a message to the slave node 2 to indicate that the master node is alive.
  • the slave node 2 does not receive the survival message sent by the master node 1, the master node 1 can be removed from the zookeeper cluster Delete and use slave node 2 as the current master node.
  • multiple temporary nodes are created in the zookeeper cluster, and the master node and the slave node are determined from the multiple temporary nodes, and the master node is controlled to send a survival message to the slave node.
  • the slave node When receiving the survival message sent by the master node, the slave node will act as the current master node, thereby controlling the master node to send the survival message to the slave node.
  • the master node stops serving the slave node can immediately perceive its information, thereby quickly promoting as the current master node. Nodes to improve the service continuity and availability of the system.
  • FIG. 3 shows a schematic flowchart of a method for selecting a master node according to another embodiment of the present application.
  • the process shown in FIG. 3 will be described in detail below, and the method for selecting the master node may specifically include the following steps:
  • Step S210 Create the multiple temporary nodes in the zookeeper cluster, and obtain a temporary node whose creation order is the first specified order position from the multiple temporary nodes.
  • each temporary node in the multiple temporary nodes created corresponds to a creation order, for example, if the created The number of multiple temporary nodes is four, and the creation sequence of the four temporary nodes corresponds to the first sequence bit, the second sequence bit, the third sequence bit, and the fourth sequence bit respectively.
  • the temporary node whose creation order is the first specified order position can be obtained from the multiple temporary nodes.
  • the first specified order is It can be any one of the first sequential position, the second sequential position, the third sequential position, and the fourth sequential position, which is not limited here.
  • the temporary node whose creation order is the first specified order position can be obtained. For example, if the first specified order position is the first order position, then multiple temporary nodes can be created before In the process of temporary node, the temporary node whose creation order is the first order is obtained. In some embodiments, after creating multiple temporary nodes, the temporary node whose creation order is the first specified order position can be obtained. When the node ends, the temporary node whose creation order is the first order is obtained from multiple temporary nodes.
  • Step S220 Determine the temporary node whose creation sequence is the first specified sequence bit as the master node, and determine the temporary node other than the master node among the plurality of temporary nodes as the slave node.
  • the temporary node whose creation order is the first designated order position may be determined as the master node, and the plurality of temporary nodes Among the temporary nodes, temporary nodes other than the master node are determined as slave nodes. For example, if the multiple temporary nodes include temporary nodes with the first order of creation, temporary nodes with the second order of creation, temporary nodes with the third order of creation, and temporary nodes of the fourth order of creation.
  • the temporary node whose creation order is the first order position can be determined as the primary node, and the creation order is the temporary node of the second order position and the creation order is the first order position.
  • the temporary node with the three-order position and the temporary node with the fourth-order position in the creation order are determined as slave nodes.
  • the first designated sequence bit is the first sequence bit, that is, the temporary node created first is used as the master node, and the temporary node created later is used as the slave node.
  • Step S230 Obtain the identification information of the slave node.
  • the identification information of the slave node can be obtained.
  • the identification information of the slave node can be pulled from the zookeeper server.
  • the identification information may include International Internet Protocol IP information, and the IP information of the slave node may be pulled from the zookeeper server.
  • Step S240 Based on the identification information, control the master node to send the survival message to the slave node.
  • the master node after the identification information of the slave node is obtained, the master node can be controlled to send the survival message to the slave node based on the identification information of the slave node, and to ensure that the survival message sent by the master node can be accurately sent to the slave node .
  • the identification information is IP information
  • the master node may be controlled to send a survival message to the slave node based on the IP information.
  • Step S250 When the slave node does not receive the survival message sent by the master node, the slave node is used as the current master node.
  • step S250 please refer to step S130, which will not be repeated here.
  • multiple temporary nodes are created in the zookeeper cluster, and the temporary nodes whose creation order is the first designated order are obtained from the multiple temporary nodes, and the creation order is the first designated
  • the temporary node of the sequence bit is determined as the master node, and the temporary node except the master node among the multiple temporary nodes is determined as the slave node, and the identification information of the slave node is obtained, and based on the identification information, the master node is controlled to send survival to the slave node Message, when the slave node does not receive the survival message sent by the master node, the slave node will be the current master node.
  • this embodiment also determines the master node and the slave node according to the creation sequence of the temporary node, so as to increase the speed of acquiring the master node and the slave node. In addition, this embodiment also sends a survival message to the slave node according to the identification information of the slave node to ensure accurate transmission of the survival message.
  • FIG. 4 shows a schematic flowchart of a method for selecting a master node according to another embodiment of the present application.
  • the following will elaborate on the process shown in FIG. 4, where there are multiple slave nodes, and the method for selecting the master node may specifically include the following steps:
  • Step S310 Create multiple temporary nodes in the zookeeper cluster, and determine the master node and the slave node from the multiple temporary nodes.
  • step S310 For the specific description of step S310, please refer to step S110, which will not be repeated here.
  • Step S320 Select a slave node from a plurality of slave nodes as the target slave node.
  • the number of slave nodes determined from the plurality of temporary nodes created is multiple, then one slave node can be selected from the multiple slave nodes as the target slave node, and the master node can be received through the target slave node Survival message sent. For example, if multiple temporary nodes include temporary nodes with the first order of creation, temporary nodes with the second order of creation, temporary nodes with the third order of creation, and temporary nodes of the fourth order of creation.
  • the multiple slave nodes include the temporary node whose creation order is the second order, the temporary node whose creation order is the third order, and the creation For the temporary node whose order is the fourth order, you can select a temporary node from the temporary node whose creation order is the second order, the temporary node whose creation order is the third order, and the temporary node whose creation order is the fourth order. As the target slave node.
  • FIG. 5 shows a schematic flow chart of step S320 of the method for selecting a master node shown in FIG. 4 of the present application.
  • the flow shown in FIG. 5 will be described in detail below.
  • the method may specifically include the following step:
  • Step S321 Acquire a temporary node whose creation order is the second specified order position from the plurality of temporary nodes.
  • the temporary node whose creation order is the second specified order position may be obtained from the multiple temporary nodes other than the main node. For example, if multiple temporary nodes include temporary nodes with the first order of creation, temporary nodes with the second order of creation, temporary nodes with the third order of creation, and temporary nodes of the fourth order of creation.
  • the temporary node whose creation order is the first order is determined as the master node, you can start from the temporary node whose creation order is the second order, the temporary node whose creation order is the third order, and the temporary node whose creation order is the fourth From the temporary nodes of the sequence bit, the temporary node whose creation sequence is the second specified sequence bit is obtained, where the second specified sequence bit can be any one of the second sequence bit, the third sequence bit, and the fourth sequence bit. Make a limit.
  • the temporary node whose creation order is the second specified order position can be obtained. For example, if the second specified order position is the second order position, you can create multiple temporary nodes. In the process of the temporary node, the temporary node whose creation order is the second order is obtained. In some implementations, after the creation of multiple temporary nodes is completed, the temporary node whose creation order is the second specified order position can be obtained. For example, if the second specified order position is the second order position, you can create multiple temporary nodes When the node ends, the temporary node whose creation order is the second order is obtained from multiple temporary nodes.
  • Step S322 Determine the temporary node whose creation sequence is the second specified sequence position as the target slave node.
  • the temporary node whose creation order is the second designated order position may be determined as the target Slave node. For example, if the multiple temporary nodes other than the main node include the temporary node whose creation order is the second order, the temporary node whose creation order is the third order, and the temporary node whose creation order is the fourth order, when the second When the designated sequence bit is the second sequence bit, the temporary node whose creation sequence is the second sequence bit can be determined as the target slave node.
  • the second designated sequence bit is the second sequence bit, that is, the first temporary node created after the temporary node serving as the master node is used as the target slave node.
  • Step S330 Control the master node to send the survival message to the target slave node.
  • Step S340 When the target slave node does not receive the survival message sent by the master node, use the target slave node as the current master node.
  • step S330 to step S340 please refer to step S120 to step S130, which will not be repeated here.
  • Step S350 Delete the master node in the zookeeper cluster, and sequentially increase the order positions of slave nodes among the plurality of slave nodes except for the target slave node.
  • the master node after it is determined that the master node is out of service, the master node can be deleted from the zookeeper cluster, and the order of the slave nodes other than the target slave node among the plurality of slave node points can be sequentially increased.
  • the out-of-service node (master node) can be deleted from the zookeeper cluster directory, and the order of the slave nodes is increased in turn.
  • since the target slave node is already the current master The node therefore, can promote the order bits of multiple slave nodes except the target slave node.
  • the master node is a temporary node whose creation order is the first order position
  • the target slave node is a temporary node whose creation order is the second order position
  • Temporary nodes and temporary nodes whose creation order is the fourth order then, when the main node (the temporary node whose creation order is the first order) is out of service, the temporary node whose creation order is the first order can be deleted, and it will be created
  • the temporary node with the second order as the current master node, and the order of the temporary node with the third order of creation is promoted to the first order, and the temporary node with the creation order of the fourth order is promoted to the first order.
  • the order bit is promoted to the second order bit.
  • FIG. 6 shows a schematic flow chart of step S350 of the method for selecting a master node shown in FIG. 4 of the present application.
  • the flow shown in FIG. 6 will be described in detail below.
  • the method may specifically include the following step:
  • Step S351 Restart the master node.
  • the slave node when the slave node does not receive the survival message sent by the slave node, it indicates that the master node may be currently in a down state, where the cause of the master node in the down state may be caused by the master node itself , It may also be caused by the outside. Therefore, you can try to restart the master node. If the master node can restart successfully, it means that the cause of the main node downtime is externally caused, that is, the master node can still continue to serve externally. If the master node Failure to restart successfully indicates that the cause of the downtime of the master node is caused by itself, that is, it indicates that the master node cannot continue to serve externally.
  • Step S352 When the master node restarts unsuccessfully, delete the master node from the zookeeper cluster, and sequentially increase the order positions of slave nodes among the plurality of slave nodes except for the target slave node.
  • the master node when the master node restarts unsuccessfully, it means that the cause of the master node downtime is caused by itself, that is, the master node can no longer continue to serve externally. Therefore, the master node can be deleted from the zookeeper cluster and upgraded in turn The sequence bits of the slave nodes excluding the target slave node among the plurality of slave nodes.
  • Step S353 When the master node restarts successfully, switch the master node to a slave node to join the zookeeper cluster.
  • the master node when the master node restarts successfully, is the cause of the master node downtime caused by external causes, that is, the master node can continue to serve externally, and since the target slave node is already the current master node at this time, In order to ensure the service continuity of the system, therefore, the master node can be switched to a slave node to join the zookeeper cluster to perform external services when needed.
  • the sequence bit of the master node can be switched to the sequence bit of the target slave node, or after the sequence bit of the master node is switched to the sequence bit of all slave nodes, There is no limitation here.
  • Step S360 Monitoring the service status of the zookeeper cluster.
  • the service status of the zookeeper cluster can be monitored to determine whether the zookeeper cluster can normally serve externally after the slave node is promoted to the current master node.
  • Step S370 When the zookeeper cluster is in a service state, control the current master node to send a survival message to a designated slave node, where the designated slave node is the target slave node among the plurality of slave nodes Any one of the slave nodes.
  • the zookeeper cluster when it is detected that the zookeeper cluster is not in a service state, it indicates that the zookeeper cluster stops external services. Therefore, as a way, the zookeeper cluster can be inspected as a whole to determine whether the zookeeper cluster is out of service due to other reasons. As another hint, you can re-use other slave nodes as the current master node to determine Whether it is the external service suspension caused by the former slave node of the master node, etc., is not limited here.
  • slave nodes other than the target slave node can be selected from multiple slave nodes. Select any slave node as the designated slave node, and control the current master node to send a survival message to the designated slave node, so as to quickly use the designated slave node as the current master node when the current master node stops serving.
  • FIG. 7 shows a schematic flow chart of step S370 of the method for selecting a master node shown in FIG. 4 of the present application.
  • the flow shown in FIG. 7 will be described in detail below.
  • the method may specifically include the following step:
  • Step S371 When the zookeeper cluster is in the service state, obtain the current sequence bits of the slave nodes except the target slave node among the plurality of slave nodes.
  • the current sequence bits of the slave nodes other than the target slave node among the plurality of slave nodes can be obtained. For example, if the master node is a temporary node whose creation order is the first order position, and the target slave node is a temporary node whose creation order is the second order position, among the multiple slave nodes, in addition to the target node, there is also a temporary node whose creation order is the third order position.
  • Temporary nodes and temporary nodes whose creation order is the fourth order then, when the main node (the temporary node whose creation order is the first order) is out of service, the temporary node whose creation order is the first order can be deleted, and it will be created
  • the temporary node with the second order as the current master node, and the order of the temporary node with the third order of creation is promoted to the first order, and the temporary node with the creation order of the fourth order is promoted to the first order.
  • the sequence bit is promoted to the second sequence bit.
  • multiple slave nodes temporary nodes in the second order of creation, temporary nodes in the third order in the creation order, and temporary nodes in the fourth order in the creation order
  • the target slave node the creation order is the first
  • the secondary nodes other than the temporary node with the second order also include the temporary node with the creation order of the third order and the temporary node with the creation order of the fourth order.
  • the current node of the temporary node with the creation order of the third order The sequence bit is the first sequence bit
  • the current sequence bit of the temporary node whose creation sequence is the fourth sequence bit is the second sequence bit.
  • Step S372 Determine the slave node whose current order position is the first order position as the designated slave node.
  • the slave node whose current sequence position is the first sequence position may be obtained, and the current sequence position may be the first sequence position.
  • the slave node with a sequence bit is determined as the designated slave node.
  • the temporary node whose creation order is the third order is determined as the designated slave node.
  • Step S373 Control the current master node to send a survival message to the designated slave node.
  • the current master node after determining the current master node and the designated slave node, the current master node can be controlled to send a survival message to the designated slave node.
  • the survival message sent by the current master node to the designated slave node may only be used to indicate that the current master node is in a survival state, and the content, type, and form of the survival message are not limited here.
  • the current master node can be controlled to send survival messages to designated slave nodes in real time, the current master node can be controlled to send survival messages to designated slave nodes at specified time intervals, and the current master node can be controlled to send survival messages to designated slave nodes at a specified time. Survival messages can control the current master node to send survival messages to designated slave nodes according to other specified rules.
  • the current master node in order to improve the service continuity of the system, can be controlled to send a survival message to the designated slave node in real time.
  • multiple temporary nodes are created in the zookeeper cluster, and the master node and the slave node are determined from the multiple temporary nodes, and a slave node is selected from the multiple slave nodes as the target slave
  • the node controls the master node to send survival messages to the target slave node.
  • the target slave node does not receive the survival message sent by the master node
  • the target slave node is used as the current master node
  • the master node is deleted from the zookeeper cluster
  • multiple The order of the slave nodes except the target slave node in the slave node monitors the service status of the zookeeper cluster.
  • the zookeeper cluster When the zookeeper cluster is in the service state, it controls the current master node to send survival messages to the designated slave node.
  • the designated slave node is more than one. Any one of the slave nodes except the target slave node among the slave nodes.
  • the master node selection method shown in FIG. 1 in this embodiment, when the number of slave nodes is multiple, one slave node is selected from the multiple slave nodes as the target slave node to receive the survival message sent by the master node. To ensure the normal message interaction between the master node and the slave node.
  • this embodiment also monitors the service status of the zookeeper cluster after the target slave node is used as the current master node, and controls the current master node to send survival messages to the designated slave node when the zookeeper cluster is in the service state, so as to improve the service of the system Continuity and availability.
  • FIG. 8 shows a schematic flowchart of a method for selecting a master node according to another embodiment of the present application. The process shown in FIG. 8 will be described in detail below.
  • the method for selecting the master node may specifically include the following steps:
  • Step S410 Obtain node deployment information of the distributed storage system.
  • this solution can perform node management and distributed coordination on the distributed kv storage system based on zookeeper.
  • the node deployment information of the distributed storage system may be obtained, where the obtained node deployment information of the distributed system may include the number of nodes in the distributed system, the relationship between the nodes in the distributed system, The nodes belonging to the same service among the nodes in the distributed system are not limited here.
  • Step S420 Based on the node deployment information, create the multiple temporary nodes in the zookeeper cluster, and determine the master node and the slave node from the multiple temporary nodes.
  • multiple temporary nodes can be created in the zookeeper cluster, and the master node and the slave node can be determined from the multiple temporary nodes.
  • FIG. 9 shows a schematic flowchart of step S420 of the method for selecting a master node shown in FIG. 8 of the present application.
  • the process shown in FIG. 9 will be described in detail below, and the method may specifically include the following steps:
  • Step S421 Based on the node deployment information, obtain master and slave nodes that belong to the same service.
  • the master and slave nodes that belong to the same service in each node in the distributed storage system can be obtained, that is, the node in the distributed storage system can be obtained.
  • the master nodes and slave nodes belonging to the same service in each node of, where the master-slave nodes of the same service represent the master-slave nodes in the same parent directory.
  • Step S422 Register the master and slave nodes belonging to the same service in the zookeeper cluster to generate the plurality of temporary nodes, and determine the master node and the slave node from the plurality of temporary nodes.
  • the master and slave nodes belonging to the same service can be registered in the zookeeper cluster to generate multiple temporary nodes, and the master node and the slave node can be determined from the multiple temporary nodes .
  • the master-slave nodes of the same service can be registered to generate multiple temporary sequence nodes in the same parent directory of zookeeper, and the master-slave nodes can be determined according to the creation order of the temporary sequence nodes. Node and slave node.
  • Step S430 Control the master node to send a survival message to the slave node.
  • Step S440 When the slave node does not receive the survival message sent by the master node, the slave node is used as the current master node.
  • step S430 to step S440 please refer to step S120 to step S130, which will not be repeated here.
  • the method for selecting a master node obtained by another embodiment of the present application obtains node deployment information of a distributed storage system, creates multiple temporary nodes in the zookeeper cluster based on the node deployment information, and determines the master node and the slave from the multiple temporary nodes
  • the node controls the master node to send a survival message to the slave node.
  • the slave node does not receive the survival message sent by the master node, the slave node is promoted to the current master node.
  • this embodiment also obtains node deployment information of the distributed storage system, and creates multiple temporary nodes in the zookeeper cluster based on the node deployment information to improve the availability of the system.
  • FIG. 10 shows a schematic flowchart of a method for selecting a master node according to another embodiment of the present application.
  • the process shown in FIG. 10 will be described in detail below.
  • the method for selecting the master node may specifically include the following steps:
  • Step S510 Create the multiple temporary nodes under the same parent directory of the zookeeper cluster, and determine the master node and the slave node from the multiple temporary nodes.
  • multiple temporary nodes can be created under the same parent directory of the zookeeper cluster, and the master node and the slave node can be determined from the multiple temporary nodes.
  • the same service node can be used as the parent node of the zookeeper cluster, and multiple temporary nodes can be created under the parent node.
  • the temporary nodes represent the master-slave process of the same service in the distributed storage system, that is, the slave multiple One temporary node can determine the master node and the slave node.
  • Step S520 Control the master node to send a survival message to the slave node.
  • Step S530 When the slave node does not receive the survival message sent by the master node, the slave node is used as the current master node.
  • step S520-step S530 please refer to step S120-step S130, which will not be repeated here.
  • the method for selecting the master node provided by another embodiment of the present application is to create multiple temporary nodes in the same parent directory of the zookeeper cluster, and determine the master node and the slave node from the multiple temporary nodes, and control the master node to send survival data to the slave node Message, when the slave node does not receive the survival message sent by the master node, the slave node will be the current master node.
  • this embodiment also creates multiple temporary nodes in the same parent directory of the zookeeper cluster to improve the availability of the system.
  • FIG. 11 shows a block diagram of a master node selecting apparatus 200 according to an embodiment of the present application.
  • the master node selection device 200 includes: a temporary node creation module 210, a survival message sending module 220, and a master node selection module 230, wherein:
  • the temporary node creation module 210 is configured to create multiple temporary nodes in the zookeeper cluster, and determine a master node and a slave node from the multiple temporary nodes.
  • the temporary node creation module 210 includes: a first temporary node creation sub-module and a first node determination sub-module, wherein:
  • the first temporary node creation submodule is configured to create the multiple temporary nodes in the zookeeper cluster, and obtain the temporary nodes whose creation order is the first designated order from the multiple temporary nodes.
  • the first node determining sub-module is configured to determine the temporary node whose creation order is the first specified order bit as the main node, and determine the temporary node among the plurality of temporary nodes except the main node Is the slave node.
  • the temporary node creation module 210 includes: a node deployment information acquisition sub-module and a second temporary node creation sub-module, where:
  • the node deployment information acquisition sub-module is used to acquire the node deployment information of the distributed storage system.
  • the second temporary node creation submodule is used to create the multiple temporary nodes in the zookeeper cluster based on the node deployment information, and determine the master node and the slave node from the multiple temporary nodes .
  • the second temporary node creation sub-module includes: a master-slave node acquisition unit and a second temporary node creation unit, wherein:
  • the master-slave node acquiring unit is configured to acquire master-slave nodes belonging to the same service based on the node deployment information.
  • the second temporary node creation unit is configured to register the master and slave nodes belonging to the same service in the zookeeper cluster to generate the plurality of temporary nodes, and determine the master node and all the temporary nodes from the plurality of temporary nodes.
  • the slave node is configured to register the master and slave nodes belonging to the same service in the zookeeper cluster to generate the plurality of temporary nodes, and determine the master node and all the temporary nodes from the plurality of temporary nodes.
  • the temporary node creation module 210 includes: a third temporary node creation sub-module, wherein:
  • the third temporary node creation submodule is used to create the multiple temporary nodes under the same parent directory of the zookeeper cluster, and determine the master node and the slave node from the multiple temporary nodes.
  • the survival message sending module 220 is configured to control the master node to send a survival message to the slave node.
  • survival message sending module 220 includes: an identification information acquisition submodule and a first survival message sending submodule, wherein:
  • the identification information acquisition sub-module is used to acquire the identification information of the slave node.
  • the first survival message sending submodule is configured to control the master node to send the survival message to the slave node based on the identification information.
  • the identification information includes International Internet Protocol IP information
  • the first survival message sending submodule includes: a first survival message sending unit, wherein:
  • the first survival message sending unit is configured to control the master node to send the survival message to the slave node based on the IP information.
  • the survival message sending module 220 includes: a target slave node selection sub-module and a second survival message sending sub-module, wherein:
  • the target slave node selection sub-module is used to select a slave node from multiple slave nodes as the target slave node.
  • the target slave node selection submodule includes: a temporary node acquisition unit and a target slave node determination unit, wherein:
  • the temporary node obtaining unit is configured to obtain a temporary node whose creation order is the second specified order position from the plurality of temporary nodes.
  • the target slave node determining unit is configured to determine the temporary node whose creation order is the second specified order position as the target slave node.
  • target slave node selection submodule includes: a target slave node selection unit, wherein:
  • the target slave node selection unit is configured to randomly select a slave node from the plurality of slave nodes as the target slave node.
  • the second survival message sending submodule is configured to control the master node to send the survival message to the target slave node.
  • the master node selection module 230 is configured to use the slave node as the current master node when the slave node does not receive the survival message sent by the master node.
  • main node selection module 230 includes: a main node selection sub-module and a sequential position promotion sub-module, wherein:
  • the master node selection submodule is configured to use the target slave node as the current master node when the target slave node does not receive the survival message sent by the master node.
  • the sequence position promotion sub-module is used to delete the master node in the zookeeper cluster, and sequentially promote the sequence positions of the slave nodes of the plurality of slave nodes except the target slave node.
  • sequence position promotion submodule includes: a master node restart unit, a sequence position promotion unit, and a master node switching unit, wherein:
  • the master node restarting unit is used to restart the master node.
  • a sequential bit promotion unit which is used to delete the master node from the zookeeper cluster when the master node restarts unsuccessfully, and sequentially promote the slave nodes of the plurality of slave nodes other than the target slave node The order bits.
  • the master node switching unit is configured to switch the master node to a slave node to join the zookeeper cluster when the master node restarts successfully.
  • the master node selection module 230 includes: a service status monitoring submodule and a third survival message sending submodule, wherein:
  • the service status monitoring sub-module is used to monitor the service status of the zookeeper cluster.
  • the third survival message sending sub-module is used to control the current master node to send a survival message to a designated slave node when the zookeeper cluster is in a service state, wherein the designated slave node is divided from the plurality of slave nodes Any one of the slave nodes other than the target slave node.
  • the third survival message sending submodule includes: a current sequence bit acquiring unit, a designated slave node determining unit, and a third survival message sending unit, wherein:
  • the current sequence bit obtaining unit is configured to obtain the current sequence bit of the slave nodes of the plurality of slave nodes excluding the target slave node when the zookeeper cluster is in a service state.
  • the designated slave node determining unit is configured to determine the slave node whose current order position is the first order position as the designated slave node.
  • the third survival message sending unit is configured to control the current master node to send a survival message to the designated slave node.
  • the coupling between the modules may be electrical, mechanical or other forms of coupling.
  • the functional modules in the various embodiments of the present application may be integrated into one processing module, or each module may exist alone physically, or two or more modules may be integrated into one module.
  • the above-mentioned integrated modules can be implemented in the form of hardware or software functional modules.
  • FIG. 12 shows a structural block diagram of an electronic device 100 provided by an embodiment of the present application.
  • the electronic device 100 may be an electronic device capable of running application programs, such as a smart phone, a tablet computer, or an e-book.
  • the electronic device 100 in this application may include one or more of the following components: a processor 110, a memory 120, and one or more application programs.
  • One or more application programs may be stored in the memory 120 and configured to be Or multiple processors 110 execute, and one or more programs are configured to execute the method described in the foregoing method embodiment.
  • the processor 110 may include one or more processing cores.
  • the processor 110 uses various interfaces and lines to connect various parts of the entire electronic device 100, and executes by running or executing instructions, programs, code sets, or instruction sets stored in the memory 120, and calling data stored in the memory 120.
  • Various functions and processing data of the electronic device 100 may adopt at least one of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), and Programmable Logic Array (PLA).
  • DSP Digital Signal Processing
  • FPGA Field-Programmable Gate Array
  • PDA Programmable Logic Array
  • the processor 110 may integrate one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), a modem, and the like.
  • the CPU mainly processes the operating system, user interface, and application programs; the GPU is used for rendering and drawing the content to be displayed; the modem is used for processing wireless communication. It can be understood that the above-mentioned modem may not be integrated into the processor 110, but may be implemented by a communication chip alone.
  • the memory 120 may include random access memory (RAM) or read-only memory (Read-Only Memory).
  • the memory 120 may be used to store instructions, programs, codes, code sets or instruction sets.
  • the memory 120 may include a program storage area and a data storage area, where the program storage area may store instructions for implementing the operating system and instructions for implementing at least one function (such as touch function, sound playback function, image playback function, etc.) , Instructions used to implement the following various method embodiments, etc.
  • the storage data area can also store data (such as phone book, audio and video data, chat record data) created by the electronic device 100 during use.
  • FIG. 13 shows a structural block diagram of a computer-readable storage medium provided by an embodiment of the present application.
  • the computer-readable medium 300 stores program code, and the program code can be invoked by a processor to execute the method described in the foregoing method embodiment.
  • the computer-readable storage medium 300 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read Only Memory), EPROM, hard disk, or ROM.
  • the computer-readable storage medium 300 includes a non-transitory computer-readable storage medium.
  • the computer-readable storage medium 300 has storage space for the program code 310 for executing any method steps in the above-mentioned methods. These program codes can be read from or written into one or more computer program products.
  • the program code 310 may be compressed in a suitable form, for example.
  • the method, device, electronic equipment, and storage medium for selecting the master node create multiple temporary nodes in the zookeeper cluster, and determine the master node and the slave node from the multiple temporary nodes, and control the master node.
  • the node sends a survival message to the slave node.
  • the slave node does not receive the survival message sent by the master node, the slave node becomes the current master node, thereby controlling the master node to send the survival message to the slave node.
  • the slave node stops serving the slave node It can immediately perceive its information, so as to quickly promote as the current master node to improve the service continuity and availability of the system.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Mobile Radio Communication Systems (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

本申请公开了一种主节点选取方法、装置、电子设备以及存储介质,涉及计算机技术领域。所述方法包括:在zookeeper集群中创建多个临时节点,并从多个临时节点中确定主节点和从节点,控制主节点向从节点发送存活消息,当从节点没有接收到主节点发送的存活消息时,将从节点作为当前主节点。本申请实施例提供的主节点选取方法、装置、电子设备以及存储介质通过控制主节点向从节点发送存活消息,当主节点停止服务时,从节点能马上感知其信息,从而快速提升作为当前主节点,以提升系统的服务连续性和可用性。

Description

主节点选取方法、装置、电子设备以及存储介质 技术领域
本申请涉及计算机技术领域,更具体地,涉及一种主节点选取方法、装置、电子设备以及存储介质。
背景技术
目前,基于zookeeper的选主方法,都是利用zookeeper去感知集群各节点的信息。
发明内容
鉴于上述问题,本申请提出了一种主节点选取方法、装置、电子设备以及存储介质,以解决上述问题。
第一方面,本申请实施例提供了一种主节点选取方法,所述方法包括:在zookeeper集群中创建多个临时节点,并从所述多个临时节点中确定主节点和从节点;控制所述主节点向所述从节点发送存活消息;当所述从节点没有接收到所述主节点发送的存活消息时,将所述从节点作为当前主节点。
第二方面,本申请实施例提供了一种主节点选取装置,所述装置包括:
临时节点创建模块,用于在zookeeper集群中创建多个临时节点,并从所述多个临时节点中确定主节点和从节点;存活消息发送模块,用于控制所述主节点向所述从节点发送存活消息;主节点选取模块,用于当所述从节点没有接收到所述主节点发送的存活消息时,将所述从节点作为当前主节点。
第三方面,本申请实施例提供了一种电子设备,包括存储器和处理器,所述存储器耦接到所述处理器,所述存储器存储指令,当所述指令由所述处理器执行时所述处理器执行上述方法。
第四方面,本申请实施例提供了一种计算机可读取存储介质,所述计算机可读取存储介质中存储有程序代码,所述程序代码可被处理器调用执行上述方法。
本申请实施例提供的主节点选取方法、装置、电子设备以及存储介质,在zookeeper集群中创建多个临时节点,并从多个临时节点中确定主节点和从节点,控制主节点向从节点发送存活消息,当从节点没有接收到主节点发送的存活消息时,将从节点作为当前主节点,从而通过控制主节点向从节点发送存活消息,当主节点停止服务时,从节点能马上感知其信息,从而快速提升作为当前主节点,以提升系统的服务连续性和可用性。
附图说明
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其它的附图。
图1示出了本申请一个实施例提供的主节点选取方法的流程示意图;
图2示出了本申请实施例提供的主节点选取的示意图;
图3示出了本申请又一个实施例提供的主节点选取方法的流程示意图;
图4示出了本申请再一个实施例提供的主节点选取方法的流程示意图;
图5示出了本申请的图4所示的主节点选取方法的步骤S320的流程示意图;
图6示出了本申请的图4所示的主节点选取方法的步骤S350的流程示意图;
图7示出了本申请的图4所示的主节点选取方法的步骤S370的流程示意图;
图8示出了本申请另一个实施例提供的主节点选取方法的流程示意图;
图9示出了本申请的图8所示的主节点选取方法的步骤S420的流程示意图;
图10示出了本申请又再一个实施例提供的主节点选取方法的流程示意图;
图11示出了本申请实施例提供的主节点选取装置的模块框图;
图12示出了本申请实施例用于执行根据本申请实施例的主节点选取方法的电子设备的框图;
图13示出了本申请实施例的用于保存或者携带实现根据本申请实施例的主节点选取方法的程序代码的存储单元。
具体实施方式
为了使本技术领域的人员更好地理解本申请方案,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述。
在互联网项目中,由于业务规模越来越大,对系统的高可用提出了更高的要求。目前,一般采取集群多活的部署架构,对于系统中某一节点出现故障,不影响整体的运行。但是在某些场景情况下(如唯一账号的使用),不能采取多活的方式,而只能采取主从的方式保证系统的高可用,在主节点发生故障时,由从节点接管业务。目前,基于一种分布式应用协调系统zookeeper的选主方法,都是利用zookeeper服务器去感知各节点的信息,当主节点停止服务时,zookeeper拉取不到该主节点的信息,便将后续的从节点提升为主节点接管业务。然而,发明人在研究中发现,当主节点停止服务时,zookeeper需要较长时间去感知确定该主节点的存活状态,在这段时间内,整个zookeeper集群对外停止服务,这大大降低了服务质量,使系统的可用性下降。
针对上述问题,发明人经过长期的研究发现,并提出了本申请实施例提供的主节点选取方法、装置、电子设备以及存储介质,通过控制主节点向从节点发送存活消息,当主节点停止服务时,从节点能马上感知其信息,从而快速提升作为当前主节点,以提升系统的服务连续性和可用性。其中,具体的主节点选取方法在后续的实施例中进行详细的说明。
请参阅图1,图1示出了申请一个实施例提供的主节点选取方法的流程示意图。所述主节点选取方法用于通过控制主节点向从节点发送存活消息,当主节点停止服务时,从节点能马上感知其信息,从而快速提升作为当前主节点,以提升系统的服务连续性和可用性。在具体的实施例中,所述主节点选取方法应用于如图11所示的主节点选取装置200的电子设备100(图12)。下面将以电子设备为例,说明本实施例的具体流程,当然,可以理解的,本实施例所应用的电子设备可以视作控制台,用于控制zookeeper集群中的各个zookeeper服务器,其中,该电子设备可以是zookeeper集群中的其中一个或多个服务器,也可以是智能手机、平板电脑、台式电脑等,在此不做限定。下面将针对图1所示的流程进行详细的阐述,所述主节点选取方法具体可以包括以下步骤:
步骤S110:在zookeeper集群中创建多个临时节点,并从所述多个临时节点中确定主节点和从节点。
在本实施例中,可以在zookeeper集群中创建多个临时节点,并从所创建的多个临时节点中确定主节点和从节点,其中,从所创建的多个临时节点中确定的主节点的数量为一个,从所创建的多个临时节点中确定的从节点的数量为一个或多个,在此不做限定。
在一些实施方式中,在zookeeper节点可以包括zookeeper持久节点和zookeeper临时节点。其中,zookeeper持久节点在被创建后,就会一直存在于zookeeper服务器上,直到有删除操作来主动删除这个节点,例如,直到有delete命令指示删除该节点,zookeeper持久节点可以用于保存一些应用数据,即时创建该zookeeper持久节点的创建者崩溃或者断开连接,数据也不会丢失,例如在主-从模式中,需要保存从节点的人物分配情况,即时分配任务的主节点已经崩溃。其中,zookeeper临时节点的生成周期和客户端会话绑定在一起,客户端会话失效,则这个节点就会被自动清除,即zookeeper传达了应用某些方面的信息,仅当创建者有效时信息才得以保存,例如在主-从模式中,当主节点创建zookeeper临时节点时,该zookeeper临时节点存在意味着主节点存在,主节点状态处于正常运行中,如果zookeeper临时节点消失,则证明主节点崩溃。
其中,由于在注册zookeeper临时节点的创建者失去连接,那么这个zookeeper临时节点 就会被zookeeper删除,而节点选主的过程就是依据这个特征,因此,在本实施例中,可以在zookeeper集群中创建多个临时节点,并从多个临时节点中选取确定主节点和从节点。
在一些实施方式中,从多个临时节点中确定主节点和从节点的方式可以包括但不限于:从多个临时节点中随机选取临时节点作为主节点,并将多个临时节点中的剩余临时节点作为从节点;从多个临时节点中将注册成功的临时节点作为主节点,并将多个临时节点中注册不成功的临时节点作为从节点;从多个临时节点中最先创建的临时节点作为主节点,并将多个临时节点中在最先创建的临时节点之后创建的临时节点作为从节点;可以按预设规则从多个临时节点中确定主节点和从节点;可以根据用户选择从多个临时节点中确定主节点和从节点。
步骤S120:控制所述主节点向所述从节点发送存活消息。
在本实施例中,在从多个临时节点中确定主节点和从节点后,可以控制主节点向从节点发送存活消息。在一些实施方式中,主节点向从节点发送的存活消息可以仅用于表征主节点处于存活状态,对于存活消息的的内容、类型以及形式等,在此不做限定。
在一些实施方式中,可以控制主节点实时向从节点发送存活消息,可以控制主节点按指定时间间隔向从节点发送存活消息,可以控制主节点按指定时间向从节点发送存活消息,可以控制主节点按其他指定规则向从节点发送存活消息等。可选地,在本实施例中,为了提升系统的服务连续性,可以控制主节点实时向从节点发送存活消息。
步骤S130:当所述从节点没有接收到所述主节点发送的存活消息时,将所述从节点作为当前主节点。
在一些实施方式中,当从节点接收到主节点发送的存活消息时,可以确定主节点处于正常服务的状态,则可以保持原本确定的主节点和从节点不变。
在一些实施方式中,当从节点没有接收到主节点发送的存活消息时,可以确定主节点处于停止服务的状态,则可以在zookeeper集群中删除该主节点,并将从节点作为当前主节点,从而实现zookeeper集群可以继续对外提供读取服务,这样提高了整个系统的可读性、可写性,保证了系统的高可用、可服务性,实现了主节点和从节点的无差别切换,同时,整个选主过程清晰明了,降低了系统的编程难度,提高了开发效率。
请参阅图2,图2示出了示出了本申请实施例提供的主节点选取的示意图。如图2所示,主节点1可以向从节点2发送消息,以表征主节点处于存活状态,当从节点2没有接收到主节点1发送的存活消息时,可以将主节点1从zookeeper集群中删除,并将从节点2作为当前主节点。
本申请一个实施例提供的主节点选取方法,在zookeeper集群中创建多个临时节点,并从多个临时节点中确定主节点和从节点,控制主节点向从节点发送存活消息,当从节点没有接收到主节点发送的存活消息时,将从节点作为当前主节点,从而通过控制主节点向从节点发送存活消息,当主节点停止服务时,从节点能马上感知其信息,从而快速提升作为当前主节点,以提升系统的服务连续性和可用性。
请参阅图3,图3示出了本申请又一个实施例提供的主节点选取方法的流程示意图。下面将针对图3所示的流程进行详细的阐述,所述主节点选取方法具体可以包括以下步骤:
步骤S210:在所述zookeeper集群中创建所述多个临时节点,并从所述多个临时节点中获取创建顺序为第一指定顺序位的临时节点。
其中,在zookeeper集群中创建多个临时节点时,多个临时节点是依序进行创建的,因此,所创建的多个临时节点中的每个临时节点均对应有创建顺序,例如,若所创建的多个临时节点的数量为四个,则四个临时节点的创建顺序分别对应的第一顺序位、第二顺序位、第三顺序位以及第四顺序位。
在一些实施方式中,在zookeeper集群中创建多个临时节点后,可以从多个临时节点中获取创建顺序为第一指定顺序位的临时节点。例如,当多个临时节点的数量为四个,且四个临时节点的创建顺序分别对应的第一顺序位、第二顺序位、第三顺序位以及第四顺序位,则第 一指定顺序为可以为第一顺序位、第二顺序位、第三顺序位以及第四顺序位中的任意一个,在此不做限定。
在一些实施方式中,可以在创建多个临时节点的过程中,获取创建顺序为第一指定顺序位的临时节点,例如,若第一指定顺序位为第一顺序位,则可以在创建多个临时节点的过程中,获取创建顺序为第一顺序位的临时节点。在一些实施方式中,可以在创建多个临时节点结束后,获取创建顺序为第一指定顺序位的临时节点,例如,若第一指定顺序位为第一顺序位,则可以在创建多个临时节点结束时,从多个临时节点中获取创建顺序为第一顺序位的临时节点。
步骤S220:将所述创建顺序为第一指定顺序位的临时节点确定为所述主节点,并将所述多个临时节点中除所述主节点之外的临时节点确定为所述从节点。
在本实施例中,在从多个临时节点中获取创建顺序为第一指定顺序位的临时节点后,可以将该创建顺序为第一指定顺序位的临时节点确定为主节点,并将多个临时节点中除该主节点之外的临时节点确定为从节点。例如,若多个临时节点包括创建顺序为第一顺序位的临时节点、创建顺序为第二顺序位的临时节点、创建顺序为第三顺序位的临时节点以及创建顺序为第四顺序位的临时节点,当第一指定顺序位为第一顺序位时,则可以将创建顺序为第一顺序位的临时节点确定为主节点,并将创建顺序为第二顺序位的临时节点、创建顺序为第三顺序位的临时节点以及创建顺序为第四顺序位的临时节点确定为从节点。
可选地,在本实施例中,该第一指定顺序位为第一顺序位,即将最先创建的临时节点作为主节点,将在之后创建的临时节点作为从节点。
步骤S230:获取所述从节点的标识信息。
在本实施例中,在从多个临时节点中确定主节点和从节点后,可以获取该从节点的标识信息。在一些实施方式中,可以从zookeeper服务器中拉取该从节点的标识信息。在一些实施方式中,该标识信息可以包括国际互联协议IP信息,则可以从zookeeper服务器中拉取该从节点的IP信息。
步骤S240:基于所述标识信息,控制所述主节点向所述从节点发送所述存活消息。
在本实施例中,在获取到从节点的标识信息后,可以基于该从节点的标识信息,控制主节点向从节点发送存活消息,与保证主节点所发出的存活消息能准确发送至从节点。在一些实施方式中,当标识信息为IP信息时,在获取到从节点的IP信息后,可以基于该IP信息,控制主节点向从节点发送存活消息。
步骤S250:当所述从节点没有接收到所述主节点发送的存活消息时,将所述从节点作为当前主节点。
其中,步骤S250的具体描述请参阅步骤S130,在此不再赘述。
本申请又一个实施例提供的主节点选取方法,在zookeeper集群中创建多个临时节点,并从多个临时节点中获取创建顺序为第一指定顺序位的临时节点,将创建顺序为第一指定顺序位的临时节点确定为主节点,并将多个临时节点中除主节点之外的临时节点确定为从节点,获取从节点的标识信息,基于该标识信息,控制主节点向从节点发送存活消息,当从节点没有接收到主节点发送的存活消息时,将从节点作为当前主节点。相较于图1所示的主节点选取方法,本实施例还根据临时节点的创建顺序确定主节点和从节点,以提升主节点和从节点的获取速度。另外,本实施例还根据从节点的标识信息向从节点发送存活消息,以保证存活消息的准确发送。
请参阅图4,图4示出了本申请再一个实施例提供的主节点选取方法的流程示意图。下面将针对图4所示的流程进行详细的阐述,其中,从节点的数据为多个,所述主节点选取方法具体可以包括以下步骤:
步骤S310:在zookeeper集群中创建多个临时节点,并从所述多个临时节点中确定主节点和从节点。
其中,步骤S310的具体描述请参阅步骤S110,在此不再赘述。
步骤S320:从多个从节点中选取一个从节点作为目标从节点。
在本实施例中,从所创建的多个临时节点中确定的从节点的数量为多个,则可以从多个从节点中选取一个从节点作为目标从节点,并通过目标从节点接收主节点发送的存活消息。例如,若多个临时节点包括创建顺序为第一顺序位的临时节点、创建顺序为第二顺序位的临时节点、创建顺序为第三顺序位的临时节点以及创建顺序为第四顺序位的临时节点,且创建顺序为第一顺序位的临时节点被确定为主节点时,那么,多个从节点包括创建顺序为第二顺序位的临时节点、创建顺序为第三顺序位的临时节点以及创建顺序为第四顺序位的临时节点,则可以从创建顺序为第二顺序位的临时节点、创建顺序为第三顺序位的临时节点以及创建顺序为第四顺序位的临时节点中选取一个临时节点作为目标从节点。
请参阅图5,图5示出了本申请的图4所示的主节点选取方法的步骤S320的流程示意图,下面将针对图5所示的流程进行详细的阐述,所述方法具体可以包括以下步骤:
步骤S321:从所述多个临时节点中获取创建顺序为第二指定顺序位的临时节点。
在一些实施方式中,在获取除主节点之外的多个临时节点后,可以从除主节点之外的多个临时节点中获取创建顺序为第二指定顺序位的临时节点。例如,若多个临时节点包括创建顺序为第一顺序位的临时节点、创建顺序为第二顺序位的临时节点、创建顺序为第三顺序位的临时节点以及创建顺序为第四顺序位的临时节点,且创建顺序为第一顺序位的临时节点被确定为主节点时,则可以从创建顺序为第二顺序位的临时节点、创建顺序为第三顺序位的临时节点以及创建顺序为第四顺序位的临时节点中获取创建顺序为第二指定顺序位的临时节点,其中,第二指定顺序位可以为第二顺序位、第三顺序位以及第四顺序位中的任意一个,在此不做限定。
在一些实施方式中,可以在创建多个临时节点的过程中,获取创建顺序为第二指定顺序位的临时节点,例如,若第二指定顺序位为第二顺序位,则可以在创建多个临时节点的过程中,获取创建顺序为第二顺序位的临时节点。在一些实施方式中,可以在创建多个临时节点结束后,获取创建顺序为第二指定顺序位的临时节点,例如,若第二指定顺序位为第二顺序位,则可以在创建多个临时节点结束时,从多个临时节点中获取创建顺序为第二顺序位的临时节点。
步骤S322:将所述创建顺序为第二指定顺序位的临时节点确定为所述目标从节点。
在本实施例中,在从除主节点之外的多个临时节点中获取创建顺序为第二指定顺序位的临时节点后,可以将该创建顺序为第二指定顺序位的临时节点确定为目标从节点。例如,若除主节点之外的多个临时节点包括创建顺序为第二顺序位的临时节点、创建顺序为第三顺序位的临时节点以及创建顺序为第四顺序位的临时节点,当第二指定顺序位为第二顺序位时,则可以将创建顺序为第二顺序位的临时节点确定为目标从节点。
可选地,在本实施例中,该第二指定顺序位为第二顺序位,即将在作为主节点的临时节点之后创建的第一个临时节点作为目标从节点。
步骤S330:控制所述主节点向所述目标从节点发送所述存活消息。
步骤S340:当所述目标从节点没有接收到所述主节点发送的存活消息时,将所述目标从节点作为所述当前主节点。
其中,步骤S330-步骤S340的具体描述请参阅步骤S120-步骤S130,在此不再赘述。
步骤S350:在所述zookeeper集群中删除所述主节点,并依次提升所述多个从节点中除所述目标从节点之外的从节点的顺序位。
在本实施例中,在确定主节点停止服务后,可以在zookeeper集群中删除该主节点,并依次提升多个从节点点中除目标从节点之外的从节点的顺序位。在一些实施方式中,在确定主节点停止服务后,可以在zookeeper集群的目录中删除停止服务的节点(主节点),并依次提升从节点的顺序位,其中,由于目标从节点已经作为当前主节点,因此,可以提升多个从节点中除目标从节点之外的顺序位。
例如,若主节点为创建顺序为第一顺序位的临时节点,目标从节点为创建顺序为第二顺序位的临时节点,多个从节点中除了目标节点还包括创建顺序为第三顺序位的临时节点以及创建顺序为第四顺序位的临时节点,那么,主节点(创建顺序为第一顺序位的临时节点)停止服务时,可以将创建顺序为第一顺序位的临时节点删除,将创建顺序为第二顺序位的临时节点作为当前主节点,并依次将创建顺序为第三顺序位的临时节点的顺序位提升为第一顺序位,以及将创建顺序为第四顺序位的临时节点的顺序位提升为第二顺序位。
请参阅图6,图6示出了本申请的图4所示的主节点选取方法的步骤S350的流程示意图,下面将针对图6所示的流程进行详细的阐述,所述方法具体可以包括以下步骤:
步骤S351:重启所述主节点。
在一些实施方式中,当从节点没有接收到从节点发送的存活消息时,表征该主节点当前可能处于宕机状态,其中,导致主节点处于宕机状态的原因可能是由于主节点自身造成的,也有可能是由于外部造成的,因此,可以尝试重启主节点,如果主节点能够重启成功,表征导致主节点宕机的原因是外部造成的,即表征主节点仍然可以继续对外服务,如果主节点不能够重启成功,表征导致主节点宕机的原因是自身造成的,即表征主节点不能继续对外服务。
步骤S352:当所述主节点重启未成功时,在所述zookeeper集群中删除所述主节点,并依次提升所述多个从节点中除所述目标从节点之外的从节点的顺序位。
在一些实施方式中,当主节点重启未成功时,表征导致主节点宕机的原因是自身造成的,即主节点不能再继续对外服务,因此,可以在zookeeper集群中删除该主节点,并依次提升多个从节点中除目标从节点之外的从节点的顺序位。
步骤S353:当所述主节点重启成功时,将所述主节点切换为从节点加入所述zookeeper集群。
在一些实施方式中,当主节点重启成功时,表征导致主节点宕机的原因是外部造成的吗,即主节点还可以再继续对外服务,而由于此时已经将目标从节点作为当前主节点,以保证系统的服务连续性,因此,可以将主节点切换为从节点加入zookeeper集群中,以在需要是再对外进行服务。在一些实施方式中,在将主节点切换为从节点时,可以将主节点的顺序位切换为目标从节点的顺序位,也可以将主节点的顺序位切换为所有从节点的顺序位之后,在此不做限定。
步骤S360:监测所述zookeeper集群的服务状态。
在一些实施方式中,在将从节点作为当前主节点后,可以对zookeeper集群的服务状态进行监听,以确定将从节点提升为当前主节点后,该zookeeper集群是否可以正常对外服务。
步骤S370:当所述zookeeper集群处于服务状态时,控制所述当前主节点向指定从节点发送存活消息,其中,所述指定从节点为所述多个从节点中除所述目标从节点之外的从节点中的任意一个。
在一些实施方式中,当监测到zookeeper集群没有处于服务状态时,表征zookeeper集群停止对外服务。因此,作为一种方式,可以对zookeeper集群进行整体检测,以确定是否为zookeeper集群的其他原因造成的对外停止服务,作为另一种发暗示,可以重新将其他从节点作为当前主节点,以确定是否为之前作为当主节点的从节点的原因造成的对外停止服务等,在此不做限定。
在一些实施方式中,当监测到zookeeper集群处于服务状态时,表征zookeeper集群正常对外服务,因此,为了提升系统后续的连续服务性,可以从多个从节点中除目标从节点之外的从节点中选取任意一个从节点作为指定从节点,并控制当前主节点向指定从节点发送存活消息,以在当前主节点停止服务时,快速将指定从节点作为当前主节点。
请参阅图7,图7示出了本申请的图4所示的主节点选取方法的步骤S370的流程示意图,下面将针对图7所示的流程进行详细的阐述,所述方法具体可以包括以下步骤:
步骤S371:当所述zookeeper集群处于服务状态时,获取所述多个从节点中除所述目标从节点之外的从节点的当前顺序位。
在一些实施方式中,当监测到zookeeper集群处于服务状态时,可以获取多个从节点中除目标从节点之外的从节点的当前顺序位。例如,若主节点为创建顺序为第一顺序位的临时节点,目标从节点为创建顺序为第二顺序位的临时节点,多个从节点中除了目标节点还包括创建顺序为第三顺序位的临时节点以及创建顺序为第四顺序位的临时节点,那么,主节点(创建顺序为第一顺序位的临时节点)停止服务时,可以将创建顺序为第一顺序位的临时节点删除,将创建顺序为第二顺序位的临时节点作为当前主节点,并依次将创建顺序为第三顺序位的临时节点的顺序位提升为第一顺序位,以及将创建顺序为第四顺序位的临时节点的顺序位提升为第二顺序位。因此,多个从节点(创建顺序为第二顺序位的临时节点、创建顺序为第三顺序位的临时节点、创建顺序为第四顺序位的临时节点)中除目标从节点(创建顺序为第二顺序位的临时节点)之外的从节点还包括创建顺序为第三顺序位的临时节点和创建顺序为第四顺序位的临时节点,其中,创建顺序为第三顺序位的临时节点的当前顺序位为第一顺序位,创建顺序为第四顺序位的临时节点的当前顺序位为第二顺序位。
步骤S372:将所述当前顺序位为第一顺序位的从节点确定为所述指定从节点。
在一些实施方式中,在获取多个从节点中除目标从节点之外的从节点的当前顺序位后,可以获取当前顺序位为第一顺序位的从节点,并将该当前顺序位为第一顺序位的从节点确定为指定从节点。例如,将创建顺序为第三顺序位的临时节点确定为指定从节点。
步骤S373:控制所述当前主节点向所述指定从节点发送存活消息。
在本实施例中,在确定当前主节点和指定从节点后,可以控制当前主节点向指定从节点发送存活消息。在一些实施方式中,当前主节点向指定从节点发送的存活消息可以仅用于表征当前主节点处于存活状态,对于存活消息的的内容、类型以及形式等,在此不做限定。
在一些实施方式中,可以控制当前主节点实时向指定从节点发送存活消息,可以控制当前主节点按指定时间间隔向指定从节点发送存活消息,可以控制当前主节点按指定时间向指定从节点发送存活消息,可以控制当前主节点按其他指定规则向指定从节点发送存活消息等。可选地,在本实施例中,为了提升系统的服务连续性,可以控制当前主节点实时向指定从节点发送存活消息。
本申请再一个实施例提供的主节点选取方法,在zookeeper集群中创建多个临时节点,并从多个临时节点中确定主节点和从节点,从多个从节点中选取一个从节点作为目标从节点,控制主节点向目标从节点发送存活消息,当目标从节点没有接收到主节点发送的存活消息时,将目标从节点作为当前主节点,在zookeeper集群中删除主节点,并依次提升多个从节点中除目标从节点之外的从节点的顺序位,监测zookeeper集群的服务状态,当zookeeper集群处于服务状态时,控制当前主节点向指定从节点发送存活消息,其中,指定从节点为多个从节点中除目标从节点之外的从节点中的任意一个。相较于图1所示的主节点选取方法,本实施例还在从节点的数量为多个时,从多个从节点中选取一个从节点作为目标从节点以接收主节点发送的存活消息,以保证主节点和从节点正常的消息交互。另外,本实施例还在将目标从节点作为当前主节点后,监测zookeeper集群的服务状态,并在zookeeper集群处于服务状态时,控制当前主节点向指定从节点发送存活消息,以提升系统的服务连续性和可用性。
请参阅图8,图8示出了本申请另一个实施例提供的主节点选取方法的流程示意图。下面将针对图8所示的流程进行详细的阐述,所述主节点选取方法具体可以包括以下步骤:
步骤S410:获取分布式存储系统的节点部署信息。
其中,本方案可以基于zookeeper对分布式kv存储系统进行节点管理与分布式协调。在一些实施方式中,可以获取分布式存储系统的节点部署信息,其中,所获取的分布式系统的节点部署信息可以包括分布式系统的节点数量、分布式系统中的各个节点之间的关系、分布式系统中的各个节点之间属于相同服务的节点等,在此不做限定。
步骤S420:基于所述节点部署信息,在所述zookeeper集群中创建所述多个临时节点, 并从所述多个临时节点中确定所述主节点和所述从节点。
在一些实施方式中,在获取分布式存储系统的节点部署信息后,可以基于该节点部署信息,在zookeeper集群中创建多个临时节点,并从多个临时节点中确定主节点和从节点。
请参阅图9,图9示出了本申请的图8所示的主节点选取方法的步骤S420的流程示意图。下面将针对图9所示的流程进行详细的阐述,所述方法具体可以包括以下步骤:
步骤S421:基于所述节点部署信息,获取属于相同服务的主从节点。
在一些实施方式中,在获取分布式存储系统的节点部署信息后,可以基于该节点部署信息,获取分布式存储系统中的各个节点中属于相同服务的主从节点,即获取分布式存储系统中的各个节点中属于相同服务的主节点和从节点,其中,相同服务的主从节点表征相同父目录下主从节点。
步骤S422:将所述属于相同服务的主从节点在所述zookeeper集群中注册生成所述多个临时节点,并从所述多个临时节点中确定所述主节点和所述从节点。
在本实施例中,在获取属于相同服务的主从节点后,可以将属于相同服务的主从节点在zookeeper集群中注册生成多个临时节点,并从多个临时节点中确定主节点和从节点。在一些实施方式中,在获取属于相同服务的主从节点后,可以将相同服务的主从节点注册生成zookeeper相同父目录下的多个临时顺序节点,并根据临时顺序节点的创建顺序从中确定主节点和从节点。
步骤S430:控制所述主节点向所述从节点发送存活消息。
步骤S440:当所述从节点没有接收到所述主节点发送的存活消息时,将所述从节点作为当前主节点。
其中,步骤S430-步骤S440的具体描述请参阅步骤S120-步骤S130,在此不再赘述。
本申请另一个实施例提供的主节点选取方法,获取分布式存储系统的节点部署信息,基于节点部署信息,在zookeeper集群中创建多个临时节点,并从多个临时节点中确定主节点和从节点,控制主节点向从节点发送存活消息,当从节点没有接收到主节点发送的存活消息时,将从节点提升为当前主节点。相较于图1所示的主节点选取方法,本实施例还获取分布式存储系统的节点部署信息,并基于节点部署信息在zookeeper集群中创建多个临时节点,以提高系统的可用性。
请参阅图10,图10示出了本申请又再一个实施例提供的主节点选取方法的流程示意图。下面将针对图10所示的流程进行详细的阐述,所述主节点选取方法具体可以包括以下步骤:
步骤S510:在所述zookeeper集群的相同父目录下创建所述多个临时节点,并从所述多个临时节点中确定所述主节点和所述从节点。
在本实施例中,可以在zookeeper集群的相同父目录下创建多个临时节点,并从多个临时节点中确定主节点和从节点。在一些实施方式中,可以利用相同服务节点作为zookeeper集群的父节点,并在该父节点下创建生成多个临时节点,临时节点分别代表分布式存储系统中相同服务的主从进程,即从多个临时节点中可以确定主节点和从节点。
步骤S520:控制所述主节点向所述从节点发送存活消息。
步骤S530:当所述从节点没有接收到所述主节点发送的存活消息时,将所述从节点作为当前主节点。
其中,步骤S520-步骤S530的具体描述请参阅步骤S120-步骤S130,在此不再赘述。
本申请又再一个实施例提供的主节点选取方法,在zookeeper集群的相同父目录下创建多个临时节点,并从多个临时节点中确定主节点和从节点,控制主节点向从节点发送存活消息,当从节点没有接收到主节点发送的存活消息时,将从节点作为当前主节点。相较于图1所示的主节点选取方法,本实施例还在zookeeper集群的相同父目录下创建多个临时节点,以提高系统的可用性。
请参阅图11,图11示出了本申请实施例提供的主节点选取装置200的模块框图。下面将针对图11所示的框图进行阐述,所述主节点选取装置200包括:临时节点创建模块210、存活消息发送模块220以及主节点选取模块230,其中:
临时节点创建模块210,用于在zookeeper集群中创建多个临时节点,并从所述多个临时节点中确定主节点和从节点。
进一步地,所述临时节点创建模块210包括:第一临时节点创建子模块和第一节点确定子模块,其中:
第一临时节点创建子模块,用于在所述zookeeper集群中创建所述多个临时节点,并从所述多个临时节点中获取创建顺序为第一指定顺序位的临时节点。
第一节点确定子模块,用于将所述创建顺序为第一指定顺序位的临时节点确定为所述主节点,并将所述多个临时节点中除所述主节点之外的临时节点确定为所述从节点。
进一步地,临时节点创建模块210包括:节点部署信息获取子模块和第二临时节点创建子模块,其中:
节点部署信息获取子模块,用于获取分布式存储系统的节点部署信息。
第二临时节点创建子模块,用于基于所述节点部署信息,在所述zookeeper集群中创建所述多个临时节点,并从所述多个临时节点中确定所述主节点和所述从节点。
进一步地,所述第二临时节点创建子模块包括:主从节点获取单元和第二临时节点创建单元,其中:
主从节点获取单元,用于基于所述节点部署信息,获取属于相同服务的主从节点。
第二临时节点创建单元,用于将所述属于相同服务的主从节点在所述zookeeper集群中注册生成所述多个临时节点,并从所述多个临时节点中确定所述主节点和所述从节点。
进一步地,所述临时节点创建模块210包括:第三临时节点创建子模块,其中:
第三临时节点创建子模块,用于在所述zookeeper集群的相同父目录下创建所述多个临时节点,并从所述多个临时节点中确定所述主节点和所述从节点。
存活消息发送模块220,用于控制所述主节点向所述从节点发送存活消息。
进一步地,所述存活消息发送模块220包括:标识信息获取子模块和第一存活消息发送子模块,其中:
标识信息获取子模块,用于获取所述从节点的标识信息。
第一存活消息发送子模块,用于基于所述标识信息,控制所述主节点向所述从节点发送所述存活消息。
进一步地,所述标识信息包括国际互联协议IP信息,所述第一存活消息发送子模块包括:第一存活消息发送单元,其中:
第一存活消息发送单元,用于基于所述IP信息,控制所述主节点向所述从节点发送所述存活消息。
进一步地,所述从节点的数量为多个,所述存活消息发送模块220包括:目标从节点选取子模块和第二存活消息发送子模块,其中:
目标从节点选取子模块,用于从多个从节点中选取一个从节点作为目标从节点。
进一步地,所述目标从节点选取子模块包括:临时节点获取单元和目标从节点确定单元,其中:
临时节点获取单元,用于从所述多个临时节点中获取创建顺序为第二指定顺序位的临时节点。
目标从节点确定单元,用于将所述创建顺序为第二指定顺序位的临时节点确定为所述目标从节点。
进一步地,所述目标从节点选取子模块包括:目标从节点选取单元,其中:
目标从节点选取单元,用于从所述多个从节点中随机选取一个从节点作为所述目标从节点。
第二存活消息发送子模块,用于控制所述主节点向所述目标从节点发送所述存活消息。
主节点选取模块230,用于当所述从节点没有接收到所述主节点发送的存活消息时,将所述从节点作为当前主节点。
进一步地,所述主节点选取模块230包括:主节点选取子模块和顺序位提升子模块,其中:
主节点选取子模块,用于当所述目标从节点没有接收到所述主节点发送的存活消息时,将所述目标从节点作为所述当前主节点。
顺序位提升子模块,用于在所述zookeeper集群中删除所述主节点,并依次提升所述多个从节点中除所述目标从节点之外的从节点的顺序位。
进一步地,所述顺序位提升子模块包括:主节点重启单元、顺序位提升单元以及主节点切换单元,其中:
主节点重启单元,用于重启所述主节点。
顺序位提升单元,用于当所述主节点重启未成功时,在所述zookeeper集群中删除所述主节点,并依次提升所述多个从节点中除所述目标从节点之外的从节点的顺序位。
主节点切换单元,用于当所述主节点重启成功时,将所述主节点切换为从节点加入所述zookeeper集群。
进一步地,所述主节点选取模块230包括:服务状态监测子模块和第三存活消息发送子模块,其中:
服务状态监测子模块,用于监测所述zookeeper集群的服务状态。
第三存活消息发送子模块,用于当所述zookeeper集群处于服务状态时,控制所述当前主节点向指定从节点发送存活消息,其中,所述指定从节点为所述多个从节点中除所述目标从节点之外的从节点中的任意一个。
进一步地,所述第三存活消息发送子模块包括:当前顺序位获取单元、指定从节点确定单元以及第三存活消息发送单元,其中:
当前顺序位获取单元,用于当所述zookeeper集群处于服务状态时,获取所述多个从节点中除所述目标从节点之外的从节点的当前顺序位。
指定从节点确定单元,用于将所述当前顺序位为第一顺序位的从节点确定为所述指定从节点。
第三存活消息发送单元,用于控制所述当前主节点向所述指定从节点发送存活消息。
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述装置和模块的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。
在本申请所提供的几个实施例中,模块相互之间的耦合可以是电性,机械或其它形式的耦合。
另外,在本申请各个实施例中的各功能模块可以集成在一个处理模块中,也可以是各个模块单独物理存在,也可以两个或两个以上模块集成在一个模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。
请参阅图12,其示出了本申请实施例提供的一种电子设备100的结构框图。该电子设备100可以是智能手机、平板电脑、电子书等能够运行应用程序的电子设备。本申请中的电子设备100可以包括一个或多个如下部件:处理器110、存储器120以及一个或多个应用程序,其中一个或多个应用程序可以被存储在存储器120中并被配置为由一个或多个处理器110执行,一个或多个程序配置用于执行如前述方法实施例所描述的方法。
其中,处理器110可以包括一个或者多个处理核。处理器110利用各种接口和线路连接整个电子设备100内的各个部分,通过运行或执行存储在存储器120内的指令、程序、代码集或指令集,以及调用存储在存储器120内的数据,执行电子设备100的各种功能和处理数据。可选地,处理器110可以采用数字信号处理(Digital Signal Processing,DSP)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)、可编程逻辑阵 列(Programmable Logic Array,PLA)中的至少一种硬件形式来实现。处理器110可集成中央处理器(Central Processing Unit,CPU)、图形处理器(Graphics Processing Unit,GPU)和调制解调器等中的一种或几种的组合。其中,CPU主要处理操作系统、用户界面和应用程序等;GPU用于负责待显示内容的渲染和绘制;调制解调器用于处理无线通信。可以理解的是,上述调制解调器也可以不集成到处理器110中,单独通过一块通信芯片进行实现。
存储器120可以包括随机存储器(Random Access Memory,RAM),也可以包括只读存储器(Read-Only Memory)。存储器120可用于存储指令、程序、代码、代码集或指令集。存储器120可包括存储程序区和存储数据区,其中,存储程序区可存储用于实现操作系统的指令、用于实现至少一个功能的指令(比如触控功能、声音播放功能、图像播放功能等)、用于实现下述各个方法实施例的指令等。存储数据区还可以存储电子设备100在使用中所创建的数据(比如电话本、音视频数据、聊天记录数据)等。
请参阅图13,其示出了本申请实施例提供的一种计算机可读存储介质的结构框图。该计算机可读介质300中存储有程序代码,所述程序代码可被处理器调用执行上述方法实施例中所描述的方法。
计算机可读存储介质300可以是诸如闪存、EEPROM(电可擦除可编程只读存储器)、EPROM、硬盘或者ROM之类的电子存储器。可选地,计算机可读存储介质300包括非易失性计算机可读介质(non-transitory computer-readable storage medium)。计算机可读存储介质300具有执行上述方法中的任何方法步骤的程序代码310的存储空间。这些程序代码可以从一个或者多个计算机程序产品中读出或者写入到这一个或者多个计算机程序产品中。程序代码310可以例如以适当形式进行压缩。
综上所述,本申请实施例提供的主节点选取方法、装置、电子设备以及存储介质,在zookeeper集群中创建多个临时节点,并从多个临时节点中确定主节点和从节点,控制主节点向从节点发送存活消息,当从节点没有接收到主节点发送的存活消息时,将从节点作为当前主节点,从而通过控制主节点向从节点发送存活消息,当主节点停止服务时,从节点能马上感知其信息,从而快速提升作为当前主节点,以提升系统的服务连续性和可用性。
最后应说明的是:以上实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不驱使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围。

Claims (20)

  1. 一种主节点选取方法,其特征在于,所述方法包括:
    在zookeeper集群中创建多个临时节点,并从所述多个临时节点中确定主节点和从节点;
    控制所述主节点向所述从节点发送存活消息;
    当所述从节点没有接收到所述主节点发送的存活消息时,将所述从节点作为当前主节点。
  2. 根据权利要求1所述的方法,其特征在于,所述控制所述主节点向所述从节点发送存活消息,包括:
    获取所述从节点的标识信息;
    基于所述标识信息,控制所述主节点向所述从节点发送所述存活消息。
  3. 根据权利要求2所述的方法,其特征在于,所述标识信息包括国际互联协议IP信息,所述基于所述标识信息,控制所述主节点向所述从节点发送所述存活消息,包括:
    基于所述IP信息,控制所述主节点向所述从节点发送所述存活消息。
  4. 根据权利要求1-3任一项所述的方法,其特征在于,所述在zookeeper集群中创建多个临时节点,并从所述多个临时节点中确定主节点和从节点,包括:
    在所述zookeeper集群中创建所述多个临时节点,并从所述多个临时节点中获取创建顺序为第一指定顺序位的临时节点;
    将所述创建顺序为第一指定顺序位的临时节点确定为所述主节点,并将所述多个临时节点中除所述主节点之外的临时节点确定为所述从节点。
  5. 根据权利要求4所述的方法,其特征在于,所述第一指定顺序位为第一顺序位。
  6. 根据权利要求1-5任一项所述的方法,其特征在于,所述从节点的数量为多个,所述控制所述主节点向所述从节点发送存活消息,包括:
    从多个从节点中选取一个从节点作为目标从节点;
    控制所述主节点向所述目标从节点发送所述存活消息。
  7. 根据权利要求6所述的方法,其特征在于,所述从多个从节点中选取一个从节点作为目标从节点,包括:
    从所述多个临时节点中获取创建顺序为第二指定顺序位的临时节点;
    将所述创建顺序为第二指定顺序位的临时节点确定为所述目标从节点。
  8. 根据权利要求7所述的方法,其特征在于,所述第二指定顺序位为第二顺序位。
  9. 根据权利要求6所述的方法,其特征在于,所述从多个从节点中选取一个从节点作为目标从节点,包括:
    从所述多个从节点中随机选取一个从节点作为所述目标从节点。
  10. 根据权利要求6-9任一项所述的方法,其特征在于,所述当所述从节点没有接收到所述主节点发送的存活消息时,将所述从节点作为当前主节点,包括:
    当所述目标从节点没有接收到所述主节点发送的存活消息时,将所述目标从节点作为所述当前主节点;
    在所述zookeeper集群中删除所述主节点,并依次提升所述多个从节点中除所述目标从节点之外的从节点的顺序位。
  11. 根据权利要求10所述的方法,其特征在于,所述在所述zookeeper集群中删除所述主节点,并依次提升所述多个从节点中除所述目标从节点之外的从节点的顺序位之后,还包括:
    监测所述zookeeper集群的服务状态;
    当所述zookeeper集群处于服务状态时,控制所述当前主节点向指定从节点发送存活消息,其中,所述指定从节点为所述多个从节点中除所述目标从节点之外的从节点中的任意 一个。
  12. 根据权利要求11所述的方法,其特征在于,所述当所述zookeeper集群处于服务器状态时,控制所述当前主节点向指定从节点发送存活消息,包括:
    当所述zookeeper集群处于服务状态时,获取所述多个从节点中除所述目标从节点之外的从节点的当前顺序位;
    将所述当前顺序位为第一顺序位的从节点确定为所述指定从节点;
    控制所述当前主节点向所述指定从节点发送存活消息。
  13. 根据权利要求10-12任一项所述的方法,其特征在于,所述在所述zookeeper集群中删除所述主节点,并依次提升所述多个从节点中除所述目标从节点之外的从节点的顺序位,包括:
    重启所述主节点;
    当所述主节点重启未成功时,在所述zookeeper集群中删除所述主节点,并依次提升所述多个从节点中除所述目标从节点之外的从节点的顺序位。
  14. 根据权利要求13所述的方法,其特征在于,所述方法还包括:
    当所述主节点重启成功时,将所述主节点切换为从节点加入所述zookeeper集群。
  15. 根据权利要求1-14任一项所述的方法,其特征在于,所述在zookeeper集群中创建多个临时节点,并从所述多个临时节点中确定主节点和从节点,包括:
    获取分布式存储系统的节点部署信息;
    基于所述节点部署信息,在所述zookeeper集群中创建所述多个临时节点,并从所述多个临时节点中确定所述主节点和所述从节点。
  16. 根据权利要求15所述的方法,其特征在于,所述基于所述节点部署信息,在所述zookeeper集群中创建所述多个临时节点,并从所述多个临时节点中确定所述主节点和所述从节点,包括:
    基于所述节点部署信息,获取属于相同服务的主从节点;
    将所述属于相同服务的主从节点在所述zookeeper集群中注册生成所述多个临时节点,并从所述多个临时节点中确定所述主节点和所述从节点。
  17. 根据权利要求1-16任一项所述的方法,其特征在于,所述在zookeeper集群中创建多个临时节点,并从所述多个临时节点中确定主节点和从节点,包括:
    在所述zookeeper集群的相同父目录下创建所述多个临时节点,并从所述多个临时节点中确定所述主节点和所述从节点。
  18. 一种主节点选取装置,其特征在于,所述装置包括:
    临时节点创建模块,用于在zookeeper集群中创建多个临时节点,并从所述多个临时节点中确定主节点和从节点;
    存活消息发送模块,用于控制所述主节点向所述从节点发送存活消息;
    主节点选取模块,用于当所述从节点没有接收到所述主节点发送的存活消息时,将所述从节点作为当前主节点。
  19. 一种电子设备,其特征在于,包括存储器和处理器,所述存储器耦接到所述处理器,所述存储器存储指令,当所述指令由所述处理器执行时所述处理器执行如权利要求1-17任一项所述的方法。
  20. 一种计算机可读取存储介质,其特征在于,所述计算机可读取存储介质中存储有程序代码,所述程序代码可被处理器调用执行如权利要求1-17任一项所述的方法。
PCT/CN2020/079574 2020-03-17 2020-03-17 主节点选取方法、装置、电子设备以及存储介质 WO2021184177A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
PCT/CN2020/079574 WO2021184177A1 (zh) 2020-03-17 2020-03-17 主节点选取方法、装置、电子设备以及存储介质
CN202080095213.0A CN115088235B (zh) 2020-03-17 2020-03-17 主节点选取方法、装置、电子设备以及存储介质

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2020/079574 WO2021184177A1 (zh) 2020-03-17 2020-03-17 主节点选取方法、装置、电子设备以及存储介质

Publications (1)

Publication Number Publication Date
WO2021184177A1 true WO2021184177A1 (zh) 2021-09-23

Family

ID=77769604

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/079574 WO2021184177A1 (zh) 2020-03-17 2020-03-17 主节点选取方法、装置、电子设备以及存储介质

Country Status (2)

Country Link
CN (1) CN115088235B (zh)
WO (1) WO2021184177A1 (zh)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113660350A (zh) * 2021-10-18 2021-11-16 恒生电子股份有限公司 分布式锁协调方法、装置、设备及存储介质
CN114070739A (zh) * 2021-11-11 2022-02-18 杭州和利时自动化有限公司 一种集群部署方法、装置、设备和计算机可读存储介质
CN115150273A (zh) * 2022-06-30 2022-10-04 联想(北京)有限公司 一种升级处理方法及装置
CN115643237A (zh) * 2022-10-13 2023-01-24 北京华建云鼎科技股份公司 一种用于会议的数据处理系统

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105426439A (zh) * 2015-11-05 2016-03-23 腾讯科技(深圳)有限公司 一种元数据的处理方法和装置
CN106375342A (zh) * 2016-10-21 2017-02-01 用友网络科技股份有限公司 一种基于zookeeper技术的系统集群方法及系统
CN106850260A (zh) * 2016-12-23 2017-06-13 曙光云计算技术有限公司 一种虚拟化资源管理平台的部署方法和装置
US20180095845A1 (en) * 2016-09-30 2018-04-05 Commvault Systems, Inc. Heartbeat monitoring of virtual machines for initiating failover operations in a data storage management system, including virtual machine distribution logic
CN109240840A (zh) * 2017-07-11 2019-01-18 阿里巴巴集团控股有限公司 集群系统的容灾方法、装置和机器可读介质

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106254100B (zh) * 2016-07-27 2019-04-16 腾讯科技(深圳)有限公司 一种数据容灾方法、装置和系统
CN106302648B (zh) * 2016-07-29 2019-05-07 北京小米移动软件有限公司 业务处理方法及装置

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105426439A (zh) * 2015-11-05 2016-03-23 腾讯科技(深圳)有限公司 一种元数据的处理方法和装置
US20180095845A1 (en) * 2016-09-30 2018-04-05 Commvault Systems, Inc. Heartbeat monitoring of virtual machines for initiating failover operations in a data storage management system, including virtual machine distribution logic
CN106375342A (zh) * 2016-10-21 2017-02-01 用友网络科技股份有限公司 一种基于zookeeper技术的系统集群方法及系统
CN106850260A (zh) * 2016-12-23 2017-06-13 曙光云计算技术有限公司 一种虚拟化资源管理平台的部署方法和装置
CN109240840A (zh) * 2017-07-11 2019-01-18 阿里巴巴集团控股有限公司 集群系统的容灾方法、装置和机器可读介质

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113660350A (zh) * 2021-10-18 2021-11-16 恒生电子股份有限公司 分布式锁协调方法、装置、设备及存储介质
CN114070739A (zh) * 2021-11-11 2022-02-18 杭州和利时自动化有限公司 一种集群部署方法、装置、设备和计算机可读存储介质
CN114070739B (zh) * 2021-11-11 2024-01-26 杭州和利时自动化有限公司 一种集群部署方法、装置、设备和计算机可读存储介质
CN115150273A (zh) * 2022-06-30 2022-10-04 联想(北京)有限公司 一种升级处理方法及装置
CN115150273B (zh) * 2022-06-30 2024-05-28 联想(北京)有限公司 一种升级处理方法及装置
CN115643237A (zh) * 2022-10-13 2023-01-24 北京华建云鼎科技股份公司 一种用于会议的数据处理系统
CN115643237B (zh) * 2022-10-13 2023-08-11 北京华建云鼎科技股份公司 一种用于会议的数据处理系统

Also Published As

Publication number Publication date
CN115088235A (zh) 2022-09-20
CN115088235B (zh) 2024-05-28

Similar Documents

Publication Publication Date Title
WO2021184177A1 (zh) 主节点选取方法、装置、电子设备以及存储介质
TWI783355B (zh) 深度學習模型的分布式訓練方法以及裝置
US10949158B2 (en) Screenshot method and apparatus
EP3750291B1 (en) Collaborative editing of media in a mixed computing environment
CN107908708A (zh) 一种集群文件同步的方法、系统、设备和存储介质
CN107666493B (zh) 一种数据库配置方法及其设备
CN112114761A (zh) 一种无线投屏控制方法、装置、终端设备及可读存储介质
CN108055304B (zh) 远程数据的同步方法、装置、服务器、设备和存储介质
CN111181787B (zh) 一种bmc参数配置方法、装置、设备、介质
CN107665141B (zh) 一种数据库配置方法及其设备
CN111752488B (zh) 存储集群的管理方法、装置、管理节点及存储介质
CN111064626A (zh) 配置更新方法、装置、服务器及可读存储介质
CN109032767B (zh) 异步多进程的业务处理系统、方法、装置及存储介质
CN116820527B (zh) 程序升级方法、装置、计算机设备和存储介质
CN112044061B (zh) 游戏画面处理方法、装置、电子设备以及存储介质
WO2021226781A1 (zh) 防火墙规则的更新方法、装置、服务器及存储介质
WO2021223109A1 (zh) 数据同步方法、装置、系统、电子设备及存储介质
CN109347994B (zh) 互联网协议ip地址获取方法、装置、存储介质及电子设备
CN108427691B (zh) 网络数据传输方法、装置和计算机设备
CN113452948B (zh) 会议终端的控制方法、装置、设备及存储介质
CN112187877B (zh) 一种基于分布式集群的节点唤醒方法及受控终端
CN107547593B (zh) 一种实现日志同步的方法、装置及分布式系统
CN117493024B (zh) 多进程异构程序的迁移方法、存储介质及电子设备
CN113660339B (zh) 用于去中心化集群的方法和装置
CN113835892B (zh) 统一存储设备及其业务管理方法、模块和可读存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20925829

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 22.02.23)

122 Ep: pct application non-entry in european phase

Ref document number: 20925829

Country of ref document: EP

Kind code of ref document: A1