You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@zookeeper.apache.org by Tom White <to...@gmail.com> on 2009/02/13 18:45:57 UTC

Watcher guarantees

If client sets a watcher on a znode by doing a getData operation is it
guaranteed to get the next change after the value it read, or can a
change be missed?

In other words if the value it read had zxid z1 and the next update of
the znode has zxid z2, will the watcher always get the event for the
change z2?

Thanks,
Tom

Re: Watcher guarantees

Posted by Patrick Hunt <ph...@apache.org>.
Tom White wrote:
> If client sets a watcher on a znode by doing a getData operation is it
> guaranteed to get the next change after the value it read, or can a
> change be missed?

> In other words if the value it read had zxid z1 and the next update of
> the znode has zxid z2, will the watcher always get the event for the
> change z2?

Yes, that is a strong guarantee. See the following:
http://hadoop.apache.org/zookeeper/docs/r3.0.1/zookeeperProgrammers.html#sc_WatchGuarantees

Patrick

Re: Watcher guarantees

Posted by Patrick Hunt <ph...@apache.org>.
Tom White wrote:
> Thanks for your answers. I understand that you have to call getData()
> to find the value of the znode, and that it may have been updated
> between the watcher being called and the getData() call. So in that
> sense you can miss updates. But watches have strong enough guarantees
> to allow you to keep up to date with the latest value by repeatedly
> setting a new watch after the old one fires.
> 
> The situation I was thinking about - and trying to avoid - was not
> being notified about z2, and having to wait for a further update z3
> before the watch fired (which could be an arbitrary time later),
> because it somehow missed z2. Sounds like this doesn't happen.

If it does please enter a JIRA. ;-)

Patrick

> 
> On Fri, Feb 13, 2009 at 6:21 PM, Mahadev Konar <ma...@yahoo-inc.com> wrote:
>>> If client sets a watcher on a znode by doing a getData operation is it
>>> guaranteed to get the next change after the value it read, or can a
>>> change be missed?
>> The watch is just a notification that the node changed. If you do a getData
>> on the node, you their might have been more updates on the node.
>> So yes, you can miss changes.
>>> In other words if the value it read had zxid z1 and the next update of
>>> the znode has zxid z2, will the watcher always get the event for the
>>> change z2?
>>>
>> The watcher will always get an event for zxid z2, but since the watch does
>> not have the data with it -- it will have to do getdata for the that node.
>>
>>> Thanks,
>>> Tom
>> Mahadev
>>
>>

Re: Watcher guarantees

Posted by Tom White <to...@gmail.com>.
Thanks for your answers. I understand that you have to call getData()
to find the value of the znode, and that it may have been updated
between the watcher being called and the getData() call. So in that
sense you can miss updates. But watches have strong enough guarantees
to allow you to keep up to date with the latest value by repeatedly
setting a new watch after the old one fires.

The situation I was thinking about - and trying to avoid - was not
being notified about z2, and having to wait for a further update z3
before the watch fired (which could be an arbitrary time later),
because it somehow missed z2. Sounds like this doesn't happen.

Cheers,
Tom

On Fri, Feb 13, 2009 at 6:21 PM, Mahadev Konar <ma...@yahoo-inc.com> wrote:
>> If client sets a watcher on a znode by doing a getData operation is it
>> guaranteed to get the next change after the value it read, or can a
>> change be missed?
> The watch is just a notification that the node changed. If you do a getData
> on the node, you their might have been more updates on the node.
> So yes, you can miss changes.
>>
>> In other words if the value it read had zxid z1 and the next update of
>> the znode has zxid z2, will the watcher always get the event for the
>> change z2?
>>
> The watcher will always get an event for zxid z2, but since the watch does
> not have the data with it -- it will have to do getdata for the that node.
>
>> Thanks,
>> Tom
> Mahadev
>
>

Re: Watcher guarantees

Posted by Mahadev Konar <ma...@yahoo-inc.com>.
> If client sets a watcher on a znode by doing a getData operation is it
> guaranteed to get the next change after the value it read, or can a
> change be missed?
The watch is just a notification that the node changed. If you do a getData
on the node, you their might have been more updates on the node.
So yes, you can miss changes.
> 
> In other words if the value it read had zxid z1 and the next update of
> the znode has zxid z2, will the watcher always get the event for the
> change z2?
>
The watcher will always get an event for zxid z2, but since the watch does
not have the data with it -- it will have to do getdata for the that node.
 
> Thanks,
> Tom
Mahadev