zk 1.7.3 → 1.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +1 -47
- data/RELEASES.markdown +7 -0
- data/Rakefile +1 -1
- data/lib/zk/locker/locker_base.rb +2 -2
- data/lib/zk/version.rb +1 -1
- data/spec/informal/two-locks-enter-three-locks-leave.rb +54 -0
- metadata +7 -5
data/README.markdown
CHANGED
@@ -64,53 +64,7 @@ In addition to all of that, I would like to think that the public API the ZK::Cl
|
|
64
64
|
[EventMachine]: https://github.com/eventmachine/eventmachine
|
65
65
|
[zk-eventmachine]: https://github.com/slyphon/zk-eventmachine
|
66
66
|
|
67
|
-
##
|
68
|
-
|
69
|
-
### v1.7.1 ###
|
70
|
-
|
71
|
-
* Fixes nasty bug "LockWaitTimeout causes lock to be forever unusable" (#49)
|
72
|
-
|
73
|
-
### v1.7.0 ###
|
74
|
-
|
75
|
-
* Added Locker timeout feature for blocking calls. (issue #40)
|
76
|
-
|
77
|
-
Previously, when dealing with locks, there were only two options: blocking or non-blocking. In order to come up with a time-limited lock, you had to poll every so often until you acquired the lock. This is, needless to say, both inefficient and doesn't allow for fair acquisition.
|
78
|
-
|
79
|
-
A timeout option has been added so that when blocking waiting for a lock, you can specify a deadline by which the lock should have been acquired.
|
80
|
-
|
81
|
-
```ruby
|
82
|
-
zk = ZK.new
|
83
|
-
|
84
|
-
locker = zk.locker('lock name')
|
85
|
-
|
86
|
-
begin
|
87
|
-
locker.lock(:wait => 5.0) # wait up to 5.0 seconds to acquire the lock
|
88
|
-
rescue ZK::Exceptions::LockWaitTimeoutError
|
89
|
-
$stderr.puts "could not acquire the lock in time"
|
90
|
-
end
|
91
|
-
```
|
92
|
-
|
93
|
-
Also available when using the convenience `#with_lock` methods
|
94
|
-
|
95
|
-
```ruby
|
96
|
-
|
97
|
-
zk = ZK.new
|
98
|
-
|
99
|
-
begin
|
100
|
-
zk.with_lock('lock name', :wait => 5.0) do |lock|
|
101
|
-
# do stuff while holding lock
|
102
|
-
end
|
103
|
-
rescue ZK::Exceptions::LockWaitTimeoutError
|
104
|
-
$stderr.puts "could not acquire the lock in time"
|
105
|
-
end
|
106
|
-
|
107
|
-
```
|
108
|
-
|
109
|
-
### v1.6.4 ###
|
110
|
-
|
111
|
-
* Remove unnecessary dependency on backports gem
|
112
|
-
* *Fix for use in resque!* A small bug was preventing resque from activating the fork hook.
|
113
|
-
|
67
|
+
## Release info / Changelog
|
114
68
|
|
115
69
|
See the [RELEASES][] page for more info on features and bugfixes in each release.
|
116
70
|
|
data/RELEASES.markdown
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
This file notes feature differences and bugfixes contained between releases.
|
2
2
|
|
3
|
+
### v1.7.4 ###
|
4
|
+
|
5
|
+
* Narsty bug in Locker (#54)
|
6
|
+
|
7
|
+
If a locker is waiting on the lock, and a connection interruption occurs (that doesn't render the session invalid), the waiter will attempt to clean up while the connection is invalid, and not succeed in cleaning up its ephemeral. This patch will recognize that the `@lock_path` was already acquired, and just wait on the current owner (ie. it won't create an erroneous *third* lock node). The reproduction code has been added under `spec/informal/two-locks-enter-three-locks-leave.rb`
|
8
|
+
|
9
|
+
|
3
10
|
### v1.7.3 ###
|
4
11
|
|
5
12
|
* bug fix for "Callbacks Hash in EventHandlerSubscription::Base gets longer randomly" (#52)
|
data/Rakefile
CHANGED
@@ -8,7 +8,7 @@ if File.exists?(release_ops_path)
|
|
8
8
|
require File.join(release_ops_path, 'releaseops')
|
9
9
|
|
10
10
|
# sets up the multi-ruby zk:test_all rake tasks
|
11
|
-
ReleaseOps::TestTasks.define_for(*%w[1.8.7 1.9.2 jruby ree 1.9.3])
|
11
|
+
ReleaseOps::TestTasks.define_for(*%w[1.8.7 1.9.2 jruby-1.6.8 ree 1.9.3])
|
12
12
|
|
13
13
|
# sets up the task :default => 'spec:run' and defines a simple
|
14
14
|
# "run the specs with the current rvm profile" task
|
@@ -327,8 +327,8 @@ module ZK
|
|
327
327
|
#
|
328
328
|
def create_lock_path!(prefix='lock')
|
329
329
|
@mutex.synchronize do
|
330
|
-
@lock_path
|
331
|
-
@parent_stat
|
330
|
+
@lock_path ||= @zk.create("#{root_lock_path}/#{prefix}", :mode => :ephemeral_sequential)
|
331
|
+
@parent_stat ||= @zk.stat(root_lock_path)
|
332
332
|
end
|
333
333
|
|
334
334
|
logger.debug { "got lock path #{@lock_path}" }
|
data/lib/zk/version.rb
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'zk'
|
3
|
+
require 'logger'
|
4
|
+
STDOUT.sync = true
|
5
|
+
$logger = Logger.new(STDOUT)
|
6
|
+
|
7
|
+
ZK_ERRORS = [
|
8
|
+
ZK::Exceptions::LockAssertionFailedError,
|
9
|
+
ZK::Exceptions::InterruptedSession,
|
10
|
+
ZK::Exceptions::Retryable,
|
11
|
+
Zookeeper::Exceptions::ContinuationTimeoutError
|
12
|
+
].freeze
|
13
|
+
|
14
|
+
ZK.logger = $logger
|
15
|
+
Zookeeper.logger = $logger
|
16
|
+
|
17
|
+
def with_lock
|
18
|
+
@zk_lock ||= @zk.locker('test_lock')
|
19
|
+
$logger.info("Our lock: #{@zk_lock.inspect}")
|
20
|
+
@zk_lock.lock!(true)
|
21
|
+
@zk_lock.assert!
|
22
|
+
yield
|
23
|
+
ensure
|
24
|
+
if @zk_lock
|
25
|
+
begin
|
26
|
+
@zk_lock.unlock!
|
27
|
+
$logger.info("Lock successfully released.")
|
28
|
+
rescue => ex
|
29
|
+
$logger.warn("Failed to release lock: #{ex.inspect}")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def wait_for_lock
|
35
|
+
$logger.info("Waiting for lock")
|
36
|
+
with_lock { manage }
|
37
|
+
end
|
38
|
+
|
39
|
+
def manage
|
40
|
+
while true
|
41
|
+
@zk_lock.assert!
|
42
|
+
$logger.info("I have the lock")
|
43
|
+
sleep 5
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
begin
|
48
|
+
@zk ||= ZK.new('localhost:2181')
|
49
|
+
wait_for_lock
|
50
|
+
rescue *ZK_ERRORS => ex
|
51
|
+
$logger.warn("Exception: #{ex}, #{ex.backtrace.first}. Retrying")
|
52
|
+
sleep 2
|
53
|
+
retry
|
54
|
+
end
|
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:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
version: 1.7.
|
9
|
+
- 4
|
10
|
+
version: 1.7.4
|
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-
|
19
|
+
date: 2012-11-10 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: zookeeper
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- spec/event_catcher_spec.rb
|
118
118
|
- spec/informal/close-in-event-thread.rb
|
119
119
|
- spec/informal/lock_with_dead_session.rb
|
120
|
+
- spec/informal/two-locks-enter-three-locks-leave.rb
|
120
121
|
- spec/informal/what-the-fork.rb
|
121
122
|
- spec/log4j.properties
|
122
123
|
- spec/logging_progress_bar_formatter.rb
|
@@ -186,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
187
|
requirements: []
|
187
188
|
|
188
189
|
rubyforge_project:
|
189
|
-
rubygems_version: 1.8.
|
190
|
+
rubygems_version: 1.8.24
|
190
191
|
signing_key:
|
191
192
|
specification_version: 3
|
192
193
|
summary: A high-level wrapper around the zookeeper driver
|
@@ -194,6 +195,7 @@ test_files:
|
|
194
195
|
- spec/event_catcher_spec.rb
|
195
196
|
- spec/informal/close-in-event-thread.rb
|
196
197
|
- spec/informal/lock_with_dead_session.rb
|
198
|
+
- spec/informal/two-locks-enter-three-locks-leave.rb
|
197
199
|
- spec/informal/what-the-fork.rb
|
198
200
|
- spec/log4j.properties
|
199
201
|
- spec/logging_progress_bar_formatter.rb
|