zookeeper-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Waite <waite....@googlemail.com>
Subject how to lock one-of-many ?
Date Tue, 23 Feb 2010 12:05:47 GMT

I have a set of resources each of which has a unique identifier.  Each
resource element must be locked before it is used, and unlocked afterwards.

The logic of the application is something like:

lock any one element;
if (none locked) then
   exit with error;
   get resource-id from lock
   use resource
   unlock resource

Zookeeper looks like a good candidate for managing these locks, being fast
and resilient, and it seems quite simple to recover from client failure.

However, I cannot think of a good way to implement this sort of one-of-many

I could create a directory called "available" and another called "locked".
Available would have one entry for each resource id ( or one entry
containing a list of the resource-ids).  For locking, I could loop through
the available ids, attempting to create a lock for that in the locked
directory.  However this seems a bit clumsy and slow.  Also, the locks are
held for a relatively short time (1 second on average), and by time I have
blundered through all the possible locks, ids that were locked at the start
might be available by time I finished.

Can anyone think of a more elegant and efficient way of doing this ?


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