zk 1.9.0 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,11 @@
1
1
  This file notes feature differences and bugfixes contained between releases.
2
2
 
3
+ ### v1.9.1 ###
4
+
5
+ * Fix re-rewatchind children watchers after the parent znode was deleted #68
6
+ * Deal with reopening a closed connection properly #70
7
+
8
+
3
9
  ### v1.9.0 ###
4
10
 
5
11
  * Semaphores!
data/Rakefile CHANGED
@@ -38,7 +38,7 @@ if File.exists?(release_ops_path)
38
38
  cd tmpdir do
39
39
  sh "git co #{tag} && git reset --hard && git clean -fdx"
40
40
 
41
- sh "rvm 1.8.7 do gem build zk.gemspec"
41
+ sh "gem build zk.gemspec"
42
42
 
43
43
  mv FileList['*.gem'], orig_dir
44
44
  end
@@ -245,6 +245,8 @@ module ZK
245
245
  logger.debug { "reopening, no fork detected" }
246
246
  @last_cnx_state = Zookeeper::ZOO_CONNECTING_STATE
247
247
 
248
+ @client_state = RUNNING # reset state to running if we were paused or closed
249
+
248
250
  timeout ||= @connection_timeout # or @connection_timeout here is the docuemnted behavior on Base#reopen
249
251
 
250
252
  @cnx.reopen(timeout) # ok, we werent' forked, so just reopen
@@ -17,14 +17,6 @@ module ZK
17
17
  # @private
18
18
  ALL_STATE_EVENTS_KEY = :all_state_events
19
19
 
20
- # @private
21
- ZOOKEEPER_WATCH_TYPE_MAP = {
22
- Zookeeper::ZOO_CREATED_EVENT => :data,
23
- Zookeeper::ZOO_DELETED_EVENT => :data,
24
- Zookeeper::ZOO_CHANGED_EVENT => :data,
25
- Zookeeper::ZOO_CHILD_EVENT => :child,
26
- }.freeze
27
-
28
20
  # @private
29
21
  VALID_THREAD_OPTS = [:single, :per_callback].freeze
30
22
 
@@ -157,10 +149,10 @@ module ZK
157
149
  # and session events go through here, NOT anything else!!
158
150
  #
159
151
  # @private
160
- def process(event)
152
+ def process(event, watch_type = nil)
161
153
  @zk.raw_event_handler(event)
162
154
 
163
- logger.debug { "EventHandler#process dispatching event: #{event.inspect}" }# unless event.type == -1
155
+ logger.debug { "EventHandler#process dispatching event for #{watch_type.inspect}: #{event.inspect}" }# unless event.type == -1
164
156
  event.zk = @zk
165
157
 
166
158
  cb_keys =
@@ -173,7 +165,7 @@ module ZK
173
165
  end
174
166
 
175
167
  cb_ary = synchronize do
176
- clear_watch_restrictions(event)
168
+ clear_watch_restrictions(event, watch_type)
177
169
 
178
170
  @callbacks.values_at(*cb_keys)
179
171
  end
@@ -193,11 +185,11 @@ module ZK
193
185
  # happens inside the lock, clears the restriction on setting new watches
194
186
  # for a given path/event type combination
195
187
  #
196
- def clear_watch_restrictions(event)
188
+ def clear_watch_restrictions(event, watch_type)
197
189
  return unless event.node_event?
198
190
 
199
- if watch_type = ZOOKEEPER_WATCH_TYPE_MAP[event.type]
200
- #logger.debug { "re-allowing #{watch_type.inspect} watches on path #{event.path.inspect}" }
191
+ if watch_type
192
+ logger.debug { "re-allowing #{watch_type.inspect} watches on path #{event.path.inspect}" }
201
193
 
202
194
  # we recieved a watch event for this path, now we allow code to set new watchers
203
195
  @outstanding_watches[watch_type].delete(event.path)
@@ -286,11 +278,13 @@ module ZK
286
278
  path = opts[:path]
287
279
 
288
280
  if set.add?(path)
281
+ logger.debug { "adding watcher #{watch_type.inspect} for #{path.inspect}"}
282
+
289
283
  # if we added the path to the set, blocking further registration of
290
284
  # watches and an exception is raised then we rollback
291
285
  begin
292
286
  # this path has no outstanding watchers, let it do its thing
293
- opts[:watcher] = watcher_callback
287
+ opts[:watcher] = watcher_callback(watch_type)
294
288
 
295
289
  yield opts
296
290
  rescue Exception
@@ -298,6 +292,8 @@ module ZK
298
292
  raise
299
293
  end
300
294
  else
295
+ logger.debug { "watcher #{watch_type.inspect} already set for #{path.inspect}"}
296
+
301
297
  # we did not add the path to the set, which means we are not
302
298
  # responsible for removing a block on further adds if the operation
303
299
  # fails, therefore, we just yield
@@ -311,8 +307,8 @@ module ZK
311
307
  @mutex.synchronize { yield }
312
308
  end
313
309
 
314
- def watcher_callback
315
- Zookeeper::Callbacks::WatcherCallback.create { |event| process(event) }
310
+ def watcher_callback(watch_type = nil)
311
+ Zookeeper::Callbacks::WatcherCallback.create { |event| process(event, watch_type) }
316
312
  end
317
313
 
318
314
  def state_key(arg)
@@ -47,7 +47,7 @@ module ZK
47
47
  message_title = "message"
48
48
  end
49
49
  @zk.create("#{full_queue_path}/#{message_title}", data, :mode => mode)
50
- rescue KeeperException::NodeExists
50
+ rescue ZK::Exceptions::NodeExists
51
51
  return false
52
52
  end
53
53
 
@@ -1,3 +1,3 @@
1
1
  module ZK
2
- VERSION = "1.9.0"
2
+ VERSION = "1.9.1"
3
3
  end
@@ -36,11 +36,35 @@ describe ZK::Client::Threaded do
36
36
 
37
37
  shutdown_thread.join(5).should == shutdown_thread
38
38
 
39
- wait_until(5) { @zk.closed? }.should be_true
39
+ wait_until(5) { @zk.closed? }.should be_true
40
40
  end
41
41
  end
42
42
  end
43
43
 
44
+ describe :reopen do
45
+ include_context 'connection opts'
46
+
47
+ before do
48
+ @zk = ZK::Client::Threaded.new(*connection_args)
49
+ end
50
+
51
+ after do
52
+ @zk.close! unless @zk.closed?
53
+ end
54
+
55
+ it %[should say the client is connected after reopen] do
56
+ @zk.connected?.should == true
57
+
58
+ @zk.close!
59
+
60
+ @zk.connected?.should == false
61
+
62
+ @zk.reopen
63
+
64
+ @zk.connected?.should == true
65
+ end
66
+ end
67
+
44
68
  describe :retry do
45
69
  include_context 'connection opts'
46
70
 
@@ -54,8 +78,8 @@ describe ZK::Client::Threaded do
54
78
 
55
79
  it %[should retry a Retryable operation] do
56
80
  # TODO: this is a terrible test. there is no way to guarantee that this
57
- # has been retried. the join at the end should not raise an error
58
-
81
+ # has been retried. the join at the end should not raise an error
82
+
59
83
  @zk.should_not be_connected
60
84
 
61
85
  th = Thread.new do
@@ -156,6 +156,52 @@ describe ZK do
156
156
  events.should_not be_empty
157
157
  end
158
158
 
159
+ it %[should call a child listener when the node is deleted] do
160
+ events = []
161
+
162
+ sub = @zk.register(@path) do |ev|
163
+ logger.debug { "got event #{ev}" }
164
+ events << ev
165
+ end
166
+
167
+ @zk.create(@path, '')
168
+
169
+ # Watch for children
170
+ @zk.children(@path, :watch => true)
171
+
172
+ # Delete the node
173
+ @zk.delete(@path)
174
+
175
+ # We expect to see a delete event show up
176
+ wait_while(5) { events.empty? }
177
+
178
+ event = events.pop
179
+
180
+ event.should_not be_nil
181
+
182
+ event.path.should == @path
183
+ event.type.should == Zookeeper::ZOO_DELETED_EVENT
184
+
185
+ # Create the node again
186
+ @zk.create(@path, '')
187
+
188
+ # Watch for children again
189
+ @zk.children(@path, :watch => true)
190
+
191
+ # Delete the node again
192
+ @zk.delete(@path)
193
+
194
+ # We expect to see another delete event show up
195
+ wait_while(5) { events.empty? }
196
+
197
+ event = events.pop
198
+
199
+ event.should_not be_nil
200
+
201
+ event.path.should == @path
202
+ event.type.should == Zookeeper::ZOO_DELETED_EVENT
203
+ end
204
+
159
205
  describe ':all' do
160
206
  before do
161
207
  mute_logger do
metadata CHANGED
@@ -1,67 +1,58 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: zk
3
- version: !ruby/object:Gem::Version
4
- hash: 51
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.9.1
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 9
9
- - 0
10
- version: 1.9.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Jonathan D. Simms
14
9
  - Topper Bowers
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2013-08-07 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2013-09-09 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: zookeeper
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
19
+ requirements:
27
20
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 1
32
- - 4
33
- - 0
21
+ - !ruby/object:Gem::Version
34
22
  version: 1.4.0
35
23
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: logging
39
24
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: !ruby/object:Gem::Requirement
41
26
  none: false
42
- requirements:
27
+ requirements:
43
28
  - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 15
46
- segments:
47
- - 1
48
- - 7
49
- - 2
29
+ - !ruby/object:Gem::Version
30
+ version: 1.4.0
31
+ - !ruby/object:Gem::Dependency
32
+ name: logging
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
50
38
  version: 1.7.2
51
39
  type: :runtime
52
- version_requirements: *id002
53
- description: |
54
- A high-level wrapper around the zookeeper driver
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 1.7.2
47
+ description: ! 'A high-level wrapper around the zookeeper driver
55
48
 
56
- email:
49
+ '
50
+ email:
57
51
  - slyphon@gmail.com
58
52
  executables: []
59
-
60
53
  extensions: []
61
-
62
54
  extra_rdoc_files: []
63
-
64
- files:
55
+ files:
65
56
  - .dotfiles/ctags_paths
66
57
  - .dotfiles/rspec-logging
67
58
  - .dotfiles/ruby-gemset
@@ -164,38 +155,35 @@ files:
164
155
  - zk.gemspec
165
156
  homepage: https://github.com/slyphon/zk
166
157
  licenses: []
167
-
168
158
  post_install_message:
169
159
  rdoc_options: []
170
-
171
- require_paths:
160
+ require_paths:
172
161
  - lib
173
- required_ruby_version: !ruby/object:Gem::Requirement
162
+ required_ruby_version: !ruby/object:Gem::Requirement
174
163
  none: false
175
- requirements:
176
- - - ">="
177
- - !ruby/object:Gem::Version
178
- hash: 3
179
- segments:
164
+ requirements:
165
+ - - ! '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ segments:
180
169
  - 0
181
- version: "0"
182
- required_rubygems_version: !ruby/object:Gem::Requirement
170
+ hash: 1065717701995457844
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
172
  none: false
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- hash: 3
188
- segments:
173
+ requirements:
174
+ - - ! '>='
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ segments:
189
178
  - 0
190
- version: "0"
179
+ hash: 1065717701995457844
191
180
  requirements: []
192
-
193
181
  rubyforge_project:
194
182
  rubygems_version: 1.8.25
195
183
  signing_key:
196
184
  specification_version: 3
197
185
  summary: A high-level wrapper around the zookeeper driver
198
- test_files:
186
+ test_files:
199
187
  - spec/event_catcher_spec.rb
200
188
  - spec/informal/close-in-event-thread.rb
201
189
  - spec/informal/lock_with_dead_session.rb
@@ -240,3 +228,4 @@ test_files:
240
228
  - spec/zk/threadpool_spec.rb
241
229
  - spec/zk/watch_spec.rb
242
230
  - spec/zk/zookeeper_spec.rb
231
+ has_rdoc: