javaapache-zookeeperapache-curator

Zookeper + Curator: watch node remove / remove a watch


I'm using zookeeper with curator 2.12.0.

I'm successfully watching on new nodes by calling getChildren (I don't know full node paths in advance) with watcher that submits task to call getChildren with watcher again. Now I want to watch node remove and only remove. I call checkExists with watcher. But if node doesn't exists for some reason it will be actually watcher for node creation that will never happen in my case. So I will left more and more "thrash" watchers, that will waste some resources as I suppose.

How could I remove watcher or add a watcher only if node exists?


Solution

  • ZooKeeper 3.4.x does not support watcher removal. Watchers are only removed when they trigger. ZooKeeper 3.5.x adds support for watcher removal. If you move to ZK 3.5.x and Curator 3.x/4.x you can use the watcher removal APIs. (NOTE: I'm the main author of Apache ZooKeeper).