Permalink
Browse files

Fix for #55

  • Loading branch information...
tsilen committed Nov 19, 2012
1 parent 5bb2561 commit 2aa4c0adc05c538d7a27d72da11234ad3ec055bf
Showing with 12 additions and 2 deletions.
  1. +12 −2 lib/zk/locker/locker_base.rb
@@ -327,8 +327,10 @@ def got_lock?
#
def create_lock_path!(prefix='lock')
@mutex.synchronize do
- @lock_path ||= @zk.create("#{root_lock_path}/#{prefix}", :mode => :ephemeral_sequential)
- @parent_stat ||= @zk.stat(root_lock_path)
+ unless lock_path_exists?
+ @lock_path = @zk.create("#{root_lock_path}/#{prefix}", :mode => :ephemeral_sequential)
+ @parent_stat = @zk.stat(root_lock_path)
+ end
end
logger.debug { "got lock path #{@lock_path}" }
@@ -338,6 +340,14 @@ def create_lock_path!(prefix='lock')
retry
end
+ # if we previously had a lock path, check if it still exists
+ #
+ def lock_path_exists?
+ return false unless @lock_path
+ return false unless root_lock_path_same?
+ zk.exists?(@lock_path)
+ end
+
# if the root_lock_path has the same stat .ctime as the one
# we cached when we created our lock path, then we can be sure
# that we actually own the lock_path

0 comments on commit 2aa4c0a

Please sign in to comment.