zookeeper-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrick Hunt <ph...@apache.org>
Subject Re: Getting data after the watch
Date Fri, 02 Mar 2012 17:54:10 GMT
On Thu, Mar 1, 2012 at 4:11 PM, Amirhossein Kiani <amirhkiani@gmail.com> wrote:
> Hi ZooKeepers,

Hi Amir.

> I just recently had an issue about getting the a node's updated data after the watch
was actually fired. Being pretty confused, I read the documentation page again and sure enough
this has been stated:
>
> "A client will see a watch event for a znode it is watching before seeing the new data
that corresponds to that znode."
> http://zookeeper.apache.org/doc/r3.1.2/zookeeperProgrammers.html
>

Those docs are pretty old. Try using the current version:
http://zookeeper.apache.org/doc/current/zookeeperProgrammers.html

> Now, I'm confused about how a data watch could actually be useful... But aside from that,
is this statement also true about the node's list of Children? I.e. are a node's children
it's "data" too?
>

Watches let you know something changed. Then you can take actions.
Typically this means that the data of a znode changed, or the znode
itself changed (created/deleted, children added/removed). There are
two separate calls related to your question - getData and getChildren,
they set watches on the data an child list respectively.

> Because if this is the case, wouldn't the recipe for barriers hang if it gets the watch
for a new node addition goes off and in:
>
>  if (list.size() < size) {
>                        mutex.wait();
>
>  list.size() is still smaller than size?
>
> Or is this statement about watches only true for a data on the node?

No. It's true for both cases. If you set a data watch then it's
guaranteed that if you getData after being notified you will see the
updated data. Same for getChildren and it's child list.

Regards,

Patrick

Mime
View raw message