zk 1.7.1 → 1.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,9 +32,12 @@ module ZK
32
32
  watcher.register_state_handler(:connecting, &block)
33
33
  end
34
34
 
35
- # register a block to be called when our session has expired. This usually happens
36
- # due to a network partitioning event, and means that all callbacks and watches must
37
- # be re-registered with the server
35
+ # register a block to be called when our session has expired. This
36
+ # usually happens due to a network partitioning event, and means that all
37
+ # watches must be re-registered with the server (i.e. after the
38
+ # on_connected event is received). Callbacks set up via #register are
39
+ # still valid and will respond to events, it's the event delivery you
40
+ # have to set up again by using :watch.
38
41
  #
39
42
  # @todo need to come up with a way to test this
40
43
  def on_expired_session(&block)
@@ -54,9 +54,10 @@ module ZK
54
54
  elsif lock_opts.blocking?
55
55
  block_until_write_lock!(:timeout => lock_opts.timeout)
56
56
  else
57
- cleanup_lock_path!
58
57
  false
59
58
  end
59
+ ensure
60
+ cleanup_lock_path! unless @mutex.synchronize { @locked }
60
61
  end
61
62
 
62
63
  # the node that is next-lowest in sequence number to ours, the one we
@@ -92,15 +93,6 @@ module ZK
92
93
 
93
94
  @node_deletion_watcher.block_until_deleted(opts)
94
95
  rescue WeAreTheLowestLockNumberException
95
- rescue ZK::Exceptions::LockWaitTimeoutError
96
- # in the case of a timeout exception, we need to ensure the lock
97
- # path is cleaned up, since we're not interested in acquisition
98
- # anymore
99
- logger.warn { "got ZK::Exceptions::LockWaitTimeoutError, cleaning up lock path" }
100
- cleanup_lock_path!
101
- raise
102
- ensure
103
- logger.debug { "block_until_deleted returned" }
104
96
  end
105
97
 
106
98
  @mutex.synchronize { @locked = true }
@@ -91,11 +91,10 @@ module ZK
91
91
  elsif lock_opts.blocking?
92
92
  block_until_read_lock!(:timeout => lock_opts.timeout)
93
93
  else
94
- # we didn't get the lock, and we're not gonna wait around for it, so
95
- # clean up after ourselves
96
- cleanup_lock_path!
97
94
  false
98
95
  end
96
+ ensure
97
+ cleanup_lock_path! unless @mutex.synchronize { @locked }
99
98
  end
100
99
 
101
100
  def block_until_read_lock!(opts={})
@@ -109,12 +108,6 @@ module ZK
109
108
  end
110
109
 
111
110
  @node_deletion_watcher.block_until_deleted(opts)
112
- rescue ZK::Exceptions::LockWaitTimeoutError
113
- # in the case of a timeout exception, we need to ensure the lock
114
- # path is cleaned up, since we're not interested in acquisition
115
- # anymore
116
- cleanup_lock_path!
117
- raise
118
111
  rescue NoWriteLockFoundException
119
112
  # next_lowest_write_lock_name may raise NoWriteLockFoundException,
120
113
  # which means we should not block as we have the lock (there is nothing to wait for)
@@ -1,3 +1,3 @@
1
1
  module ZK
2
- VERSION = "1.7.1"
2
+ VERSION = "1.7.2"
3
3
  end
@@ -15,31 +15,32 @@ shared_examples_for 'ZK::Locker::ExclusiveLocker' do
15
15
  zk.mkdir_p(rlp)
16
16
 
17
17
  bogus_path = zk.create("#{rlp}/#{ZK::Locker::EXCLUSIVE_LOCK_PREFIX}", :sequential => true, :ephemeral => true)
18
+ logger.debug { "bogus_path: #{bogus_path.inspect}" }
18
19
 
19
20
  th = Thread.new do
20
- locker2.lock(true)
21
+ locker.lock(true)
21
22
  end
22
23
 
23
24
  th.run
24
25
 
25
26
  logger.debug { "calling wait_until_blocked" }
26
- proc { locker2.wait_until_blocked(2) }.should_not raise_error
27
+ proc { locker.wait_until_blocked(5) }.should_not raise_error
27
28
  logger.debug { "wait_until_blocked returned" }
28
- locker2.should be_waiting
29
+ locker.should be_waiting
29
30
 
30
- wait_until { zk.exists?(locker2.lock_path) }
31
+ wait_until { zk.exists?(locker.lock_path) }
31
32
 
32
- zk.exists?(locker2.lock_path).should be_true
33
+ zk.exists?(locker.lock_path).should be_true
33
34
 
34
35
  zk.delete(bogus_path)
35
36
 
36
37
  th.join(5).should == th
37
38
 
38
- locker2.lock_path.should_not == bogus_path
39
+ locker.lock_path.should_not == bogus_path
39
40
 
40
41
  zk.create(bogus_path, :ephemeral => true)
41
42
 
42
- lambda { locker2.assert! }.should raise_error(ZK::Exceptions::LockAssertionFailedError)
43
+ lambda { locker.assert! }.should raise_error(ZK::Exceptions::LockAssertionFailedError)
43
44
  end
44
45
  end
45
46
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zk
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 7
9
- - 1
10
- version: 1.7.1
9
+ - 2
10
+ version: 1.7.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jonathan D. Simms
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-09-22 00:00:00 Z
19
+ date: 2012-10-08 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: zookeeper