zookeeper-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ted Dunning <ted.dunn...@gmail.com>
Subject Re: how to lock one-of-many ?
Date Wed, 24 Feb 2010 06:05:44 GMT
You have to be careful there of race conditions.  ZK's slightly surprising
API makes it pretty easy to get this right, however.

The correct way to do what you suggest is to read the list of children in
the locks directory and put a watch on the directory at the same time.  If
the number of locks equals the number of resources, you wait.  If it is
less, you can randomly pick one of the apparently unlocked resources at
random.  If you fail, start again by checking the number of resources.

On Tue, Feb 23, 2010 at 9:09 PM, Martin Waite <waite.134@googlemail.com>wrote:

> I guess another optimisation might be to count the number of locks held
> first:  if the count equals the number of resources, try again later.  But
> I
> suppose that might require a sync call first to ensure that zk instance my
> client is connected to is up to date.

Ted Dunning, CTO

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message