Disclosure of Invention
The application provides a data processing method and device for a zookeeper client, which aim to solve the problem that the existing zookeeper client cannot process data of nodes, such as the importing, exporting, backing up and restoring of the node data, so that the existing zookeeper client cannot meet the requirement of developers for processing the node data.
In a first aspect, the present application provides a data processing method for a zookeeper client, where the method includes:
acquiring an IP address and corresponding port information of a server in a zookeeper cluster, which are input by a user;
generating a node tree corresponding to the server information according to the IP address and the corresponding port information;
acquiring all target nodes of the node tree and corresponding data processing requests, wherein the target nodes are nodes selected by a user on the node tree, and the data processing requests are one of target node deletion requests, requests for creating child nodes under the target nodes, requests for modifying, adding and deleting node data of the target nodes and requests for importing or exporting the node data of the target node data;
if the data processing request is one of a target node deleting request, a request for creating a child node under the target node and a modifying, adding and deleting request of the node data of the target node, corresponding processing is carried out on the corresponding target node and/or the node data of the target node;
and if the data processing request is an import or export request of the node data of the target node, importing or exporting the node data of the target node.
In a second aspect, the present application provides a data processing apparatus for a zookeeper client, the apparatus comprising:
the first acquisition module is used for acquiring the IP address of the server in the zookeeper cluster and the corresponding port information which are input by a user;
a generating module, configured to generate a node tree corresponding to the server information according to the IP address and the corresponding port information;
a second obtaining module, configured to obtain all target nodes of the node tree and corresponding data processing requests, where the target nodes are nodes selected by a user on the node tree, and the data processing requests are one of a target node deletion request, a request for creating child nodes under the target nodes, a modification, addition, and deletion request of node data of the target nodes, and an import or export request of node data of the target node data;
the processing module is used for correspondingly processing the corresponding target node and/or the node data of the target node if the data processing request is one of a target node deleting request, a request for creating a child node under the target node and a modifying, adding and deleting request of the node data of the target node;
and if the data processing request is an import or export request of the node data of the target node, importing or exporting the node data of the target node.
According to the technical scheme, the data processing method and device for the zookeeper client are provided, a user can select a specific node in a node tree to import and export node data, backup and restoration of the node data can be achieved through the import and export of the node data, and actual requirements of the user can be well met.
Detailed Description
Referring to fig. 1, in a first aspect, an embodiment of the present application provides a data processing method for a zookeeper client, including the following steps:
step 101: and acquiring the IP address of the server in the zookeeper cluster and the corresponding port information which are input by the user.
Zookeeper is a formal sub-project of Hadoop, is a reliable coordination system for large-scale distributed systems, and provides functions including: configuration maintenance, name service, distributed synchronization, group service, etc. The Zookeeper aims to package complex and error-prone key services and provide a simple and easy-to-use interface and a system with high performance and stable functions for users.
Zookeeper clusters typically consist of more than three servers. When a zookeeper cluster is deployed, a user can input configuration information of the zookeeper cluster through an Application Programming Interface (API), browse configuration requests generated according to the configuration information and send the configuration requests to a central control server, the central control server receives the configuration requests and generates basic configurations of zookeeper instances of the zookeeper cluster deployed on a belt, and therefore the zookeeper instances are generated and sent to each server to be deployed, each server finishes deployment of the zookeeper instances on the local server and starts the deployed zookeeper instances, and therefore the zookeeper cluster is formed.
Step 102: and generating a node tree corresponding to the server information according to the IP address and the corresponding port information.
Step 103: and acquiring all target nodes of the node tree and corresponding data processing requests, wherein the target nodes are nodes selected by a user on the node tree, and the data processing requests are one of target node deletion requests, requests for creating child nodes under the target nodes, requests for modifying, adding and deleting node data of the target nodes and requests for importing or exporting the node data of the target node data.
The target nodes can be selected by the user on the node tree according to actual requirements, and one or more target nodes can be selected. The zookeeper client provided by the embodiment of the application can realize the creation or deletion of the node, the modification, addition or deletion of the node data, and the import and export of the node data, thereby perfecting the functions of the existing zookeeper and increasing the use flexibility.
Step 104: and if the data processing request is one of a target node deleting request, a request for creating a child node under the target node and a modifying, adding and deleting request of the node data of the target node, carrying out corresponding processing on the corresponding target node and/or the node data of the target node.
Step 105: and if the data processing request is an import or export request of the node data of the target node, importing or exporting the node data of the target node.
According to the technical scheme, the data processing method of the zookeeper client is provided, a user can select a specific node in a node tree to import and export node data, backup and restoration of the node data can be realized through the import and export of the node data, and the actual requirements of the user can be well met.
Referring to fig. 2, in another embodiment provided by the present application, the step 102 of the above embodiment includes the following steps:
step 201: and finding the corresponding root node in the zookeeper according to the IP address and the corresponding port information.
In zookeeper, a node is a node similar to the unix file system path, and data can be stored to or retrieved from the node. If flag is set to EPHEMERAL when a node is created, the node will not be in the presence of zookeeper when the created node and zookeeper lose connectivity. Each node has corresponding authority for different servers, specifically, matching with the access authority set by the node through the IP addresses and corresponding port information of different servers, and if matching is successful, indicating that the server can access the node to acquire the node data of the node. In this step, the IP address of any server in the zookeeper cluster and the corresponding port information, which are entered by the user, are used to find the corresponding root node, which is used as the root node of the node tree.
Step 202: and searching by using a recursive method from the root node until leaf nodes without child nodes are searched, and obtaining the node tree.
The specific implementation mode of searching by using the recursive method is as follows: searching from the root node to the downstream, finding whether the root node has a child node, if so, continuing to search whether the child node belonging to the root node has a child node, and so on until a node without child nodes, that is, a leaf node, is searched, obtaining a node tree consisting of the root node, the leaf node, and a plurality of intermediate nodes, specifically referring to the node tree shown in fig. 5, where node a is the root node, node D, E, F, G is the leaf node, and the rest are the intermediate nodes. Preferably, the generated node tree can be presented to the user by a tree structure, so that the user can intuitively know the node relation related to the server of the query.
Referring to fig. 3, in another embodiment provided by the present application, when the data processing request is a node data request for deriving the target node, the step 105 includes the following steps:
step 301: traversing from each of the target nodes to a leaf node without child nodes.
The target nodes can be selected by the user on the node tree according to actual requirements, and one or more target nodes can be selected. Specifically, referring to fig. 5, assuming that the user selects a node, the nodes are traversed starting from node to node.
Step 302: node data stored from each of the target nodes to all of the leaf nodes having no child nodes is obtained.
The node data includes data related to the node, such as node configuration data and the like.
Step 303: all of the node data is derived.
Step 304: and storing all nodes from each target node to leaf nodes without child nodes and all derived node data into a preset file.
All nodes and the exported node data are stored in a preset file, and the data can be backed up to prevent the node data from being restored when the data is lost or tampered.
Referring to fig. 4, when the data processing request is a node data request for importing the target node, the step 105 includes:
step 401: and acquiring a target file, wherein the target file comprises a first node directory of each target node and corresponding target node data.
The target file is a file to be imported into a designated node by a user, and the file format of the file must be the same as the file format stored by the node of the zookeeper client provided by the application. The target file may include node directories corresponding to all target nodes and corresponding target node data. If the user sets all the nodes on the node tree as target nodes, the node data of all the nodes needs to be imported, namely, the node data is imported in a full amount.
Step 402: judging whether each target node stores a second node directory which is the same as the first node directory of the target node, and executing a step 403 if the target node stores a second node directory which is the same as the first node directory of the target node; if the target node does not store a second nodal directory that is the same as the first nodal directory of the target node, then step 404 is performed.
Step 403: and importing the target node data corresponding to the first node directory in the target file into the second node directory.
Step 404: and creating a second node directory which is the same as the first node directory of the target node, and importing the target node data corresponding to the first node directory in the target file into the second node directory.
According to the technical scheme, a user can select one or more target nodes on the node tree according to actual requirements, corresponding target node data is imported, restoration of the node data is achieved under the condition that the data is damaged or lost, and data reliability and safety of the zookeeper client are improved.
Referring to fig. 6, the present application provides a data processing apparatus of a zookeeper client, the apparatus comprising:
a first obtaining module 601, configured to obtain an IP address and corresponding port information of a server in a zookeeper cluster, where the IP address and the port information are recorded by a user;
a generating module 602, configured to generate a node tree corresponding to the server information according to the IP address and the corresponding port information;
a second obtaining module 603, configured to obtain all target nodes of the node tree and corresponding data processing requests, where the target nodes are nodes selected by a user on the node tree, and the data processing requests are one of a target node deletion request, a request for creating child nodes under the target nodes, a modification, addition, and deletion request of node data of the target nodes, and an import or export request of node data of the target node data;
a processing module 604, configured to perform corresponding processing on the node data of the corresponding target node and/or target node if the data processing request is one of the target node deletion request, the request for creating a child node under the target node, and the modification, addition, and deletion requests of the node data of the target node;
and if the data processing request is an import or export request of the node data of the target node, importing or exporting the node data of the target node.
According to the technical scheme, the data processing device of the zookeeper client is provided, a user can select a specific node in a node tree to import and export node data, backup and restoration of the node data can be realized through the import and export of the node data, and the actual requirements of the user can be well met.
Further, referring to fig. 7, the generating module 602 includes:
a searching unit 701, configured to search a corresponding root node in the zookeeper according to the IP address and the corresponding port information;
the searching unit 702 is configured to search, starting from the root node, by using a recursive method until a leaf node without a child node is searched, so as to obtain a node tree.
Further, referring to fig. 8, when the data processing request is a node data request for exporting the target node, the processing module 604 includes:
a traversal unit 801, configured to traverse from each target node to a leaf node without a child node;
a first obtaining unit 802, configured to obtain node data stored in all nodes from each target node to a leaf node without a child node;
a deriving unit 803, configured to derive all the node data.
Further, the apparatus further comprises:
and the storage unit is used for storing all nodes from each target node to the leaf nodes without child nodes and all the derived node data into a preset file.
Further, referring to fig. 9, when the data processing request is a node data request for importing the target node, the processing module 604 includes:
a second obtaining unit 901, configured to obtain a target file, where the target file includes a first node directory of each target node and corresponding target node data;
a determining unit 902, configured to determine whether each target node stores a second node directory that is the same as the first node directory of the target node, and if the target node stores a second node directory that is the same as the first node directory of the target node, import target node data corresponding to the first node directory in the target file into the second node directory; and if the target node does not store a second node directory which is the same as the first node directory of the target node, creating a second node directory which is the same as the first node directory of the target node, and importing the target node data corresponding to the first node directory in the target file into the second node directory.
According to the technical scheme, the data processing method and device for the zookeeper client are provided, a user can select a specific node in a node tree to import and export node data, backup and restoration of the node data can be achieved through the import and export of the node data, and actual requirements of the user can be well met.
Those skilled in the art will clearly understand that the techniques in the embodiments of the present application may be implemented by way of software plus a required general hardware platform. Based on such understanding, the technical solutions in the embodiments of the present application may be embodied in the form of a software product, which may be stored in a storage medium, such as a ROM/RAM, a magnetic disk, an optical disk, or the like, and includes a computer device (which may be a personal computer, a server, or a network device) for executing the method described in the embodiments or some parts of the embodiments of the present application.
The embodiments of the present disclosure are described in a progressive manner, and the same and similar parts among the embodiments can be referred to each other, and each embodiment focuses on the differences from the other embodiments, and particularly, for the embodiment of the apparatus, since it is substantially similar to the embodiment of the method, the description is relatively simple, and related parts can be referred to the part of the embodiment of the method.