Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement Chubby-style lock sequencers with ZooKeeper?

Google's Chubby distributed lock manager has a feature called "sequencers" that I would like to emulate using ZooKeeper. Is there a known good way to do so?

A sequencer works as follows:

  1. Client acquires a lock on a resource
  2. Client requests a sequencer for it's lock, which is a string with some metadata
  3. Client makes a call to a service and passes the sequencer as a parameter
  4. The service uses the sequencer to verify that the client still holds the lock before processing the request

The goal is to prevent a situation where a client dies after making a call to a remote service which must be protected by a lock.

The main paper on Chubby is available at http://research.google.com/archive/chubby.html. Sequencers are discussed in section 2.4.

Thanks!

like image 541
Chris Sears Avatar asked Jan 09 '12 21:01

Chris Sears


1 Answers

The zookeeper lock recipes all involve the locking process create a sequential ephemeral znode. The name of the sequential ephemeral znode will be unique, and the znode will cease to exist if the lockers session expires due to the locker not sending a valid heartbeat within the timeout.

So the locking process just needs to pass the name of the sequential ephemeral znode it created while locking to the remote service, and the remote service can check the existence of the znode before processing.

You can be even have the remote service add a watch to the znode, and be notified when the znode is removed.

like image 168
sbridges Avatar answered Oct 24 '22 05:10

sbridges