An event monitoring method, related device and event monitoring system
By registering the listening side to create events for the child nodes of the target node on the listening side, and sending changes to the child nodes according to the client policy when the target node changes, the problem of missing listening events in the existing technology is solved, and timely capture and permanent monitoring of node changes is achieved.
Patent Information
- Application Number
- CN202110082496.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-21
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2041-01-21
AI Technical Summary
In the prior art, when permanent monitoring is implemented, node changes are not registered in time, which will lead to loss of listening events, especially when nodes are frequently changed, network delays or client restarts.
By registering the listening side to create events for the child node of the target node on the listening side, and creating child nodes to store modification data when the target node changes, sending some or all child nodes of the target node to the listening side according to the client's child node acquisition strategy to ensure that the listening side can receive node changes in a timely manner.
It realizes monitoring of each change of the node, avoids the loss of listening events, especially when the node changes frequently, network delays or client restarts, it can still effectively capture all changes, meeting the needs of permanent monitoring.
Smart Images

Figure CN113778703B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to an event monitoring method, related devices and an event monitoring system. Background Art
[0002] Zookeeper (hereinafter referred to as zk) is a distributed application coordination service. Zookeeper can monitor through the watch mechanism. Zookeeper monitoring events are one-time triggers. When monitoring a node (i.e., zk node), changes to the node can only trigger a monitoring event once, and subsequent changes to the node will not continue to trigger monitoring events. In order to achieve the effect of permanent monitoring, the current solution is that after the client (i.e., the listening end) monitors the node message and processes the message, the client registers to monitor this node again.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0004] In the current solution for permanent monitoring, it is necessary to monitor the node changes and then re-register the monitoring event of the node. If the node changes before the monitoring event is re-registered, the monitoring event of this node change will be lost; when the monitored node changes multiple times in a very short period of time, or when the client registers the monitoring event, there is a network fluctuation delay in the interaction with the cluster to which the monitored node belongs, and when the client service is restarted, the monitoring event will be lost. Summary of the invention
[0005] In view of this, an embodiment of the present invention provides an event monitoring method, related devices and event monitoring system, which can monitor every change of the node and achieve the purpose of permanent monitoring; when the monitored node changes multiple times in a very short time, or there is a network fluctuation delay, and when the client service is restarted, the monitoring event will not be lost; flexible configuration of monitoring strategies is achieved, and the client can choose to monitor every change or the last change of the node.
[0006] To achieve the above objective, according to one aspect of an embodiment of the present invention, an event monitoring method is provided.
[0007] An event monitoring method includes: registering a monitoring event for a monitoring end, wherein the registration of the monitoring event includes registering a monitoring for a sub-node creation event of a target node; when the target node is triggered to be modified, creating a sub-node of the target node to store the modified data, and sending part or all of the sub-nodes of the target node to the monitoring end according to the sub-node acquisition strategy of the monitoring end.
[0008] Optionally, registering a listener for a target node's child node creation event includes: modifying the listener for the target node to listener for the target node's child nodes through an encapsulation package, and the listener for the target node's child nodes is used to listen for the child node creation event.
[0009] Optionally, after sending some or all of the child nodes of the target node to the listening end, it includes: receiving a message returned by the listening end after completing event processing based on some or all of the child nodes; for each target child node among some or all of the child nodes, determining that each listening end in the listening end set receives a message returned after completing event processing based on the target child node, and then deleting the target child node, and the listening end set is a set of listening ends that register to listen to events.
[0010] Optionally, whenever a message is received from a listener indicating that event processing based on a target subnode is completed, a persistent node is created under the target subnode; the message returned by each listener in the listener set after completing event processing based on the target subnode is determined, and then the target subnode is deleted, including: determining that the number of all persistent nodes created under the target subnode is greater than or equal to the number of listeners in the listener set, and deleting the target subnode and all persistent nodes created under the target subnode.
[0011] Optionally, before registering a listening event for the listening end, the process includes: creating a shadow node of the target node and a temporary child node under the shadow node, recording the number of listening ends in the listening end set through the number of temporary child nodes, and the temporary child nodes correspond one-to-one to the listening ends in the listening end set.
[0012] Optionally, a child node acquisition strategy is pre-configured; when the configured child node acquisition strategy indicates that only the most recent listening event is to be acquired, some or all of the child nodes of the target node are sent to the listening end, including: sending the child node with the largest sequence number of the target node to the listening end, the sequence number indicates the order in which the child nodes of the target node are created; when the configured child node acquisition strategy indicates that each listening event is to be acquired, some or all of the child nodes of the target node are sent to the listening end, including: if the listening end records the sequence number of the current event node, then the child nodes of the target node with a sequence number greater than the sequence number of the current event node are sent to the listening end; if the listening end does not record the sequence number of the current event node, then the child nodes of each sequence number of the target node are sent to the listening end, and the current event node sequence number is the sequence number of the child node corresponding to the most recent event processing completed by the listening end.
[0013] According to another aspect of an embodiment of the present invention, an event monitoring method is provided.
[0014] An event monitoring method includes: when monitoring a target node's child node creation event, obtaining some or all of the target node's child nodes from a server according to a child node acquisition strategy, wherein the target node is a node on the server; for each target child node among some or all of the child nodes, completing event processing based on the target child node, and returning a message indicating that the event processing is completed to the server.
[0015] Optionally, the method further includes: pre-registering a monitoring event with the server, wherein the monitoring event registration includes registering a monitoring event for a child node creation event of the target node.
[0016] Optionally, it also includes: periodically detecting whether the transaction identifier of the locally stored target node is consistent with the transaction identifier of the target node stored on the server. If they are inconsistent, resetting the current event node recorded locally. The current event node is the child node corresponding to the event processing most recently completed by the listening end. The locally stored transaction identifier is obtained from the server when registering the listening event with the server. The transaction identifier of the target node is generated when the target node is created.
[0017] Optionally, it also includes: pre-configuring a child node acquisition strategy on the server side; when the child node acquisition strategy indicates that only the most recent listening event is to be obtained, obtaining some or all child nodes of the target node, including: obtaining the child node with the largest sequence number of the target node, the sequence number indicating the order in which the child nodes of the target node are created; when the child node acquisition strategy indicates that each listening event is to be obtained, obtaining some or all child nodes of the target node, including: if the current event node sequence number is recorded locally, obtaining the child nodes of the target node whose sequence number is greater than the current event node sequence number; if the current event node sequence number is not recorded locally, obtaining the child nodes of each sequence number of the target node, the current event node sequence number is the sequence number of the child node corresponding to the most recent event processing completed by the listening end.
[0018] According to yet another aspect of an embodiment of the present invention, a service device for event monitoring is provided.
[0019] A service device for event monitoring includes: a monitoring event registration module, which is used to register monitoring events for a monitoring end, and the registration of monitoring events includes registering monitoring for sub-node creation events of a target node; a monitoring event triggering module, which is used to create sub-nodes of the target node to store modified data when the target node is triggered to be modified, and send part or all of the sub-nodes of the target node to the monitoring end according to the sub-node acquisition strategy of the monitoring end.
[0020] Optionally, the monitoring event registration module is further used to: modify the monitoring of the target node to the monitoring of the child nodes of the target node through the encapsulation package, and the monitoring of the child nodes of the target node is used to monitor the child node creation event.
[0021] Optionally, it also includes a message receiving module, which is used to: receive the message returned by the listening end after completing event processing based on some or all of the child nodes; for each target child node among some or all of the child nodes, determine to receive the message returned by each listening end in the listening end set after completing event processing based on the target child node; the listening event triggering module is also used to delete the target child node, and the listening end set is the set of listening ends that register for listening events.
[0022] Optionally, whenever the message receiving module receives a message returned by a listening end that event processing based on the target sub-node is completed, the listening event triggering module creates a persistent node under the target sub-node; the listening event triggering module is also used to: determine that the number of all persistent nodes created under the target sub-node is greater than or equal to the number of listening ends in the listening end set, and delete the target sub-node and all persistent nodes created under the target sub-node.
[0023] Optionally, it also includes a listening end recording module, which is used to: create a shadow node of the target node and temporary child nodes under the shadow node, so as to record the number of listening ends in the listening end set through the number of temporary child nodes, and the temporary child nodes correspond one-to-one to the listening ends in the listening end set.
[0024] Optionally, it also includes a configuration module for pre-configuring a child node acquisition strategy; when the configured child node acquisition strategy indicates that only the most recent listening event is to be acquired, the listening event triggering module is also used to: send the child node with the largest sequence number of the target node to the listening end, and the sequence number indicates the creation order of the child nodes of the target node; when the configured child node acquisition strategy indicates that each listening event is to be acquired, the listening event triggering module is also used to: if the listening end records the sequence number of the current event node, then send the child nodes of the target node whose sequence number is greater than the sequence number of the current event node to the listening end; if the listening end does not record the sequence number of the current event node, then send the child nodes of each sequence number of the target node to the listening end, and the current event node sequence number is the sequence number of the child node corresponding to the most recent event processing completed by the listening end.
[0025] According to another aspect of an embodiment of the present invention, a monitoring device for event monitoring is provided.
[0026] A monitoring device for event monitoring includes: a monitoring event acquisition module, which is used to acquire some or all of the target node's child nodes from a server according to a child node acquisition strategy when monitoring a target node's child node creation event, wherein the target node is a node on the server; and a monitoring event execution module, which is used to complete event processing based on the target child node for each target child node in some or all of the child nodes, and return a message of event processing completion to the server.
[0027] Optionally, it also includes a monitoring event registration request module, which is used to: pre-register the monitoring event with the server, and the registration of the monitoring event includes registering the monitoring of the child node creation event of the target node.
[0028] Optionally, it also includes a detection module, which is used to: periodically detect whether the transaction identifier of the locally stored target node is consistent with the transaction identifier of the target node stored on the server. If they are inconsistent, the current event node recorded locally is reset. The current event node is the child node corresponding to the event processing most recently completed by the listening end. The locally stored transaction identifier is obtained from the server when registering the listening event with the server. The transaction identifier of the target node is generated when the target node is created.
[0029] Optionally, it also includes: pre-configuring a child node acquisition strategy on the server side; when the child node acquisition strategy indicates that only the most recent listening event is to be obtained, the listening event acquisition module is also used to: obtain the child node with the largest sequence number of the target node, the sequence number indicating the order in which the child nodes of the target node are created; when the child node acquisition strategy indicates that each listening event is to be obtained, the listening event acquisition module is also used to: if the current event node sequence number is recorded locally, then obtain the child nodes of the target node whose sequence number is greater than the current event node sequence number; if the current event node sequence number is not recorded locally, then obtain the child nodes of each sequence number of the target node, the current event node sequence number is the sequence number of the child node corresponding to the most recent event processing completed by the listening end.
[0030] According to yet another aspect of an embodiment of the present invention, an event monitoring system is provided.
[0031] An event monitoring system includes: a service device for event monitoring provided by an embodiment of the present invention, and a monitoring device for event monitoring provided by an embodiment of the present invention.
[0032] According to yet another aspect of the embodiments of the present invention, an electronic device is provided.
[0033] An electronic device includes: one or more processors; a memory for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the event monitoring method provided by an embodiment of the present invention.
[0034] According to yet another aspect of an embodiment of the present invention, a computer readable medium is provided.
[0035] A computer readable medium stores a computer program, which, when executed by a processor, implements an event monitoring method provided by an embodiment of the present invention.
[0036] One embodiment of the above invention has the following advantages or beneficial effects: registering a listening event for the listening end, and registering a listening event includes registering a listening event for the subnode creation event of the target node; when the target node is triggered to be modified, creating a subnode of the target node to store the modified data, and sending part or all of the subnodes of the target node to the listening end according to the subnode acquisition strategy of the listening end. It is possible to monitor every change of the node and achieve the purpose of permanent monitoring; when the monitored node changes multiple times in a very short time, or when there is a network fluctuation delay, and when the client service is restarted, the listening event will not be lost; the monitoring strategy can be flexibly configured, and the client can choose to monitor every change or the last change of the node.
[0037] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0039] Figure 1 is a schematic diagram of the main steps of an event monitoring method according to an embodiment of the present invention;
[0040] Figure 2 is an event monitoring process intention according to an embodiment of the present invention;
[0041] Figure 3 is a schematic diagram of main steps of an event monitoring method according to another embodiment of the present invention;
[0042] Figure 4 is a schematic diagram of main modules of a service device for event monitoring according to an embodiment of the present invention;
[0043] Figure 5 is a schematic diagram of main modules of a monitoring device for event monitoring according to an embodiment of the present invention;
[0044] Figure 6 is a schematic diagram of the main components of an event monitoring system according to an embodiment of the present invention;
[0045] Figure 7 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0046] Figure 8 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0047] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0048] Figure 1 It is a schematic diagram of main steps of an event monitoring method according to an embodiment of the present invention.
[0049] like Figure 1 As shown, the event monitoring method of an embodiment of the present invention mainly includes the following steps S101 to S102. The event monitoring method of this embodiment can be executed by a service device for event monitoring, and the service device for event monitoring, i.e., the server of the embodiment of the present invention, can be implemented based on Zookeeper (a distributed distributed application coordination service), which includes multiple nodes.
[0050] Step S101: registering a monitoring event to a monitoring end (ie, a client for monitoring), wherein the monitoring event registration includes registering a monitoring event for a child node creation event of a target node.
[0051] Registering a listener for a target node's child node creation event may include: modifying the listener for the target node to listener for the target node's child nodes through an encapsulation package, and the listener for the target node's child nodes is used to listen for the child node creation event.
[0052] Before registering a listening event for a listening end, the following may be included: creating a shadow node of the target node and a temporary child node under the shadow node, recording the number of listening ends in the listening end set through the number of temporary child nodes under the shadow node, and the temporary child nodes under the shadow node correspond one-to-one to the listening ends in the listening end set.
[0053] The listener set is a set of listeners that have registered for listener events.
[0054] The shadow node of the target node corresponds to the target node, and the path information (file path) of the shadow node includes the node path of the corresponding target node. Specifically, the path information of the shadow node can be the node path of the corresponding target node plus a specific suffix (a specific suffix such as "_SHADOW"). The shadow node is used to record how many clients have registered to listen to the target node, that is, the number of clients that listen to the child node creation event of the target node. Each listening end in the corresponding listening end set needs to create a temporary child node under the shadow node of the target node. Therefore, the shadow node can record the number of listening ends in the listening end set through the number of its temporary child nodes.
[0055] Step S102: when the target node is triggered to be modified, a child node of the target node is created to store the modified data, and part or all of the child nodes of the target node are sent to the listening end according to the child node acquisition strategy of the listening end.
[0056] The embodiment of the present invention may include two client clusters, one of which is a cluster composed of listening terminals, wherein the clients are used to listen to registered listening events. The other client cluster is a cluster composed of clients that trigger modification of server nodes, wherein the clients are used to trigger modification of server nodes. The target node is one of the nodes of the server, and taking Zookeeper (abbreviated as zk) as an example, the target node can be any zk node.
[0057] The sub-node acquisition strategy of the listening end can be configured in advance according to the business needs of the listening end, for example, the listening end is configured to obtain only the most recent listening event, or the listening end is configured to obtain every listening event.
[0058] In the case where the configured child node acquisition strategy indicates that only the most recent listening event is acquired, sending some or all of the child nodes of the target node to the listening end may include: sending the child node with the largest sequence number of the target node to the listening end, the sequence number of the child node of the target node indicates the creation order of the child nodes of the target node, wherein the child node with the largest sequence number is the most recently created child node of the target node. Each time a child node of the target node is created, 1 is added to the maximum sequence number of the original child node to obtain the sequence number of the newly created child node.
[0059] When the configured child node acquisition strategy indicates to acquire each listening event, some or all child nodes of the target node are sent to the listening end, which may include: if the listening end records the current event node sequence number, then the child nodes of the target node whose sequence number is greater than the current event node sequence number are sent to the listening end; if the listening end does not record the current event node sequence number, then the child nodes of each sequence number of the target node are sent to the listening end, and the current event node sequence number is the sequence number of the child node corresponding to the most recently completed event processing by the listening end.
[0060] After sending some or all of the child nodes of the target node to the listening end, it can include: receiving the message returned by the listening end after completing event processing based on some or all of the child nodes; for each target child node in some or all of the child nodes, determining that each listening end in the listening end set receives the message returned after completing event processing based on the target child node, and then deleting the target child node, and the target child node can be any child node in the some or all of the child nodes.
[0061] The listener performs event processing based on some or all of the child nodes. Specifically, the listener can process the corresponding business logic based on the modified data in the part or all of the child nodes of the target node. When the listener completes processing the corresponding business logic, the event processing is completed.
[0062] Whenever a message is received from a listener that an event processing is completed based on a target subnode, a persistent node is created under the target subnode; determining the message returned by each listener in the listener set after completing the event processing based on the target subnode, and then deleting the target subnode, may include: determining that the number of all persistent nodes created under the target subnode is greater than or equal to the number of listeners in the listener set, and deleting the target subnode and all persistent nodes created under the target subnode. Creating a persistent node under the target subnode means creating a child node under the target subnode, and the created child node is a persistent node. A persistent node is a node that will always exist unless a deletion operation is actively called once it is created.
[0063] The following takes the implementation of permanent monitoring based on Zookeeper as an example to describe in detail the event monitoring method of the embodiment of the present invention.
[0064] Figure 2 This is an event monitoring process intention according to an embodiment of the present invention.
[0065] like Figure 2As shown, when the client registering the monitoring event monitors the target node P for the first time, the Zookeeper end (i.e., the service device for event monitoring, or the service end) creates the shadow node P_S of the target node P and the temporary child node (such as C_S1, C_S2, etc.) under the shadow node, so as to record the number of listening terminals in the listening terminal set by the number of temporary child nodes, and the temporary child node corresponds to the listening terminal in the listening terminal set one by one. Wherein, the target node P is a node (i.e., zk node) on the Zookeeper end, the shadow node P_S is a persistent node, the file path rule of the shadow node P_S can be the file path of the P node plus the suffix "_SHADOW", and the temporary child node under the shadow node refers to the child node (such as C_S1, C_S2, etc.) under the shadow node is a temporary node. The temporary child node under the shadow node can specifically be a temporary sequential node, and the temporary node refers to a node that disappears after the client disconnects. A sequential node refers to a node arranged in order, and the node number gradually increases. A temporary sequential node is a node having the characteristics of both the above-mentioned temporary node and the sequential node. When each listening end listens to the P node for the first time, the Zookeeper end creates a corresponding temporary sequence node under the shadow node P_S of the P node to record the number of listening ends listening to the P node. When the listening end exits the listening, the temporary child node under the corresponding shadow node is deleted. After creating the temporary child node under the shadow node corresponding to the listening end, the listening event of the target node P is registered based on the listening end.
[0066] Based on the listening event of the target node (i.e., P node) registered by the listening end, the listening of the target node is modified to the listening of the subnodes of the target node through the encapsulation package, and the listening of the subnodes of the target node is used to listen to the subnode creation event, that is, only the subnode creation event of the target node is listened and processed, and the deletion event of the subnode of the target node is not processed. The subnode of the target node is specifically a persistent sequential node. A persistent sequential node refers to a node that has the characteristics of both a persistent node and a sequential node. The subnode of the target node P can also be called the persistent sequential subnode of the target node P.
[0067] When the target node P is triggered to be modified, the Zookeeper end creates a child node (such as C1, C2, etc.) of the target node P to store the modified data. When the client in the distributed cluster service for modifying nodes (i.e., the client that modifies the node) modifies the node P, the Zookeeper end encapsulates the modified P node into a persistent sequence child node of the created P node through an encapsulation package. The order of the persistent sequence child nodes of the P node is the order of modifying the P node, and the data of modifying the P node is stored in the persistent sequence child node of the corresponding P node. The order of the persistent sequence child nodes of the P node can be sorted according to the order in which the persistent sequence child nodes are created, and the newly created child node has the largest sequence number.
[0068] When the client of the modified node triggers the modification of the P node, the target subnode is sent to the listening end according to the subnode acquisition strategy of the listening end, and the target subnode represents each subnode of some or all subnodes of the target node acquired by the listening end. The subnode acquisition strategy of the listening end is pre-configured, and the subnode acquisition strategy may include obtaining only the most recent listening event and obtaining each listening event. In the case where the configured subnode acquisition strategy indicates that only the most recent listening event is obtained, the maximum sequence number subnode of the target node P is sent to the listening end as the target subnode, and the sequence number represents the creation order of the subnodes of the target node, that is, the most recently created subnode of the target node P is sent to the listening end. In the case where the configured child node acquisition strategy indicates to acquire each listening event, it can be determined whether the listening end has recorded the current event node sequence number. Specifically, it can be determined whether the current event node sequence number (current_event) is empty. If the listening end has recorded the current event node sequence number (i.e., current_event is not empty), the child node of the target node P with a sequence number greater than the current event node sequence number is sent to the listening end. The current event node sequence number in the listening end records the sequence number of the child node corresponding to the latest event processing completed by the listening end. If the sequence number of a child node of the target node P is greater than the current event node sequence number in the listening end, it means that the listening end has not performed event processing on the child node of the target node P, and the child node needs to be sent to the listening end for corresponding event processing; if the listening end does not record the current event node sequence number (i.e., current_event is empty), it means that the service is started for the first time, and the child nodes of the target node P with each sequence number are sent to the listening end as the target child node. If no target child node is sent to the listening end, no processing is performed, and the event monitoring process is terminated. The current event node number can be locked to prevent concurrent modifications.
[0069] The listening end processes the corresponding business logic based on the information of some or all of the child nodes of the target node. After the listening end completes event processing based on some or all of the child nodes, the listening end updates the sequence number of the current event node to the sequence number of the child node corresponding to the most recently completed event processing. The server receives the message returned by the listening end after completing event processing based on some or all of the child nodes. Whenever the server receives a message returned by the listening end indicating that event processing based on the target child node is completed, a persistent node is created under the target child node, indicating that a listening end has processed the listening event corresponding to the target child node. As mentioned above, creating a persistent node under the target child node refers to creating a child node under the target child node, and the created child node is a persistent node. At the same time, the child node under the target child node can also be a sequential node, so it can be called a persistent sequential node under the target child node, such as Figure 2The persistent sequential node C1_U in the target node P is created, indicating that a listener has processed the listen event corresponding to the C1 node (C1 is a child node under the target node P). Make sure that the number of all persistent nodes created under the target child node is greater than or equal to the number of listeners in the listener set, and delete the target child node and all persistent nodes created under the target child node. Figure 2 As shown, if the number of child nodes under the C1 node is greater than or equal to the number of child nodes under the P_S node, it means that all listening ends have processed the listening events corresponding to the C1 node, and the C1 node and its child nodes can all be deleted to reduce the occupation of cache resources.
[0070] After the monitoring event is triggered, the monitoring end can re-register the monitoring event on the Zookeeper end to monitor the target node.
[0071] When the listener starts the service to initially register the P node, it can periodically detect whether the transaction identifier of the target node P stored locally is consistent with the transaction identifier of the target node P stored on the server (i.e., Zookeeper). If they are inconsistent, it means that the P node has been recreated on the server. Then the listener resets the local node related information, mainly including resetting the current event node recorded locally, such as setting the current event node sequence number current_event to null. The transaction identifier of the node (i.e., cZxid) is generated when the node is created. It records the ID of the node creation transaction. The transaction identifier is also stored in the local cache of the listener to verify whether the corresponding node has been deleted and recreated on the server.
[0072] Figure 3 It is a schematic diagram of main steps of an event monitoring method according to another embodiment of the present invention.
[0073] like Figure 3 As shown, an event monitoring method according to an embodiment of the present invention mainly includes the following steps S301 to S302. The event monitoring method according to this embodiment can be executed by a monitoring device for event monitoring. The monitoring device for event monitoring can be a client for monitoring, that is, a monitoring end.
[0074] Step S301: when a child node creation event of a target node is monitored, some or all child nodes of the target node are acquired from a server according to a child node acquisition strategy, where the target node is a node of the server, which may be a Zookeeper terminal.
[0075] Step S302: For each target sub-node in some or all of the sub-nodes, complete event processing based on the target sub-node, and return a message indicating that the event processing is completed to the server.
[0076] Register the monitoring event with the server in advance, including registering the monitoring event for the target node's child node creation event.
[0077] Periodically check whether the transaction identifier of the target node stored locally is consistent with the transaction identifier of the target node stored on the server. If they are inconsistent, reset the current event node recorded locally. The current event node is the child node corresponding to the most recently completed event processing on the listening end. The locally stored transaction identifier is obtained from the server when registering the listening event with the server. The transaction identifier of the target node is generated when the target node is created.
[0078] Pre-configure the child node acquisition strategy on the server side; when the child node acquisition strategy indicates that only the most recent listening event is to be obtained, obtain some or all child nodes of the target node, including: obtaining the child node with the largest sequence number of the target node, where the sequence number indicates the order in which the child nodes of the target node are created; when the child node acquisition strategy indicates that each listening event is to be obtained, obtain some or all child nodes of the target node, including: if the current event node sequence number is recorded locally, obtain the child nodes of the target node whose sequence number is greater than the current event node sequence number; if the current event node sequence number is not recorded locally, obtain the child nodes of each sequence number of the target node, where the current event node sequence number is the sequence number of the child node corresponding to the most recently completed event processing on the listening side.
[0079] The contents already introduced in the above embodiments will not be described in detail in this embodiment.
[0080] Figure 4 4 is a schematic diagram of main modules of a service device for event monitoring according to an embodiment of the present invention.
[0081] like Figure 4 As shown, a service device 400 for event monitoring according to an embodiment of the present invention mainly includes: a monitoring event registration module 401 and a monitoring event triggering module 402 .
[0082] The monitoring event registration module 401 is used to register the monitoring event for the monitoring end, and the monitoring event registration includes registering the monitoring of the child node creation event of the target node.
[0083] The monitoring event triggering module 402 is used to create a child node of the target node to store the modified data when the target node is triggered to be modified, and send part or all of the child nodes of the target node to the monitoring end according to the child node acquisition strategy of the monitoring end.
[0084] In one embodiment, the monitoring event registration module is specifically used to: modify the monitoring of the target node to the monitoring of the child nodes of the target node through the encapsulation package, and the monitoring of the child nodes of the target node is used to monitor the child node creation event.
[0085] In one embodiment, a message receiving module is further included, which is used to: receive a message returned by the listener after completing event processing based on some or all of the child nodes; for each target child node in some or all of the child nodes, determine the message returned by each listener in the listener set after completing event processing based on the target child node. The listener event triggering module 402 can also be used to delete the target child node. The listener set is a set of listeners that register for listener events.
[0086] In one embodiment, whenever the message receiving module receives a message returned by a listening end that event processing based on a target subnode is completed, the listening event triggering module 402 creates a persistent node under the target subnode; the listening event triggering module 402 is also specifically used to: determine that the number of all persistent nodes created under the target subnode is greater than or equal to the number of listening ends in the listening end set, and delete the target subnode and all persistent nodes created under the target subnode.
[0087] In one embodiment, it also includes a listening end recording module, which is used to: create a shadow node of the target node and a temporary child node under the shadow node, so as to record the number of listening ends in the listening end set through the number of temporary child nodes, and the temporary child nodes correspond one-to-one to the listening ends in the listening end set.
[0088] In one embodiment, the service device 400 for event monitoring also includes a configuration module for pre-configuring a child node acquisition strategy; when the configured child node acquisition strategy indicates that only the most recent monitoring event is obtained, the monitoring event triggering module is specifically used to: send the child node with the largest sequence number of the target node to the monitoring end, and the sequence number indicates the creation order of the child nodes of the target node; when the configured child node acquisition strategy indicates that each monitoring event is obtained, the monitoring event triggering module is specifically used to: if the monitoring end records the current event node sequence number, then send the child nodes of the target node with a sequence number greater than the current event node sequence number to the monitoring end; if the monitoring end does not record the current event node sequence number, then send each sequence number child node of the target node to the monitoring end, and the current event node sequence number is the sequence number of the child node corresponding to the most recent event processing completed by the monitoring end.
[0089] The contents already introduced in the above embodiments will not be described in detail in this embodiment.
[0090] Figure 5 It is a schematic diagram of main modules of a monitoring device for event monitoring according to an embodiment of the present invention.
[0091] like Figure 5 As shown, a monitoring device 500 for event monitoring according to an embodiment of the present invention mainly includes: a monitoring event acquisition module 501 and a monitoring event execution module 502 .
[0092] The monitoring event acquisition module 501 is used to acquire part or all of the child nodes of the target node from the server according to the child node acquisition strategy when monitoring the child node creation event of the target node. The target node is a node of the server.
[0093] The monitoring event execution module 502 is used to complete event processing for each target sub-node in some or all of the sub-nodes based on the target sub-node, and return a message indicating that the event processing is completed to the server.
[0094] In one embodiment, the monitoring device 500 for event monitoring further includes a monitoring event registration request module, which is used to pre-register a monitoring event with the server, and the registration of the monitoring event includes registering the monitoring of the child node creation event of the target node.
[0095] In one embodiment, the listening device 500 for event listening also includes a detection module, which is used to periodically detect whether the transaction identifier of the locally stored target node is consistent with the transaction identifier of the target node stored on the server. If they are inconsistent, the current event node recorded locally is reset. The current event node is the child node corresponding to the most recent event processing completed by the listening end. The locally stored transaction identifier is obtained from the server when registering the listening event with the server, and the transaction identifier of the target node is generated when the target node is created.
[0096] In one embodiment, a subnode acquisition strategy is pre-configured on the server side; when the subnode acquisition strategy indicates that only the most recent monitoring event is to be obtained, the monitoring event acquisition module 501 is specifically used to: obtain the maximum sequence number child node of the target node, and the sequence number indicates the creation order of the child nodes of the target node; when the subnode acquisition strategy indicates that each monitoring event is to be obtained, the monitoring event acquisition module 501 is specifically used to: if the current event node sequence number is recorded locally, then obtain the child nodes of the target node whose sequence number is greater than the current event node sequence number; if the current event node sequence number is not recorded locally, then obtain the child nodes of each sequence number of the target node, and the current event node sequence number is the sequence number of the child node corresponding to the most recent event processing completed by the listening end.
[0097] The contents already introduced in the above embodiments will not be described in detail in this embodiment.
[0098] Figure 6 It is a schematic diagram of the main structure of an event monitoring system according to an embodiment of the present invention.
[0099] like Figure 6As shown, an event monitoring system 600 according to an embodiment of the present invention mainly includes: a service device 601 for event monitoring, and a monitoring device 602 for event monitoring. The service device 601 for event monitoring has the same modules as the service device 400 for event monitoring described above, and the module functions are also the same; the monitoring device 602 for event monitoring has the same modules as the monitoring device 500 for event monitoring described above, and the module functions are also the same.
[0100] The contents already introduced in the above embodiments will not be described in detail in this embodiment.
[0101] Figure 7 An exemplary system architecture 700 to which the event monitoring method or event monitoring device according to the embodiment of the present invention can be applied is shown.
[0102] like Figure 7 As shown, system architecture 700 may include terminal devices 701, 702, 703, network 704 and server 705. Network 704 is used to provide a medium for communication links between terminal devices 701, 702, 703 and server 705. Network 704 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0103] Users can use terminal devices 701, 702, and 703 to interact with server 705 through network 704 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 701, 702, and 703, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).
[0104] The terminal devices 701 , 702 , and 703 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0105] The server 705 may be a server that provides various services, such as a backend management server (only for example) that supports shopping websites browsed by users using the terminal devices 701, 702, and 703. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information, product information - only for example) to the terminal device.
[0106] It should be noted that the event monitoring method provided in the embodiment of the present invention is generally executed by the server 705 , and accordingly, the event monitoring device is generally disposed in the server 705 .
[0107] It should be understood that Figure 7The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0108] Reference below Figure 8 , which shows a schematic diagram of the structure of a computer system 800 of a terminal device or server suitable for implementing an embodiment of the present invention. Figure 8 The terminal device or server shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0109] like Figure 8 As shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage part 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the system 800 are also stored. The CPU 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0110] The following components are connected to the I / O interface 805: an input section 806 including a keyboard, a mouse, etc.; an output section 807 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, a modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the I / O interface 805 as needed. A removable medium 811, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 810 as needed, so that a computer program read therefrom is installed into the storage section 808 as needed.
[0111] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 809, and / or installed from the removable medium 811. When the computer program is executed by the central processing unit (CPU) 801, the above-mentioned functions defined in the system of the present invention are executed.
[0112] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0113] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0114] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be arranged in a processor, for example, may be described as: a processor includes a monitoring event registration module and a monitoring event triggering module. Wherein, the names of these modules do not constitute a limitation on the modules themselves under certain circumstances, for example, the monitoring event registration module may also be described as "a module for registering monitoring events for a monitoring end, wherein the registration of monitoring events includes registering a monitoring module for a subnode creation event of a target node".
[0115] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: registering a listening event for a listening end, and registering a listening event includes registering a listening event for a subnode creation event of a target node; when a target node is triggered to be modified, creating a subnode of the target node to store the modified data, and sending part or all of the subnodes of the target node to the listening end according to the subnode acquisition strategy of the listening end.
[0116] According to the technical solution of the embodiment of the present invention, the listening end registers the listening event, and the registered listening event includes registering the listening of the child node creation event of the target node (such as the zk node); when the target node is triggered to be modified, the child node of the target node is created to store the modified data, and according to the child node acquisition strategy of the listening end, some or all of the child nodes of the target node are sent to the listening end. It is possible to monitor every change of the node and achieve the purpose of permanent monitoring; when the zk node changes multiple times in a very short time, or when there is a network fluctuation delay, and when the client service is restarted, the listening event will not be lost; the flexible configuration of the monitoring strategy is realized, and the client can choose to monitor every change or the last change of the node.
[0117] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. An event monitoring method, characterized in that: include: Registering a monitoring event for the monitoring end, wherein the registering monitoring event includes registering a monitoring for a child node creation event of the target node; When the target node is triggered to be modified, a child node of the target node is created to store the modified data, and part or all of the child nodes of the target node are sent to the listening end according to the child node acquisition strategy of the listening end; The target node is one of the nodes on the server side, and the child nodes of the target node are persistent sequential nodes.
2. The method according to claim 1, characterized in that The registering of monitoring the child node creation event of the target node includes: By encapsulating the package, the monitoring of the target node is modified to the monitoring of the child nodes of the target node, and the monitoring of the child nodes of the target node is used to monitor the child node creation event.
3. The method according to claim 1, characterized in that After sending some or all of the child nodes of the target node to the listening end, the method further comprises: Receive a message returned by the listener after completing event processing based on some or all of the child nodes; For each target child node among some or all of the child nodes, determine the message returned by each listener set after the target child node completes the event processing, and then delete the target child node. The listener set is a set of listeners registered to listen to events.
4. The method according to claim 3, characterized in that Whenever a message is received from the listening end indicating that the event processing is completed based on the target child node, a persistent node is created under the target child node; The step of determining that each listening end in the listening end set receives the message returned after completing the event processing based on the target child node, and then deleting the target child node, includes: It is determined that the number of all persistent nodes created under the target child node is greater than or equal to the number of listening terminals in the listening terminal set, and the target child node and all persistent nodes created under the target child node are deleted.
5. The method according to claim 4, characterized in that Before registering the monitoring event on the monitoring end, the following steps are included: A shadow node of the target node and a temporary child node under the shadow node are created to record the number of listening terminals in the listening terminal set through the number of the temporary child nodes, and the temporary child nodes correspond one-to-one to the listening terminals in the listening terminal set.
6. The method according to claim 1, characterized in that Pre-configuring the child node acquisition strategy; In the case where the configured child node acquisition strategy indicates that only the most recent listening event is acquired, sending some or all of the child nodes of the target node to the listening end includes: sending the child node with the largest sequence number of the target node to the listening end, the sequence number indicating the creation order of the child nodes of the target node; In the case where the configured child node acquisition strategy indicates the acquisition of each listening event, sending part or all of the child nodes of the target node to the listening end includes: if the listening end records the current event node sequence number, sending the child nodes of the target node whose sequence numbers are greater than the current event node sequence number to the listening end; if the listening end does not record the current event node sequence number, sending each sequence-numbered child node of the target node to the listening end, and the current event node sequence number is the sequence number of the child node corresponding to the event processing most recently completed by the listening end.
7. An event monitoring method, characterized in that: include: When a child node creation event of a target node is monitored, some or all child nodes of the target node are obtained from the server according to the child node acquisition strategy, wherein the target node is one of the nodes of the server, and when the target node is triggered to be modified, a child node of the target node is created to store the modified data; For each target subnode among the part or all of the subnodes, completing event processing based on the target subnode, and returning a message of event processing completion to the server; The child nodes of the target node are persistent sequential nodes.
8. The method according to claim 7, characterized in that Also includes: Registering a monitoring event with the server in advance, wherein the registering monitoring event includes registering a monitoring event for a child node creation event of the target node.
9. The method according to claim 8, characterized in that Also includes: Periodically check whether the transaction identifier of the target node stored locally is consistent with the transaction identifier of the target node stored in the server. If they are inconsistent, reset the current event node recorded locally. The current event node is the child node corresponding to the event processing most recently completed by the current listening end. The locally stored transaction identifier is obtained from the server when registering a listening event with the server. The transaction identifier of the target node is generated when the target node is created.
10. The method according to claim 7, characterized in that Also includes: Pre-configure the child node acquisition strategy on the server; In the case where the child node acquisition strategy indicates that only the most recent listening event is acquired, the acquiring of some or all child nodes of the target node includes: acquiring the child node with the largest sequence number of the target node, where the sequence number indicates the order in which the child nodes of the target node are created; In the case where the child node acquisition strategy indicates to acquire each monitoring event, the acquisition of part or all of the child nodes of the target node includes: if the current event node sequence number is recorded locally, then acquiring the child nodes of the target node whose sequence number is greater than the current event node sequence number; if the current event node sequence number is not recorded locally, then acquiring the child nodes of each sequence number of the target node, the current event node sequence number is the sequence number of the child node corresponding to the event processing most recently completed by the listening end.
11. A service device for event monitoring, characterized in that: include: A monitoring event registration module, used to register monitoring events for the monitoring end, wherein the monitoring event registration includes registering monitoring of the child node creation event of the target node; A listening event triggering module is used to create a child node of the target node to store the modified data when the target node is triggered to be modified, and send some or all of the child nodes of the target node to the listening end according to the child node acquisition strategy of the listening end; the target node is one of the nodes of the server end, and the child nodes of the target node are persistent sequential nodes.
12. The device according to claim 11, characterized in that It also includes a message receiving module, which is used to: receive a message returned by the listening end after completing event processing based on some or all of the sub-nodes; for each target sub-node among the some or all of the sub-nodes, determine the message returned by each listening end of the listening end set after completing the event processing based on the target sub-node; The monitoring event triggering module is further used to delete the target child node, and the monitoring end set is a set of monitoring ends that register monitoring events.
13. The device according to claim 12, characterized in that It also includes a listening end recording module for: A shadow node of the target node and a temporary child node under the shadow node are created to record the number of listening terminals in the listening terminal set through the number of the temporary child nodes, and the temporary child nodes correspond one-to-one to the listening terminals in the listening terminal set.
14. The device according to claim 11, characterized in that It also includes a configuration module, which is used to pre-configure the sub-node acquisition strategy; In the case where the configured child node acquisition strategy indicates that only the most recent listening event is acquired, the listening event triggering module is further used to: send the child node with the largest sequence number of the target node to the listening end, where the sequence number indicates the creation order of the child nodes of the target node; In the case where the configured sub-node acquisition strategy indicates the acquisition of each listening event, the listening event triggering module is also used for: if the listening end records the current event node sequence number, then the sub-nodes of the target node whose sequence number is greater than the current event node sequence number are sent to the listening end; if the listening end does not record the current event node sequence number, then the sub-nodes of each sequence number of the target node are sent to the listening end, and the current event node sequence number is the sequence number of the sub-node corresponding to the event processing most recently completed by the listening end.
15. A monitoring device for event monitoring, characterized in that: include: A monitoring event acquisition module is used to acquire part or all of the subnodes of the target node from the server according to the subnode acquisition strategy when monitoring the subnode creation event of the target node, wherein the target node is one of the nodes of the server, and when the target node is triggered to be modified, create a subnode of the target node to store the modified data; A monitoring event execution module, used for completing event processing for each target sub-node in the part or all of the sub-nodes based on the target sub-node, and returning a message of event processing completion to the server; The child nodes of the target node are persistent sequential nodes.
16. The device according to claim 15, characterized in that It also includes a monitoring event registration request module, which is used to: pre-register a monitoring event with the server, wherein the registration of the monitoring event includes registering the monitoring of the child node creation event of the target node.
17. The device according to claim 16, characterized in that Also included are detection modules for: Periodically check whether the transaction identifier of the target node stored locally is consistent with the transaction identifier of the target node stored in the server. If they are inconsistent, reset the current event node recorded locally. The current event node is the child node corresponding to the event processing most recently completed by the current listening end. The locally stored transaction identifier is obtained from the server when registering a listening event with the server. The transaction identifier of the target node is generated when the target node is created.
18. An event monitoring system, characterized in that: include: A service device for event monitoring according to any one of claims 11 to 14, and a monitoring device for event monitoring according to any one of claims 15 to 17.
19. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 10.
20. A computer readable medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 10 is implemented.
Citation Information
Patent Citations
Method and device for modifying configuration information in distributed system
CN108984544A
Configuration file management method and device, equipment and storage medium
CN110417870A