Summary of the invention
It is existing to solve this application provides the data processing method and device of a kind of zookeeper client
Zookeeper client can not be handled the data of node, such as the importing, export, backup-and-restore of node data, because
This, the client of existing zookeeper is unable to satisfy the problem of developer handles the demand of node data.
In a first aspect, this application provides a kind of data processing methods of zookeeper client, which comprises
Obtain the IP address of server and corresponding port information in the zookeeper cluster of user's typing;
According to the IP address and corresponding port information, the corresponding node tree of the server info is generated;
All destination nodes and corresponding data processing request, the destination node for obtaining the node tree are that user exists
The node selected on the node tree, the data processing request are the destination node removal request, the creation target section
The request of child node under point, modification, increase and the removal request of the node data of the destination node and the target section
One of importing or export request of the node data of point data;
If the data processing request is that destination node removal request, child node under the creation destination node are asked
Ask and one of the modification of the node data of destination node, increase and removal request, then to corresponding destination node and/
Or the node data of destination node carries out respective handling;
If the data processing request is the importing or export request of the node data of destination node, imports or export
The node data of the destination node.
Second aspect, this application provides a kind of data processing equipment of zookeeper client, described device includes:
First obtains module, the IP address of server and corresponding in the zookeeper cluster for obtaining user's typing
Port information;
Generation module, for it is corresponding to generate the server info according to the IP address and corresponding port information
Node tree;
Second obtain module, for obtain the node tree all destination nodes and corresponding data processing request, institute
Stating destination node is the node that user selects on the node tree, and the data processing request is that destination node deletion is asked
Ask, create the request of child node under the destination node, modification, increase and the deletion of the node data of the destination node to ask
Ask and the importing of the node data of the destination node data or export request one of;
Processing module, if being destination node removal request, the creation destination node for the data processing request
Under child node request and one of modification, increase and the removal request of node data of destination node, then to corresponding
Destination node and/or destination node node data carry out respective handling;
If the data processing request is the importing or export request of the node data of destination node, imports or export
The node data of the destination node.
From the above technical scheme, this application provides the data processing methods and dress of a kind of zookeeper client
It sets, user can select specific node to carry out the importing and export of node data, and the importing for passing through node data in node tree
It can be achieved that the actual demand of user can be met well to the backup-and-restore of node data with export.
Specific embodiment
Referring to Fig. 1, in a first aspect, the embodiment of the present application provides a kind of data processing method of zookeeper client,
Include the following steps:
Step 101: obtaining the IP address of server and corresponding port information in the zookeeper cluster of user's typing.
Zookeeper is the formal sub-project of Hadoop, it is that a reliable coordination for large-scale distributed system is
System, the function of providing include: configuring maintenance, name Service, distributed synchronization, group service etc..The target of Zookeeper is exactly to seal
Complicated error-prone key service is installed, the system of interface and performance efficiency easy to use, function-stable is supplied to user.
Zookeeper cluster is generally made of three or more servers.When disposing zookeeper cluster, Yong Huke
Zookeeper cluster is inputted by API (Application Programming Interface, application programming interface)
Configuration information, browsing generates configuring request according to the configuration information, and is sent to control server, and control server receives should
Configuring request generates the basic configuration of the zookeeper example of the zookeeper cluster with deployment, to generate zookeeper
Example, and it is sent to each server to be disposed, the portion for the zookeeper example for thering is each server to complete on book server
The zookeeper example of deployment is affixed one's name to and starts, to form zookeeper cluster.
Step 102: according to the IP address and corresponding port information, generating the corresponding node of the server info
Tree.
Step 103: obtain the node tree all destination nodes and corresponding data processing request, the destination node
For the node that user selects on the node tree, the data processing request is the destination node removal request, creates institute
State modification, increase and the removal request of the request of the child node under destination node, the node data of the destination node, Yi Jisuo
State one of importing or the export request of the node data of destination node data.
Destination node can be selected on node tree by user according to actual needs, can choose one or more.
Zookeeper client provided by the embodiments of the present application can not only realize that the creation or deletion of node, the modification of node data increase
Add or delete, can also be achieved the importing and export of node data, the perfect function of existing zookeeper increases the spirit used
Activity.
Step 104: if the data processing request is the son under destination node removal request, the creation destination node
One of modification, increase and removal request of node data of request and destination node of node, then to corresponding target
The node data of node and/or destination node carries out respective handling.
Step 105: if the data processing request is the importing or export request of the node data of destination node, leading
Enter or export the node data of the destination node.
From the above technical scheme, this application provides a kind of data processing method of zookeeper client, users
Specific node can be selected to carry out the importing and export of node data in node tree, and can by the importing and export of node data
It realizes to the backup-and-restore of node data, the actual demand of user can be met well.
Referring to fig. 2, in another embodiment provided by the present application, above-described embodiment step 102 includes the following steps:
Step 201: according to the IP address and corresponding port information, finding corresponding root node in zookeeper.
In zookeeper, node be one with unix file system path similar node, can be stored to the node
Data, or data are obtained from the node.If flag is set as EPHEMERAL when creating node, when creation node and
After zookeeper is disconnected, node will not be there are in zookeeper.Each node has phase for different servers
The permission answered, specifically, IP address and corresponding port information by different server, with node setting access authority into
Row matching, if successful match, then it represents that the accessible node of the server obtains the node data of the node.And at this
In step, IP address and corresponding port information using any one server in the zookeeper cluster of user's typing are searched
Root node to corresponding root node, as node tree.
Step 202: since root node, being scanned for using recursive method, until searching the leaf segment of no child node
Until point, node tree is obtained.
Wherein, the specific implementation scanned for using recursion method are as follows: it is downstream scanned for since root node,
It searches whether root node has child node, if there is child node, then continues searching and be subordinated to the child node of root node and whether there is
Child node, and so on, until search the node of no child node, i.e., until leaf node, obtain by root node, leaf node and
Several intermediate nodes form node trees, specifically can refer to node tree shown in fig. 5, wherein and node A is root node, node D,
E, F, G are leaf node, remaining is intermediate node.Preferably, the node tree of generation can be presented to user by tree structure, to use
Family can intuitively understand node relationships relevant to the server of inquiry.
Referring to Fig. 3, in another embodiment provided by the present application, when the data processing request is to export the target section
When the node data request of point, above-mentioned steps 105 include the following steps:
Step 301: being traversed from the leaf node of each destination node to no child node.
Destination node can be selected on node tree by user according to actual needs, can choose one or more.
Specifically, referring to Fig. 5, it is assumed that user has selected node, then since node until node, i.e. traverse node.
Step 302: obtaining the node of all nodes storage of the leaf node from each destination node to no child node
Data.
Node data includes data relevant to the node, such as node configuration data.
Step 303: all node datas of export.
Step 304: by all nodes of the leaf node from each destination node to no child node and derived all
Node data is stored into preset file.
All nodes and derived node data are stored in preset file, data can be backed up, to prevent
Loss of data or when distorting, restores node data.
Referring to fig. 4, when the data processing request is the node data request for importing the destination node, above-mentioned steps
105 include:
Step 401: obtain file destination, the file destination include the first node catalogue of each destination node with
And corresponding destination node data.
File destination is the file of user's specified node to be imported, the file format of this document must with it is provided by the present application
The file format of the node storage of the client of zookeeper is identical.It may include that all destination nodes are corresponding in file destination
Nodal directory, and corresponding destination node data.If node all on node tree is set destination node by user,
The node data of all nodes need to be imported, i.e., full dose imports.
Step 402: judging whether each destination node is stored with the first node catalogue phase with the destination node
Same second node catalogue, if the destination node is stored with the first node catalogue identical second with the destination node
Nodal directory thens follow the steps 403;If the destination node does not store the first node catalogue phase with the destination node
Same second node catalogue, thens follow the steps 404.
Step 403: the corresponding destination node data of first node catalogue in the file destination are imported into second section
Point catalogue.
Step 404: identical with the first node catalogue of the destination node second node catalogue of creation, and by the mesh
It marks the corresponding destination node data of first node catalogue in file and imports the second node catalogue.
From the above technical scheme, user can select one or more target sections according to actual needs on node tree
Point imports corresponding destination node data, and in the case where corrupted data or loss, realizes the reduction of node data, mention
The data reliability and safety of the client of high zookeeper.
Referring to Fig. 6, this application provides a kind of data processing equipment of zookeeper client, described device includes:
First obtains module 601, the IP address and correspondence of server in the zookeeper cluster for obtaining user's typing
Port information;
Generation module 602, for it is corresponding to generate the server info according to the IP address and corresponding port information
Node tree;
Second obtain module 603, for obtain the node tree all destination nodes and corresponding data processing request,
The destination node is the node that user selects on the node tree, and the data processing request is destination node deletion
Request, create the request of child node under the destination node, modification, increase and the deletion of the node data of the destination node
One of importing or export request of the node data of request and the destination node data;
Processing module 604, if being the destination node removal request, the creation mesh for the data processing request
One kind of the request of the child node under node and modification, the increase and removal request of the node data of the destination node is marked,
Respective handling then is carried out to the node data of corresponding destination node and/or destination node;
If the data processing request is the importing or export request of the node data of destination node, imports or export
The node data of the destination node.
From the above technical scheme, this application provides a kind of data processing equipment of zookeeper client, users
Specific node can be selected to carry out the importing and export of node data in node tree, and can by the importing and export of node data
It realizes to the backup-and-restore of node data, the actual demand of user can be met well.
Further, referring to Fig. 7, the generation module 602 includes:
Searching unit 701 is corresponding in zookeeper for finding according to the IP address and corresponding port information
Root node;
Search unit 702, for being scanned for using recursive method since root node, until searching s.m.p section
Until the leaf node of point, node tree is obtained.
Further, referring to Fig. 8, when the data processing request is to export the node data request of the destination node
When, the processing module 604 includes:
Traversal Unit 801, for being traversed from the leaf node of each destination node to no child node;
First acquisition unit 802, for obtaining all sections of the leaf node from each destination node to no child node
The node data of point storage;
Lead-out unit 803, for exporting all node datas.
Further, described device further include:
Storage unit, for by all nodes of the leaf node from each destination node to no child node and derived
All node datas are stored into preset file.
Further, referring to Fig. 9, when the data processing request is to import the node data request of the destination node
When, the processing module 604 includes:
Second acquisition unit 901, for obtaining file destination, the file destination includes the of each destination node
One nodal directory and corresponding destination node data;
Judging unit 902, for judging whether each destination node is stored with the first segment with the destination node
The identical second node catalogue of point catalogue, if the destination node is stored with the first node catalogue phase with the destination node
The corresponding destination node data of first node catalogue in the file destination are then imported described second by same second node catalogue
Nodal directory;If the destination node does not store second node mesh identical with the first node catalogue of the destination node
Record, then create identical with the first node catalogue of destination node second node catalogue, and by the file destination the
The corresponding destination node data of one nodal directory import the second node catalogue.
From the above technical scheme, this application provides the data processing methods and dress of a kind of zookeeper client
It sets, user can select specific node to carry out the importing and export of node data, and the importing for passing through node data in node tree
It can be achieved that the actual demand of user can be met well to the backup-and-restore of node data with export.
It is required that those skilled in the art can be understood that the technology in the embodiment of the present application can add by software
The mode of general hardware platform realize.Based on this understanding, the technical solution in the embodiment of the present application substantially or
Or the part that contributes to existing technology can be embodied in the form of software products, which can deposit
Storage is in storage medium, such as ROM/RAM, magnetic disk, CD, including some instructions computer equipment to as (can be with
It is personal computer, server or the network equipment etc.) execute certain part institutes of each embodiment of the application or embodiment
The method stated.
Various embodiments are described in a progressive manner for this specification, same and similar part between each embodiment
Can cross-reference, each embodiment focuses on the differences from other embodiments, especially for device reality
For applying example, since it is substantially similar to the method embodiment, so being described relatively simple, related place is referring to embodiment of the method
Part explanation.