AI-based leader node management methods, devices, equipment, and storage media

By establishing connections and monitoring the status in the ZooKeeper server, and handling the recovery or unloading of leader nodes, the problem of multiple leader nodes caused by ZooKeeper server failure or connection loss is resolved, ensuring server availability and operational efficiency.

CN114090178BActive Publication Date: 2025-11-14ONE CONNECT SMART TECH CO LTD SHENZHEN
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111390650.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-23
Publication Date
2025-11-14
Estimated Expiration
2041-11-23

AI Technical Summary

Technical Problem

In existing technologies, when the ZooKeeper server fails or loses connection with the server, multiple leader nodes may coexist, causing follow nodes to fail to be called correctly and resulting in abnormal service component calls.

Method used

By establishing the first connection in the ZooKeeper server, monitoring its running and connection status, performing leader node recovery or unloading, and re-electing a leader node when necessary, multiple leader nodes can be avoided from coexisting.

Benefits of technology

It enables automatic failover when the ZooKeeper server fails or the connection is lost, ensuring server availability, improving operational efficiency, and reducing operational burden.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114090178B_ABST
    Figure CN114090178B_ABST
Patent Text Reader

Abstract

This invention relates to artificial intelligence and discloses a leader node management method, apparatus, device, and storage medium based on artificial intelligence. The method includes: establishing a first connection between a ZooKeeper server and a server; creating a leader node through the ZooKeeper server for managing service components in the server; performing recovery or uninstallation processing on the leader node in the ZooKeeper server based on the running status of the ZooKeeper server and / or the connection status of the first connection; and re-electing a leader node for the server after uninstalling the leader node. This invention avoids the situation where multiple leader nodes coexist if the ZooKeeper server directly re-elects a new leader node when it deems the leader node offline.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence technology, and in particular to a leader node management method, apparatus, device, and storage medium based on artificial intelligence. Background Technology

[0002] When the ZooKeeper server fails or its connection to the server is lost, the ZooKeeper server considers the current leader node to be offline. In this case, the ZooKeeper server typically elects a new leader node from among the nodes corresponding to the service components on the server. However, the inventors realized that if the previous leader node comes back online, it will coexist with the new leader node on the ZooKeeper server, resulting in a server having two or more leader nodes. This leads to follow nodes being unable to be called correctly due to the coexistence of multiple leader nodes, ultimately causing service component calls to malfunction. Summary of the Invention

[0003] The purpose of this invention is to provide an artificial intelligence-based leader node management method, apparatus, device, and storage medium to solve the problem in the prior art where the re-online of a previous leader node results in a server having two or more leader nodes, causing follow nodes to be unable to be called correctly due to the coexistence of multiple leader nodes.

[0004] To achieve the above objectives, this invention provides a leader node management method, which runs on a ZooKeeper server, including:

[0005] Establish the first connection between the ZooKeeper server and the server, and create a leader node through the ZooKeeper server to manage the service components in the server, wherein the server is a service provider with at least one service component, and the service component is a computer program for providing a specified service;

[0006] Based on the running status of the ZooKeeper server and / or the connection status of the first connection, the leader node in the ZooKeeper server is restored or uninstalled.

[0007] After the leader node is unloaded, a new leader node is elected for the server.

[0008] In the above scheme, the step of creating a leader node through the ZooKeeper server to manage the service components in the server includes:

[0009] The ZooKeeper server is controlled to obtain the service components of the server through the first connection, configure nodes for the service components, and set the node status of the nodes to the looking state.

[0010] The election process controls each node to vote for any node in the server, so as to obtain the node with the most votes and set it as the target node.

[0011] The node state of the target node is changed to the leading state, making the target node a leader node. The leader node is used to receive request traffic and distribute it.

[0012] The node status of all nodes in the server other than the target node is changed to the following state, making the other nodes follow nodes; wherein, the follow nodes are used to receive and process the request traffic distributed by the leader node.

[0013] In the above scheme, before determining the running status of the ZooKeeper server and / or the connection status of the first connection, the method further includes:

[0014] In the ZooKeeper server, a first listening thread is created to monitor the running status of the ZooKeeper server, and a second listening thread is created to monitor the first connection.

[0015] In the above scheme, before determining the running status of the ZooKeeper server and / or the connection status of the first connection, the method further includes:

[0016] Establish a second connection between the ZooKeeper server and the client, wherein the client is a service consumer used to invoke service components of the server.

[0017] In the above scheme, the operating state includes a normal state and a fault state, and the connection state includes a connected state and a disconnected state;

[0018] The step of restoring or unloading the leader node in the ZooKeeper server based on the running status of the ZooKeeper server and / or the connection status of the first connection includes:

[0019] The first listening thread monitors the running status of the ZooKeeper server. When the running status is in a fault state, it determines whether the ZooKeeper server has recovered to a normal state within a preset running period. If yes, the leader node of the server side in the ZooKeeper server is restored; if no, the leader node of the server side in the ZooKeeper server is unloaded.

[0020] The second listening thread monitors the connection status of the first connection. When the connection status is disconnected, a disconnect signal is sent to the client through the second connection to trigger the client to reconnect with the server. It also determines whether the first connection has been restored to a connected state within a preset connection period. If so, the leader node of the server in the ZooKeeper server is restored. If not, the leader node of the server in the ZooKeeper server is unloaded.

[0021] In the above scheme, after performing the unloading process on the leader node in the ZooKeeper server, the method further includes:

[0022] A node listening thread is established between the ZooKeeper server and the service component to monitor changes in the leader node and send change information to the service component based on the changes.

[0023] After sending the change information to the service component based on the change, the method further includes:

[0024] The changed information is uploaded to the blockchain.

[0025] In the above scheme, the re-election of the server's leader node includes:

[0026] Determine whether a reconnection command sent by the server is received within a preset reconnection period; wherein the reconnection command reflects the change status of the leader node;

[0027] If so, change information is sent to each service component of the server, so that the node status of the corresponding node of the service component changes from following to looking; and the leader node of the server is obtained by electing the corresponding node of the service component through a preset election process.

[0028] If not, a disconnection message is sent to the control terminal, wherein the disconnection message contains the server's ID.

[0029] To achieve the above objectives, the present invention also provides a leader node management device, installed in a ZooKeeper server, comprising:

[0030] The first creation module is used to establish a first connection between the ZooKeeper server and the server, and to create a leader node through the ZooKeeper server for managing the service components in the server. The server is a service provider with at least one service component, and the service component is a computer program for providing a specified service.

[0031] The node processing module is used to perform recovery or uninstallation processing on the leader node in the ZooKeeper server according to the running status of the ZooKeeper server and / or the connection status of the first connection.

[0032] The Leader election module is used to re-elect the leader node of the server after the leader node has been unloaded.

[0033] To achieve the above objectives, the present invention also provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor of the computer device executes the computer program, it implements the steps of the leader node management method described above.

[0034] To achieve the above objectives, the present invention also provides a computer-readable storage medium storing a computer program, wherein the computer program stored in the readable storage medium, when executed by a processor, implements the steps of the above-described leader node management method.

[0035] The present invention provides an AI-based leader node management method, apparatus, device, and storage medium that, by performing recovery or unloading processing on the leader node in the ZooKeeper server based on the running status of the ZooKeeper server and / or the connection status of the first connection, achieves the following: If the ZooKeeper server restores its running status to a normal state or the first connection is restored to a connected state before it considers the current leader node offline, the leader node is restored, bringing it back online on the ZooKeeper server; if the ZooKeeper server restores its running status to a normal state or the first connection is restored to a connected state after it considers the current leader node offline, the leader node is unloaded, changing its node status from leading to looking. Therefore, this avoids the situation where multiple leader nodes coexist if the ZooKeeper server directly re-elects a new leader node when it considers a leader node offline. Attached Figure Description

[0036] Figure 1 This is a flowchart of an embodiment of the leader node management method based on artificial intelligence of the present invention;

[0037] Figure 2 This is a schematic diagram illustrating the environmental application of the leader node management method in Embodiment 2 of the artificial intelligence-based leader node management method of the present invention.

[0038] Figure 3 This is a flowchart illustrating the specific method of leader node management in Embodiment 2 of the artificial intelligence-based leader node management method of the present invention.

[0039] Figure 4 This is a schematic diagram of the program modules of a third embodiment of the AI-based leader node management device of the present invention.

[0040] Figure 5 This is a schematic diagram of the hardware structure of the computer device in Embodiment 4 of the present invention. Detailed Implementation

[0041] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without inventive effort are within the scope of protection of this invention.

[0042] This invention provides an artificial intelligence-based leader node management method, apparatus, device, and storage medium, applicable to the field of artificial intelligence technology. It provides a leader node management method based on a first creation module, a node processing module, and a leader election module. This invention establishes a first connection between a ZooKeeper server and a server-side application. The ZooKeeper server creates a leader node for managing service components on the server-side application. Based on the running status of the ZooKeeper server and / or the connection status of the first connection, the leader node in the ZooKeeper server is restored or uninstalled. After uninstalling the leader node, a new leader node is elected for the server-side application.

[0043] Example 1:

[0044] Please see Figure 1 This embodiment of an artificial intelligence-based leader node management method, running on a ZooKeeper server, includes:

[0045] S101: Establish the first connection between the ZooKeeper server and the server, and create a leader node through the ZooKeeper server to manage the service components in the server, wherein the server is a service provider with at least one service component, and the service component is a computer program for providing a specified service;

[0046] S104: Based on the running status of the ZooKeeper server and / or the connection status of the first connection, perform recovery or uninstallation processing on the leader node in the ZooKeeper server;

[0047] S106: After the leader node is unloaded, a new leader node is elected for the server.

[0048] In an exemplary embodiment, by receiving a first connection request sent by the server, and establishing a first connection between the ZooKeeper server and the server according to the registration request, the service components of the server are obtained; by creating a leader node for managing the service components in the server through the ZooKeeper server, a manager (i.e., leader node) for receiving the request is determined. The manager will distribute the request to the corresponding service components according to preset rules, thereby achieving the technical effect of concurrent processing of the request.

[0049] By performing recovery or unloading processing on the leader node in the ZooKeeper server based on the running status of the ZooKeeper server and / or the connection status of the first connection, the system achieves the following: if the ZooKeeper server's running status returns to normal or the first connection is restored to a connected state before the ZooKeeper server considers the current leader node offline, the leader node is recovered, bringing it back online on the ZooKeeper server; if the ZooKeeper server's running status returns to normal or the first connection is restored to a connected state after the ZooKeeper server considers the current leader node offline, the leader node is unloaded, changing its node status from leading to looking. Therefore, this avoids the situation where multiple leader nodes coexist if the ZooKeeper server directly re-elects a new leader node when it considers the leader node offline.

[0050] By unloading the leader node and then re-electing a leader node for the server, the service components of the server that reconnects to the ZooKeeper server can generate a new leader node to route request traffic and manage follow nodes, thereby ensuring the availability of the reconnected server. Therefore, in the event of a ZooKeeper server failure or / or a broken first connection, the technology achieves automatic leader node switching without manual intervention, improving operational efficiency and reducing operational burden.

[0051] It's important to note that ZooKeeper is a distributed, open-source distributed application coordination service, an open-source implementation of Google's Chubby, and a crucial component of Hadoop and HBase. It's software that provides consistency services for distributed applications, offering features such as configuration maintenance, domain name service, distributed synchronization, and group services. The leader node is the core of the entire ZooKeeper cluster, responsible for initiating and resolving elections and voting, and updating the system's state.

[0052] Example 2:

[0053] This embodiment is a specific application scenario of the above embodiment one. Through this embodiment, the method provided by the present invention can be explained more clearly and specifically.

[0054] The following example illustrates the method provided in this embodiment by describing how, in a server running a leader node management method, the leader node is restored or uninstalled based on the running status of the ZooKeeper server and / or the connection status of the first connection. It should be noted that this embodiment is merely exemplary and does not limit the scope of protection of this invention.

[0055] Figure 2 The illustration shows an environmental application diagram of the AI-based leader node management method according to Embodiment 2 of this application.

[0056] In an exemplary embodiment, the ZooKeeper server 2, where the leader node management method resides, connects to the server 3 and client 4 via a network. The server 2 can provide services through one or more networks, which may include various network devices such as routers, switches, multiplexers, hubs, modems, bridges, repeaters, firewalls, proxy devices, and / or more. The network may include physical links, such as coaxial cable links, twisted-pair cable links, fiber optic links, combinations thereof, and / or the like. The network may include wireless links, such as cellular links, satellite links, Wi-Fi links, and / or the like. The client 4 may be a smartphone, tablet, laptop, desktop computer, or other computer device.

[0057] Figure 3 This is a flowchart of a leader node management method based on artificial intelligence provided in an embodiment of the present invention. The method specifically includes steps S201 to S206.

[0058] S201: Establish the first connection between the ZooKeeper server and the server, and create a leader node through the ZooKeeper server to manage the service components in the server, wherein the server is a service provider with at least one service component, and the service component is a computer program for providing a specified service.

[0059] To ensure that the service components of the server can be invoked in an orderly manner and that the information of each service component can be synchronized in real time, a leader node is built in the ZooKeeper server. The leader node is used to distribute requests to the corresponding service components to achieve the technical effect of concurrent processing of the requests.

[0060] This step involves receiving a first connection request from the server and establishing a first connection between the ZooKeeper server and the server based on the registration request, thereby obtaining the service components of the server. The ZooKeeper server then creates a leader node to manage the service components in the server, determining the manager to receive the request. The manager will distribute the request to the corresponding service components according to preset rules, thus achieving the technical effect of concurrent request processing.

[0061] It's worth noting that ZooKeeper is a distributed, open-source distributed application coordination service. It's an open-source implementation of Google's Chubby and a crucial component of Hadoop and HBase. It's software that provides consistency services for distributed applications, offering features such as configuration maintenance, domain name service, distributed synchronization, and group services.

[0062] In a preferred embodiment, the step of creating a leader node for managing service components in the server via the ZooKeeper server includes:

[0063] S11: Control the ZooKeeper server to obtain the service component of the server through the first connection, configure the node of the service component, and set the node status of the node to looking state;

[0064] S12: Control each node to vote for any node in the server through the election process, so as to obtain the node with the most votes and set it as the target node;

[0065] S13: Modify the node state of the target node to the leading state, so that the target node becomes a leader node, wherein the leader node is used to receive request traffic and distribute it.

[0066] S14: Modify the node status of all nodes in the server other than the target node to the following state, so that the other nodes become follow nodes; wherein, the follow nodes are used to receive and process the request traffic distributed by the leader node.

[0067] In this embodiment, the looking state is the state of searching for a leader, and the node in this state needs to enter the election process; the leading state is the state of a leader, and the node in this state is already the leader; the following state is the state of a follower, indicating that the leader has been elected and the current node is a follower.

[0068] For example, the service components on the server side include component A, component B, and component C. Each service component is configured with nodes to serve as threads running that component, namely: node A, node B, and node C, and the node state of each node is configured to the looking state. An election process is used to allow nodes A, B, and C to vote for each of the aforementioned nodes. Assuming node A receives the most votes, its node state is changed from the looking state to the leader state, making node A the leader node, which receives and routes requests. The node states of nodes B and C are changed from the looking state to the follow state, making nodes B and C follow nodes, which receive and process requests routed by the leader node.

[0069] It should be noted that a leader node for managing the service components in the server can be created through the election process of the ZooKeeper server. This election process is a computer program built based on the ZooKeeper server's election algorithm, used to obtain the leader node and follower nodes. The leader node is the core of the entire ZooKeeper cluster, responsible for initiating and resolving election votes and updating the system state. Follower nodes are followers of the ZooKeeper cluster state, used to receive and return results to clients, and participate in voting during the election process.

[0070] S202: In the ZooKeeper server, a first listening thread is constructed to monitor the running status of the ZooKeeper server, and a second listening thread is constructed to monitor the first connection.

[0071] To achieve the technical effect of timely monitoring of the ZooKeeper server and the connection status between the ZooKeeper server and the server, this step involves building a first listening thread in the ZooKeeper server to monitor the running status of the ZooKeeper server, thereby achieving the technical effect of real-time monitoring of the ZooKeeper server, and building a second listening thread in the ZooKeeper server to monitor the first connection, thereby achieving the technical effect of real-time monitoring of the connection status between the external server and the ZooKeeper server.

[0072] In this embodiment, watch events can be used as the first and second listening threads. The watcher event is the watch method formed by the org.apache.zookeeper.Watcher interface, which is used to monitor changes in node state. Furthermore, all read operations (getData(), getChildren(), exists()) in the Zookeeper server can be configured with the Watch option. Watch events have the characteristic of one-time triggering. If the node monitored by the watch event changes its state, it will notify the server running the leader node management method.

[0073] S203: Establish a second connection between the ZooKeeper server and the client, wherein the client is a service consumer used to invoke service components of the server.

[0074] In this step, a second connection is established between the ZooKeeper server and the client to send an event message to the client. This allows a disconnect signal to be sent to the client via the second connection, triggering the client to reconnect to the server through the ZooKeeper server. In this embodiment, the disconnect signal is a disconnect event.

[0075] Furthermore, the second connection can also be used to receive information requests sent by clients through the second connection, call the leader node to send the information request to the follow node, receive address information sent by follow nodes that can satisfy the information request, and call the leader node to send the address information to the client; wherein, the address information is the address of the service component that the client needs to call.

[0076] S204: Based on the running status of the ZooKeeper server and / or the connection status of the first connection, perform recovery or uninstallation processing on the leader node in the ZooKeeper server.

[0077] When the ZooKeeper server malfunctions or the first connection is broken, the ZooKeeper server considers the current leader node to be offline. In this case, the ZooKeeper server will usually elect a new leader node from the nodes corresponding to each service component on the server. If the previous leader node comes online again, it will coexist with the new leader node on the ZooKeeper server, resulting in a server having two or more leader nodes. Consequently, follow nodes cannot be called correctly due to the coexistence of multiple leader nodes, ultimately causing service component call anomalies.

[0078] This step, by performing recovery or unloading processing on the leader node in the ZooKeeper server based on the running status of the ZooKeeper server and / or the connection status of the first connection, achieves the following: If the ZooKeeper server's running status returns to normal or the first connection is restored to a connected state before the ZooKeeper server considers the current leader node offline, the leader node is recovered, bringing it back online on the ZooKeeper server; if the ZooKeeper server's running status returns to normal or the first connection is restored to a connected state after the ZooKeeper server considers the current leader node offline, the leader node is unloaded, changing its node status from leading to looking. Therefore, it avoids the situation where multiple leader nodes coexist if the ZooKeeper server directly re-elects a new leader node when it considers the leader node offline.

[0079] Specifically, the recovery process includes the following steps:

[0080] Obtain the leader node and follower node of the server, and bring the leader node and follower node online in the ZooKeeper server to realize the recovery process of the leader node.

[0081] Specifically, the unloading process includes the following steps:

[0082] The leader node and follow nodes of the server are obtained, and the node status of the leader node is changed to the looking state, and the status of the follow nodes is changed to the looking state, so as to achieve the technical effect of unloading the leader node.

[0083] In a preferred embodiment, the operating state includes a normal state and a fault state, and the connection state includes a connected state and a disconnected state;

[0084] The step of restoring or unloading the leader node in the ZooKeeper server based on the running status of the ZooKeeper server and / or the connection status of the first connection includes:

[0085] S41: Monitor the running status of the ZooKeeper server through the first listening thread. When the running status is a fault state, determine whether the ZooKeeper server has recovered to a normal state within the preset running period. If yes, restore the leader node of the server in the ZooKeeper server. If no, unload the leader node of the server in the ZooKeeper server.

[0086] In this step, when the ZooKeeper server fails, clients will be unable to call the service components of the server through ZooKeeper. Therefore, a first listening thread monitors the running status of the ZooKeeper server in real time. Once the running status returns to a normal state within the specified running period, the leader node and follower nodes of the server are brought online directly in ZooKeeper to restore the leader node. If the running status does not return to a normal state after the specified running period, the node status of both the leader node and follower nodes is changed to the looking state to achieve the technical effect of unloading the leader node. The running period is the time ZooKeeper considers the leader node to be offline. It can be set according to the parameters in the ZooKeeper server's configuration file. For example, if the configuration file considers a 3-second connection loss between the leader node and the ZooKeeper server as a leader node failure, then the running period is set to 3 seconds.

[0087] S42: Monitor the connection status of the first connection through the second listening thread. When the connection status is disconnected, send a disconnect signal to the client through the second connection to trigger the client to reconnect with the server; and determine whether the first connection has been restored to a connected state within a preset connection period; if so, restore the leader node of the server in the ZooKeeper server; if not, unload the leader node of the server in the ZooKeeper server.

[0088] In this step, when the server malfunctions, the client will be unable to call the server's service components through the ZooKeeper server. Therefore, a disconnect signal is sent to the client through a second connection to trigger a reconnection operation between the client and the server, allowing them to re-establish a connection. Once the client reconnects to the server, the server will rebuild the first connection with the ZooKeeper server, keeping the first connection active. Once the connection is restored to active status during the connection period, the server's leader and follower nodes are brought online directly on the ZooKeeper server to restore the leader node. If the connection fails to achieve active status after the connection period, the node status of both the server's leader and follower nodes is changed to the looking state to unload the leader node. The connection period is the time ZooKeeper considers the leader node to be offline. It can be set according to the configuration parameters of the ZooKeeper server. For example, if the configuration file considers the connection between the leader node and the ZooKeeper server to be offline for 3 seconds, then the connection period is set to 3 seconds.

[0089] In this embodiment, when the running state is normal and the connection state is connected, the first listening thread and the second listening thread will respectively listen to the normal signal and the connected signal, which can be (18:49:08){"keeperState":"SyncConnected","eventType":"None"};

[0090] Sending a Disconnect event to the client via the second connection as a disconnection signal to trigger the client to reconnect with the server; for example, the disconnection signal is: (18:58:18){"keeperState":"Disconnected","eventType":"None"};

[0091] When an Expired event is received from the server after the operation period or the connection period, it is determined that the ZooKeeper server has recovered to the normal state and the first connection has recovered to the connected state; for example, the received Expired event is: (18:59:48){"keeperState":"Expired","eventType":"None"}.

[0092] S205: Establish a node listening thread between the ZooKeeper server and the service component to listen for changes in the leader node and send change information to the service component based on the changes.

[0093] Since the original leader node was uninstalled due to the disconnection between the server and the ZooKeeper server, a new leader node needs to be elected before the service components can be invoked. Therefore, to ensure that the node state of the corresponding nodes of each service component is restored to the looking state so as to facilitate the re-election of the leader node, this step establishes a node listening thread between the ZooKeeper server and the service components. This allows the node listening thread to monitor the changes of the leader node and send change information to the service components based on the changes. This enables the service components to change the node state of their corresponding nodes according to the change information, thereby changing the following state to the looking state, ensuring that a new leader node can be elected subsequently.

[0094] In this embodiment, a watch event can be used as the node listening thread. The watcher event is the watch method formed by the org.apache.zookeeper.Watcher interface, which is used to listen for changes in the node state.

[0095] Preferably, after sending the change information to the service component based on the change, the method further includes:

[0096] The changed information is uploaded to the blockchain.

[0097] It should be noted that the corresponding digest information is obtained based on the changed information. Specifically, the digest information is obtained by hashing the changed information, such as using the SHA256 algorithm. Uploading the digest information to the blockchain ensures its security and fairness and transparency to users. User devices can download the digest information from the blockchain to verify whether the changed information has been tampered with. The blockchain referred to in this example is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. Essentially, a blockchain is a decentralized database, a chain of data blocks linked using cryptographic methods. Each data block contains information about a batch of network transactions, used to verify the validity of the information (anti-counterfeiting) and generate the next block. A blockchain can include a blockchain underlying platform, a platform product service layer, and an application service layer.

[0098] S206: After the leader node is unloaded, a new leader node is elected for the server.

[0099] To ensure that a server whose leader node goes offline due to a ZooKeeper server or service failure can be reconnected to the ZooKeeper server and invoked normally by clients, this step involves unloading the leader node and then re-electing a new leader node. This allows the service components of the server that reconnects to the ZooKeeper server to generate a new leader node for routing request traffic and managing follower nodes, thus ensuring the availability of the reconnected server. Therefore, this technology achieves automatic leader node switching in the event of a ZooKeeper server failure and / or a broken initial connection, without requiring manual intervention, improving operational efficiency and reducing operational burden.

[0100] In a preferred embodiment, the re-election of the server's leader node includes:

[0101] S61: Determine whether a reconnection instruction sent by the server is received within the preset reconnection period; wherein the reconnection instruction reflects the change of the leader node;

[0102] In this step, the reconnection instruction is the Expired event, which reflects the re-establishment of the connection between the server and the ZooKeeper server, and the unloading of the leader node. If the ZooKeeper server returns to normal operation during the runtime, or if the first connection between the ZooKeeper server and the server is restored during the connection period, the server will not send the reconnection instruction. This is to avoid multiple leader elections due to short-term disconnections, which could lead to excessive computing power consumption and reduced operational stability of the ZooKeeper server. The reconnection period is a pre-defined time interval based on the needs of the service components.

[0103] S62: If so, send change information to each service component of the server, so that the node state of the corresponding node of the service component changes from following state to looking state; and elect the leader node of the server by means of a preset election process.

[0104] In this step, the change information is generated based on the reconnection instruction (i.e., the Expired event), and is a computer instruction used to change the node state of the follow node to the looking state. Then, an election process is used to re-elect a new leader node from the nodes in the looking state.

[0105] It should be noted that the election process is built on the election algorithm of the ZooKeeper server and is a computer program used to obtain leader nodes and follower nodes. The leader node is the core of the entire ZooKeeper cluster, responsible for initiating and resolving election votes and updating the system state. The follower nodes are followers of the ZooKeeper cluster state, used to receive and return results to clients, and participate in voting during the election process.

[0106] S63: If not, send a disconnection message to the control terminal, wherein the disconnection message contains the server's ID.

[0107] In this step, the server's number is the server's unique identifier.

[0108] Example 3:

[0109] Please see Figure 4 This embodiment provides an AI-based leader node management device 1, installed in a ZooKeeper server, comprising:

[0110] The first creation module 11 is used to establish a first connection between the ZooKeeper server and the server, and to create a leader node through the ZooKeeper server for managing the service components in the server. The server is a service provider with at least one service component, and the service component is a computer program for providing a specified service.

[0111] The node processing module 14 is used to perform recovery or uninstallation processing on the leader node in the ZooKeeper server according to the running status of the ZooKeeper server and / or the connection status of the first connection.

[0112] The Leader election module 16 is used to re-elect the leader node of the server after the leader node has been unloaded.

[0113] Optionally, the leader node management device 1 further includes:

[0114] The second creation module 12 is used to construct a first listening thread in the ZooKeeper server for monitoring the running status of the ZooKeeper server, and to construct a second listening thread for monitoring the first connection.

[0115] Optionally, the leader node management device 1 further includes:

[0116] The third creation module 13 is used to establish a second connection between the ZooKeeper server and the client, wherein the client is a service consumer used to call the service components of the server.

[0117] Optionally, the leader node management device 1 further includes:

[0118] The fourth creation module 15 is used to build a node listening thread between the ZooKeeper server and the service component, for listening to changes in the leader node and sending change information to the service component according to the changes.

[0119] Optionally, the first creation module 11 further includes:

[0120] The node configuration unit 111 is used to control the ZooKeeper server to obtain the service component of the server through the first connection, configure the node for the service component, and set the node status of the node to looking state.

[0121] The node voting unit 112 is used to control each node to vote for any node in the server through the election process, so as to obtain the node with the highest number of votes and set it as the target node.

[0122] Leader selection unit 113 is used to modify the node state of the target node to the leading state, so that the target node becomes a leader node, wherein the leader node is used to receive request traffic and distribute it.

[0123] Follow selection unit 114 is used to modify the node status of other nodes in the server other than the target node to the following state, so that the other nodes become follow nodes; wherein, the follow nodes are used to receive and process the request traffic distributed by the leader node.

[0124] Optionally, the node processing module 14 further includes:

[0125] The first processing unit 141 is used to monitor the running status of the ZooKeeper server through a first listening thread. When the running status is a fault state, it determines whether the ZooKeeper server has recovered to a normal state within a preset running period. If yes, it restores the leader node of the server in the ZooKeeper server. If no, it unloads the leader node of the server in the ZooKeeper server.

[0126] The second processing unit 142 is configured to monitor the connection status of the first connection through the second listening thread; when the connection status is disconnected, it sends a disconnect signal to the client through the second connection to trigger the client to reconnect with the server; and determines whether the first connection has been restored to a connected state within a preset connection period; if so, it restores the leader node of the server in the ZooKeeper server; if not, it unloads the leader node of the server in the ZooKeeper server.

[0127] Optionally, the Leader election module 16 further includes:

[0128] The time determination unit 161 is used to determine whether a reconnection instruction sent by the server is received within a preset reconnection period; wherein the reconnection instruction reflects the change of the leader node.

[0129] The node election unit 162 is used to send change information to each service component of the server, so that the node status of the corresponding node of the service component changes from the following state to the looking state; and to elect the leader node of the server by means of a preset election process.

[0130] The disconnection alarm unit 163 is used to send disconnection information to the control terminal, wherein the disconnection information contains the number of the server.

[0131] The embodiments of this application can acquire and process relevant data based on artificial intelligence technology. Artificial intelligence (AI) refers to the theories, methods, technologies, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to obtain optimal results.

[0132] Foundational technologies for artificial intelligence generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies mainly encompass computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning.

[0133] Specifically, in this embodiment, an intelligent decision-making model from the field of artificial intelligence is used. The intelligent decision-making model may be a classification model built based on a classifier. The classification model analyzes the running status of the ZooKeeper server and / or the connection status of the first connection, and performs recovery or unloading processing on the leader node in the ZooKeeper server according to the running status and / or connection status.

[0134] Example 4:

[0135] To achieve the above objectives, the present invention also provides a computer device 5. The components of the leader node management device in Embodiment 3 can be distributed across different computer devices. The computer device 5 can be a smartphone, tablet, laptop, desktop computer, rack server, blade server, tower server, or cabinet server (including independent servers or server clusters composed of multiple application servers), etc. The computer device in this embodiment includes, but is not limited to, a memory 51 and a processor 52 that can communicate with each other via a system bus. Figure 5 As shown. It should be noted that, Figure 5Only computer devices with components are shown; however, it should be understood that it is not required to implement all of the components shown, and more or fewer components may be implemented instead.

[0136] In this embodiment, the memory 51 (i.e., the readable storage medium) includes flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 51 can be an internal storage unit of a computer device, such as the hard disk or memory of the computer device. In other embodiments, the memory 51 can also be an external storage device of the computer device, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the computer device. Of course, the memory 51 can also include both the internal storage unit and the external storage device of the computer device. In this embodiment, the memory 51 is typically used to store the operating system and various application software installed on the computer device, such as the program code of the leader node management device in Embodiment 3. In addition, the memory 51 can also be used to temporarily store various types of data that have been output or will be output.

[0137] In some embodiments, processor 52 may be a central processing unit (CPU), controller, microcontroller, microprocessor, or other data processing chip. This processor 52 is typically used to control the overall operation of a computer device. In this embodiment, processor 52 is used to run program code stored in memory 51 or process data, for example, to run a leader node management device to implement the leader node management methods of Embodiments 1 and 2.

[0138] Example 5:

[0139] To achieve the above objectives, the present invention also provides a computer-readable storage medium, such as flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, server, App application store, etc., which stores a computer program. When the program is executed by the processor 52, it implements the corresponding function. The computer-readable storage medium of this embodiment is used to store a computer program that implements the leader node management method, and when executed by the processor 52, it implements the leader node management methods of Embodiments 1 and 2.

[0140] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0141] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method.

[0142] The above are merely preferred embodiments of the present invention and do not limit the scope of the patent. Any equivalent structural or procedural transformations made based on the description and drawings of the present invention, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of the present invention.

Claims

1. A leader node management method based on artificial intelligence, running on a ZooKeeper server, characterized in that, include: Establish the first connection between the ZooKeeper server and the server, and create a leader node through the ZooKeeper server to manage the service components in the server, wherein the server is a service provider with at least one service component, and the service component is a computer program for providing a specified service; A second connection is established between the ZooKeeper server and the client, wherein the client is a service consumer used to invoke service components of the server. This second connection is used to send a disconnect signal to the client, triggering the client to reconnect to the server via the ZooKeeper server. The second connection also receives information requests sent by the client through this connection, invokes the leader node to send the information request to the follower nodes, receives address information from follower nodes that can satisfy the information request, and invokes the leader node to send the address information to the client. The address information is the address of the service component that the client needs to invoke. Based on the running status of the ZooKeeper server and / or the connection status of the first connection, the leader node in the ZooKeeper server is restored or uninstalled; the running status includes normal status and fault status, and the connection status includes connected status and disconnected status. The step of restoring or unloading the leader node in the ZooKeeper server based on the running status of the ZooKeeper server and / or the connection status of the first connection includes: The first listening thread monitors the running status of the ZooKeeper server. When the running status is in a fault state, it determines whether the ZooKeeper server has recovered to a normal state within a preset running period. If yes, the leader node of the server side in the ZooKeeper server is restored; if no, the leader node of the server side in the ZooKeeper server is unloaded. The second listening thread monitors the connection status of the first connection. When the connection status is disconnected, a disconnection signal is sent to the client through the second connection to trigger the client to reconnect with the server. It also determines whether the first connection has been restored to a connected state within a preset connection period. If so, the leader node of the server in the ZooKeeper server is restored. If not, the leader node of the server in the ZooKeeper server is unloaded. After the leader node is unloaded, a new leader node is elected for the server.

2. The leader node management method based on artificial intelligence according to claim 1, characterized in that, The creation of a leader node through the ZooKeeper server for managing service components in the server includes: The ZooKeeper server is controlled to obtain the service components of the server through the first connection, configure nodes for the service components, and set the node status of the nodes to the looking state. The election process controls each node to vote for any node in the server, so as to obtain the node with the most votes and set it as the target node. The node state of the target node is changed to the leading state, making the target node a leader node. The leader node is used to receive request traffic and distribute it. The node status of all nodes in the server other than the target node is changed to the following state, making the other nodes follow nodes; wherein, the follow nodes are used to receive and process the request traffic distributed by the leader node.

3. The leader node management method based on artificial intelligence according to claim 1, characterized in that, Before determining the running status of the ZooKeeper server and / or the connection status of the first connection, the method further includes: In the ZooKeeper server, a first listening thread is created to monitor the running status of the ZooKeeper server, and a second listening thread is created to monitor the first connection.

4. The leader node management method based on artificial intelligence according to claim 1, characterized in that, After performing the unloading process on the leader node in the ZooKeeper server, the method further includes: A node listening thread is established between the ZooKeeper server and the service component to monitor changes in the leader node and send change information to the service component based on the changes. After sending the change information to the service component based on the change, the method further includes: The changed information is uploaded to the blockchain.

5. The leader node management method based on artificial intelligence according to claim 1, characterized in that, The re-election of the server's leader node includes: Determine whether a reconnection command sent by the server is received within a preset reconnection period; wherein the reconnection command reflects the change status of the leader node; If so, change information is sent to each service component of the server, so that the node status of the corresponding node of the service component changes from following to looking; and the leader node of the server is obtained by electing the corresponding node of the service component through a preset election process. If not, a disconnection message is sent to the control terminal, wherein the disconnection message contains the server's ID.

6. An artificial intelligence-based leader node management device, installed in a ZooKeeper server, characterized in that, include: The first creation module is used to establish a first connection between the ZooKeeper server and the server, and to create a leader node through the ZooKeeper server for managing the service components in the server. The server is a service provider with at least one service component, and the service component is a computer program for providing a specified service. The third creation module is used to establish a second connection between the ZooKeeper server and the client, wherein the client is a service consumer used to call service components of the server; the second connection is used to send a disconnect signal to the client, which triggers the client to reconnect with the server through the ZooKeeper server; the second connection is also used to receive information requests sent by the client through the second connection, call the leader node to send the information request to the follow nodes, receive address information sent by the follow nodes that can satisfy the information request, and call the leader node to send the address information to the client; the address information is the address of the service component that the client needs to call; The node processing module is used to perform recovery or unloading processing on the leader node in the ZooKeeper server based on the running status of the ZooKeeper server and / or the connection status of the first connection; the running status includes normal status and fault status, and the connection status includes connected status and disconnected status; the step of performing recovery or unloading processing on the leader node in the ZooKeeper server based on the running status of the ZooKeeper server and / or the connection status of the first connection includes: monitoring the running status of the ZooKeeper server through a first listening thread, and when the running status is a fault status, determining whether the ZooKeeper server is in a preset running state. If the connection is restored to a normal state within the specified period, then the leader node of the server in the ZooKeeper server is restored; otherwise, the leader node of the server in the ZooKeeper server is unloaded. The connection status of the first connection is monitored by a second listening thread. When the connection status is disconnected, a disconnect signal is sent to the client through the second connection to trigger the client to reconnect with the server. It is also determined whether the first connection is restored to a connected state within the preset connection period. If so, the leader node of the server in the ZooKeeper server is restored; otherwise, the leader node of the server in the ZooKeeper server is unloaded. The Leader election module is used to re-elect the leader node of the server after the leader node has been unloaded.

7. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor of the computer device executes the computer program, it implements the steps of the artificial intelligence-based leader node management method according to any one of claims 1 to 5.

8. A computer-readable storage medium storing a computer program thereon, characterized in that, When the computer program stored in the readable storage medium is executed by a processor, it implements the steps of the artificial intelligence-based leader node management method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Electronic device, distributed task scheduling method and storage medium

    CN108717379A