Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recipe: Double Barrier #43

Open
eric opened this issue Aug 27, 2012 · 0 comments
Open

Recipe: Double Barrier #43

eric opened this issue Aug 27, 2012 · 0 comments

Comments

@eric
Copy link
Member

eric commented Aug 27, 2012

From http://zookeeper.apache.org/doc/trunk/recipes.html

Double barriers enable clients to synchronize the beginning and the end of a computation. When enough processes have joined the barrier, processes start their computation and leave the barrier once they have finished. This recipe shows how to use a ZooKeeper node as a barrier.

The pseudo code in this recipe represents the barrier node as b. Every client process p registers with the barrier node on entry and unregisters when it is ready to leave. A node registers with the barrier node via the Enter procedure below, it waits until x client process register before proceeding with the computation. (The x here is up to you to determine for your system.)

Enter

  1. Create a name n = b+"/"+p
  2. Set watch: exists(b + "/ready", true)
  3. Create child: create( n, EPHEMERAL)
  4. L = getChildren(b, false)
  5. if fewer children in L than x, wait for watch event
  6. else create(b + "/ready", REGULAR)

Leave

  1. L = getChildren(b, false)
  2. if no children, exit
  3. if p is only process node in L, delete(n) and exit
  4. if p is the lowest process node in L, wait on highest process node in P
  5. else delete(n) if still exists and wait on lowest process node in L
  6. goto 1

Like #42, it seems like this should go in the same gem as the locker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant