Apache ZooKeeper

16 / 47
ZooKeeper - Hands-on - Znodes

== Hands On == Lets switch to the zookeeper console as opened earlier.

We will try to create a persistent znode. We are going to create a znode with our name using command: create /cloudxlab mydata Lets check if it is created by going through list of znodes: ls / Also, check the data inside znode using: get /cloudxlab

To delete a znode cloudxlab, we can simply use rmr /cloudxlab

You could try creating the znode with your own login name using : create "mylogin"

Now, lets try to create an ephermal node. Switch to the zookeeper console as opened earlier. Create an ephermal node myeph using create -e /myeph somerandomdata

Now, exit the zookeeper-client by typing quit and pressing enter. Open the zookeeper-client again. try check if the nodes exists or not using: ls /myeph It should throw an error "Node does not exist"

Now, lets try to create sequential nodes. Instead of polluting the top level znode "/" lets create our persistent node first with a name cloudxlab using command: create /cloudxlab "mydata"

Lets create first sequential child with name starting with x under /cloudxlab using: create -s /cloudxlab/x "somedata"

It says created a znode under cloudxlab with name x followed by zeros.

If we create another sequential node in it it would be suffixed with 1. lets take a look: create -s /cloudxlab/y "someotherdata"

It should print: Created /cloudxlab/y0000000001

Now, even if we delete previously created node using rmr command [execute rmr /cloudxlab/x0000000000]

And try to create another sequential node, the deletion would have no impact on the sequence number. Lets take a look: create -s /cloudxlab/x data

As you can see, The new number is 2.