You don't demote yourself on disconnect. (Everyone else may still believe you 
are the leader.) Check out the "Things to Remember about Watches" section in 
the programmer's guide.

When you are disconnected from ZK you don't know what is happening, so you have 
to act conservatively. Your session may or may not have expired. You will not 
know for sure until you reconnect to ZK.

From: []
Sent: Wednesday, January 07, 2009 8:24 AM
Subject: Re: Simpler ZooKeeper event interface....

Hiram Chirino wrote:
> Knowing about a disconnection may be important to some apps.  For
> example if an app uses ZK for leader election, and the leader gets
> disconnected from ZK, he should give up being the leader, since a
> different leader may get elected while he is disconnected from ZK.
Is that necessarily true?

My assumption is the following - if I'm connected to multiple ZK
servers, then assuming the leader election recipe given in the docs, the
leader needs to only demote itself if its session expires. Of course,
doing the same on disconnect does not violate safety, it just seems too
pessimistic. In the case of followers, a disconnected event would mean
that they will have to wait for reconnection before being able to
determine if one of them should in fact be the leader.

Reply via email to