hadoop-zookeeper-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Neo Anderson <javadeveloper...@yahoo.co.uk>
Subject Wacther question
Date Sat, 06 Nov 2010 11:50:01 GMT
My question is - what is the right way to received notification once a znode is created?

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
          }
        }

and 

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(KeeperException.java:102)
	at org.apache.zookeeper.KeeperException.create(KeeperException.java:42)
	at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:637)

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.

Thanks. 






      

Mime
View raw message