My question is - what is the right way to received notification once a znode is 

My scenario is that I have two threads, one (thread A) is going to save data to 
hdfs, another thread (thread B) is going to delete data stored in hdfs once 
thread A finishes its procedure. Thread A will create a znode and Thread B uses 
zk.exists() to register a watch. 

Thread A will only do 

zk.create(path, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);

at the end (in the final block) of a clean function. 

The watcher in therad B

      Watcher watcher = new Watcher(){
        public void process(WatchedEvent e){
          boolean exist = e.getType().equals(EventType.NodeCreated);
          boolean path = e.getPath().equals("/"+job_id+"/"+task_id);
          if(exist && path){
              // start cleaning data in hdfs


pass watcher to zk.exists(path, watcher);

but I gets `KeeperErrorCode = NoNode for' exception

org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode 
for /job_id/task_id
        at org.apache.zookeeper.KeeperException.create(
        at org.apache.zookeeper.KeeperException.create(
        at org.apache.zookeeper.ZooKeeper.create(

It looks like znode doesn't exists because thread A still not yet create znode 
with path '/job_id/task_id'; however, if I switch to make thread A create znode 
first then therad B executes zk.exists(path, watcher). Problems becomes thread 
B (or its watcher) would never get triggered deleting data in hdfs. 

How to fix this?

I appreciate any suggestion.


Reply via email to