Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reliably watching a node in Zookeeper

Is there any simple way to always be sure I have the latest state (data and/or children) of a node in Zookeeper using only watches and not polling, taking into account that the node may not exist when I start or may be deleted and recreated? I tried to do this, but doing so turned out to be complicated enough (in terms of setting up the multiple watches needed, and avoiding race conditions that could lead to data being dropped if the node is created or deleted at the wrong time) that I gave up and switched to polling. (Being a few seconds behind is no problem for my application, but missing a change is bad and missing all future changes is very bad.)

I'm using Curator in Java, which has recipes to make several things easier, but this doesn't appear to be one of them.

like image 918
npt Avatar asked Jul 23 '14 20:07

npt


1 Answers

If you're using Curator, use NodeCache for a single node or PathChildrenCache for all the children of a node.

note: I'm the primary author of Curator

like image 84
Randgalt Avatar answered Jan 01 '23 15:01

Randgalt