Quantcast

when the zookeeper Expired ,may I have to rebuild the watch on a znode?

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

when the zookeeper Expired ,may I have to rebuild the watch on a znode?

iamct
This post was updated on .
I had set watch on one znode.When the zookeeper session expired,I create a new zookeeper session.
The watch I had set is effective ?
I can/t find a answer in FAQ.
How can i do?

in the FAQ (https://cwiki.apache.org/confluence/display/ZOOKEEPER/FAQ)said:

At session expiration the cluster will delete any/all ephemeral nodes owned by that session and immediately notify any/all connected clients of the change (anyone watching those znodes)

I can/t understand 。 above , “immediately notify any/all connected clients of the change (anyone watching those znodes)”,only notify the watch on the ephemeral nodes  ?the watch on the Persistent node can/t notify?
I test it used by java bind(using the method ‘Is there an easy way to expire a session for testing?’)。I found when The session expire ,the watch set on the Persistent node can be notify
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: when the zookeeper Expired ,may I have to rebuild the watch on a znode?

Wangpei (Peter)
No. setting watcher is binds to session, so it will not triggered anymore.
you have to set the watcher again on the new session, do it yourself.
My way is writing a reconnect watcher decorator, this class add a connection watcher and it rebuild watcher.
A connection wrapper should simplify the code.

-----邮件原件-----
发件人: iamct [mailto:[hidden email]]
发送时间: 2012年6月4日 10:42
收件人: [hidden email]
主题: when the zookeeper Expired ,may I have to rebuild the watch on a znode?

I had seted a watch on one znode.When the zookeeper session expired,I create a new zookeeper session.
The watch I had seted is effective ?
I can/t find a answer in FAQ.
How can i do?

--
View this message in context: http://zookeeper-user.578899.n2.nabble.com/when-the-zookeeper-Expired-may-I-have-to-rebuild-the-watch-on-a-znode-tp7577513.html
Sent from the zookeeper-user mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: when the zookeeper Expired ,may I have to rebuild the watch on a znode?

iamct
Thank you !
And  you said “No. setting watcher is binds to session, so it will not triggered anymore.
you have to set the watcher again on the new session, do it yourself.
My way is writing a reconnect watcher decorator, this class add a connection watcher and it rebuild watcher.
A connection wrapper should simplify the code.”

can you give me a example? Thank you very much!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: when the zookeeper Expired ,may I have to rebuild the watch on a znode?

Wangpei (Peter)
In reply to this post by Wangpei (Peter)
curator is a good high level client lib, it may help you much.
my implement is a home-made lib, I do not found curator that time :(

with a connection wrapper like curator client, the watcher decorator is quite simple.
Inner connection watcher will trigger when old session expired and new session open again.
this connection watcher set the watcher, checks Stat and trigger the watcher if needed.


-----邮件原件-----
发件人: iamct [mailto:[hidden email]]
发送时间: 2012年6月4日 14:36
收件人: [hidden email]
主题: Re: when the zookeeper Expired ,may I have to rebuild the watch on a znode?

Thank you very much。
Can you give a example?

--
View this message in context: http://zookeeper-user.578899.n2.nabble.com/when-the-zookeeper-Expired-may-I-have-to-rebuild-the-watch-on-a-znode-tp7577513p7577515.html
Sent from the zookeeper-user mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: when the zookeeper Expired ,may I have to rebuild the watch on a znode?

iamct
Thank you!
I have another question。

I set a watch on one znode。 A change happen,the service my client had connected sent the  packet ,but this time,my client becomes partitioned from the ZK serving cluster。
 When my session reconnect,may I get the event?

I think it is not。
but in the http://zookeeper.apache.org/doc/current/zookeeperProgrammers.html#ch_zkWatches
said : ZooKeeper provides an ordering guarantee: a client will never see a change for which it has set a watch until it first sees the watch event.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: when the zookeeper Expired ,may I have to rebuild the watch on a znode?

Heyuan Li
ZK only guarantee on write sequence to zookeeper, not watch recv by client.

2012/6/4 iamct <[hidden email]>:

> Thank you!
> I have another question。
>
> I set a watch on one znode。 A change happen,the service my client had
> connected sent the  packet ,but this time,my client becomes partitioned from
> the ZK serving cluster。
>  When my session reconnect,may I get the event?
>
> I think it is not。
> but in the
> http://zookeeper.apache.org/doc/current/zookeeperProgrammers.html#ch_zkWatches
> said : ZooKeeper provides an ordering guarantee: a client will never see a
> change for which it has set a watch until it first sees the watch event.
>
>
>
>
> --
> View this message in context: http://zookeeper-user.578899.n2.nabble.com/when-the-zookeeper-Expired-may-I-have-to-rebuild-the-watch-on-a-znode-tp7577513p7577520.html
> Sent from the zookeeper-user mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: when the zookeeper Expired ,may I have to rebuild the watch on a znode?

Patrick Hunt
In reply to this post by iamct
On Mon, Jun 4, 2012 at 7:45 AM, iamct <[hidden email]> wrote:
>
> I set a watch on one znode。 A change happen,the service my client had
> connected sent the  packet ,but this time,my client becomes partitioned from
> the ZK serving cluster。
>  When my session reconnect,may I get the event?
>

Yes, you will get the notification when (if) the session eventually
reconnects to the service.

> I think it is not。
> but in the
> http://zookeeper.apache.org/doc/current/zookeeperProgrammers.html#ch_zkWatches
> said : ZooKeeper provides an ordering guarantee: a client will never see a
> change for which it has set a watch until it first sees the watch event.
>

That's correct. When the client reconnects you'll get any
notifications that you missed.

Patrick
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: when the zookeeper Expired ,may I have to rebuild the watch on a znode?

Wangpei (Peter)
In reply to this post by iamct
If it is the same session that it connect to another server, I believe the answer is yes.
If the old session is expired and a new session is create, the watch not get the event.
You need to set watch with new session, and those calls will return the changed data/state.
So you need to process those in your reconnect logic.
A tip: do not keep whole data or children, just the version or cversion.

-----邮件原件-----
发件人: iamct [mailto:[hidden email]]
发送时间: 2012年6月4日 22:46
收件人: [hidden email]
主题: Re: when the zookeeper Expired ,may I have to rebuild the watch on a znode?

Thank you!
I have another question。

I set a watch on one znode。 A change happen,the service my client had connected sent the  packet ,but this time,my client becomes partitioned from the ZK serving cluster。
 When my session reconnect,may I get the event?

I think it is not。
but in the
http://zookeeper.apache.org/doc/current/zookeeperProgrammers.html#ch_zkWatches
said : ZooKeeper provides an ordering guarantee: a client will never see a change for which it has set a watch until it first sees the watch event.




--
View this message in context: http://zookeeper-user.578899.n2.nabble.com/when-the-zookeeper-Expired-may-I-have-to-rebuild-the-watch-on-a-znode-tp7577513p7577520.html
Sent from the zookeeper-user mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: when the zookeeper Expired ,may I have to rebuild the watch on a znode?

iamct
This post was updated on .
In reply to this post by Patrick Hunt
Thank you all
I have another question。

I set a watch (getData)on a znode。the getData api said :
 <p>
     * If the watch is non-null and the call is successful (no exception is
     * thrown), a watch will be left on the node with the given path. The watch
     * will be triggered by a successful operation that sets data on the node, or
     * deletes the node.
     * <p>

I used the method “Is there an easy way to expire a session for testing?” to imitate the expire
(in https://cwiki.apache.org/confluence/display/ZOOKEEPER/FAQ)

in the process,I do not update the znode ,why the watch be triggered.
I found the  WatchedEvent state is Disconnected and Expired.and the event type is None

I can/t found the triggered condition in the zookeeper wiki and api. I am confuse.
The version is 3.3.3
help me! Thank you !





Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: when the zookeeper Expired ,may I have to rebuild the watch on a znode?

Michi Mutsuzaki
The event is called "None" (not a great name) in Java API. It's for
notifying the watches that the session state has changed.

http://zookeeper.apache.org/doc/r3.4.1/api/org/apache/zookeeper/Watcher.Event.EventType.html

It's up to you to decide how to handle these events. This page
provides a good insight about error handling in zookeeper.

http://wiki.apache.org/hadoop/ZooKeeper/ErrorHandling

--Michi

On Tue, Jun 5, 2012 at 1:25 AM, iamct <[hidden email]> wrote:

> Thank you all
> I have another question。
>
> I set a watch (getData)on a znode。the getData api said :
>  <p>
>     * If the watch is non-null and the call is successful (no exception is
>     * thrown), a watch will be left on the node with the given path. The
> watch
>     * will be triggered by a successful operation that sets data on the
> node, or
>     * deletes the node.
>     * <p>
>
> I used the method “Is there an easy way to expire a session for testing?” to
> imitate the expire
> (in https://cwiki.apache.org/confluence/display/ZOOKEEPER/FAQ)
>
> in the process,I can/t update the znode ,why the watch be triggered.
> I found the  WatchedEvent state is Disconnected and Expired.
>
> I can/t found the triggered condition in the zookeeper wiki and api. I am
> confuse.
>
> help me! Thank you !
>
>
>
>
>
>
>
> --
> View this message in context: http://zookeeper-user.578899.n2.nabble.com/when-the-zookeeper-Expired-may-I-have-to-rebuild-the-watch-on-a-znode-tp7577513p7577533.html
> Sent from the zookeeper-user mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: when the zookeeper Expired ,may I have to rebuild the watch on a znode?

iamct
Thank you!
but i thank it/s not my answer。
 My questiong is:using java api,I set a watch
( methed:getData(final String path, Watcher watcher, Stat stat) )

I know  the watch can be triggered when NodeDataChanged and NodeDeleted (the api tell me only the two EventType )。

but I found the watch was triggered by EventType.NOne when i try testing to expired a session。

https://cwiki.apache.org/confluence/display/ZOOKEEPER/FAQ 
Is there an easy way to expire a session for testing?)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: when the zookeeper Expired ,may I have to rebuild the watch on a znode?

Michi Mutsuzaki
Watches are not considered triggered when the watch handlers get
called with EventType.None, They are merely being notified that the
client got disconnected from ZooKeeper and they won't receive any
watch events until the session gets re-established. When the client
gets reconnected to ZooKeeper, it might find out that the session has
been expired. In that case, all the watches associated with that
sessions are lost.

This page explains why ZooKeeper notifies watches about session events.

http://zookeeper.apache.org/doc/r3.2.2/zookeeperProgrammers.html#ch_zkWatches

{quote}
When you disconnect from a server (for example, when the server
fails), you will not get any watches until the connection is
reestablished. For this reason session events are sent to all
outstanding watch handlers. Use session events to go into a safe mode:
you will not be receiving events while disconnected, so your process
should act conservatively in that mode.
{quote}

--Michi

On Tue, Jun 5, 2012 at 7:56 PM, iamct <[hidden email]> wrote:

> Thank you!
> but i thank it/s not my answer。
>  My questiong is:using java api,I set a watch
> ( methed:getData(final String path, Watcher watcher, Stat stat) )
>
> I know  the watch can be triggered when NodeDataChanged and NodeDeleted (the
> api tell me only the two EventType )。
>
> but I found the watch was triggered by EventType.NOne when i try testing to
> expired a session。
>
> (https://cwiki.apache.org/confluence/display/ZOOKEEPER/FAQ
> Is there an easy way to expire a session for testing?)
>
> --
> View this message in context: http://zookeeper-user.578899.n2.nabble.com/when-the-zookeeper-Expired-may-I-have-to-rebuild-the-watch-on-a-znode-tp7577513p7577535.html
> Sent from the zookeeper-user mailing list archive at Nabble.com.
Loading...