lib/zk/locker/locker_base.rb in zk-1.7.4 vs lib/zk/locker/locker_base.rb in zk-1.7.5
- old
+ new
@@ -325,18 +325,30 @@
# to ensure we don't accidentally remove a lock we don't own. see
# [rule #34](https://github.com/slyphon/zk/issues/34)...er, *issue* #34.
#
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}" }
@lock_path
rescue NoNode
create_root_path!
retry
+ end
+
+ # if we previously had a lock path, check if it still exists
+ #
+ def lock_path_exists?
+ @mutex.synchronize do
+ return false unless @lock_path
+ return false unless root_lock_path_same?
+ zk.exists?(@lock_path)
+ end
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