Zookeeper CLI - Apache ZooKeeper

What si Zookeeper CLI?

ZooKeeper Command Line Interface (CLI) is used to act together with the ZooKeeper ensemble for development purpose. It is useful for debugging and working approximately with special options.

To perform ZooKeeper CLI operations, first turn on your ZooKeeper server (“bin/zkServer.sh start”) and then, ZooKeeper client (“bin/zkCli.sh”). Once the client starts, you can carry out the following operation −
  • Create znodes
  • Get data
  • Watch znode for changes
  • Set data
  • Create children of a znode
  • List children of a znode
  • Check Status
  • Remove / Delete a znode
Now let us observe above command one by one with an example.

Create Znodes

Create a znode with the given pathway. The flag case denotes whether the created znode will be temporary, unrelenting, or sequential. By default, all znodes are persistent.
  • Ephemeral znodes (flag: e) will be robotically deleted when a session expires or when the client disconnects.
  • Sequential znodes guarantee that the znode path will be unique.
  • ZooKeeper ensemble will add sequence number along with 10 digit padding to the znode path. For example, the znode path /myapp will be converted to /myapp0000000001 and the next sequence number will be /myapp0000000002. If no flags are specified, then the znode is considered as persistent.

Syntax

Sample

Output

To create a Sequential znode, add -s flag as shown below.

Syntax

Sample

Output

To create an Ephemeral Znode, add -e flag as shown below.

Syntax

Sample

Output


Remember when a client connection is mislaid; the ephemeral znode will be deleted. You can try it by quitting the ZooKeeper CLI and then re-opening the CLI.

Get Data

It returns the associated data of the znode and metadata of the particular znode. You will get information such as when the data was previously modified, where it was modified, and information about the data. This CLI is also used to allocate watches to show notification about the data.

Syntax

Sample

Output


To access a sequential znode, you must enter the full path of the znode.

Sample

Output

Watch

Watches show a notification when the specified znode or znode’s children data changes. You can set a watch only in get command.

Syntax

Sample

Output

The output is similar to normal get command, but it will wait for znode changes in the background. <Start here>

Set Data

Set the data of the specified znode. Once you finish this set operation, you can check the data using the get CLI command.

Syntax

Sample

Output

If you assigned watch option in get command (as in previous command), then the output will be similar as shown below −

Output

Create Children / Sub-znode

Creating children is similar to creating new znodes. The only difference is that the path of the child znode will have the parent path as well.

Syntax

Sample

Output

List Children

This command is used to list and display the children of a znode.

Syntax

Sample

Output

Check Status

Status describes the metadata of a specified znode. It contains details such as Timestamp, Version number, ACL, Data length, and Children znode.

Syntax

Sample

Output

Remove a Znode

Removes a specified znode and recursively all its children. This would happen only if such a znode is available.

Syntax

Sample

Output

Delete (delete /path) command is similar to remove command, except the fact that it works only on znodes with no children.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Apache ZooKeeper Topics