You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@curator.apache.org by Giridhar Addepalli <gi...@gmail.com> on 2014/03/05 06:01:09 UTC

Setting watch on node only if number of children is greater than zero

Hi All,

I am new to zookeeper/ curator.

I want to setup watch on node if number of children is greater than zero.

I can check number of children before setting the watch.
But there could be a race condition in which , number of children of the
node went to zero before setting up the watch and after checking for number
of children.
And this could lead to deadlock, because i will be listening for child
removal event and there will be none.

One way i could think of solving is polling for number of children in
separate thread.
But is there any cleaner approach via which i can avoid polling ?

Thanks,
Giridhar.

Re: Setting watch on node only if number of children is greater than zero

Posted by Jordan Zimmerman <jo...@jordanzimmerman.com>.
ZooKeeper doesn’t support that. You’d need to set a watcher and then do your logic once the watcher triggers. What is the application here? I suggest looking at one of the Curator recipes such as NodeCache or PathChildrenCache.

-Jordan

From: Giridhar Addepalli Giridhar Addepalli
Reply: user@curator.apache.org user@curator.apache.org
Date: March 5, 2014 at 12:01:55 AM
To: user@curator.apache.org user@curator.apache.org
Subject:  Setting watch on node only if number of children is greater than zero  
Hi All,

I am new to zookeeper/ curator.

I want to setup watch on node if number of children is greater than zero.

I can check number of children before setting the watch.
But there could be a race condition in which , number of children of the node went to zero before setting up the watch and after checking for number of children.
And this could lead to deadlock, because i will be listening for child removal event and there will be none.

One way i could think of solving is polling for number of children in separate thread.
But is there any cleaner approach via which i can avoid polling ?

Thanks,
Giridhar.