zk_recipes 0.2.1 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/zk_recipes/cache.rb +18 -11
- data/lib/zk_recipes/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fa28d0852ec9e71d6f8a38daaf6c77626e11b7d
|
4
|
+
data.tar.gz: c2222216513454ecf137f88c266345327085551f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90599a5eb832a705ce159dcc88c1d1ca8bed88b9b282e3996b049d65a50acd3d0f6f77463a956899b19ac6deca389ab07a790c7ecf0e79b0d0adeda89a724b83
|
7
|
+
data.tar.gz: 247ca67c9cee03ab06da4e117908947ab7fc85dc598a930341b3d877534653b3a16c6bf901a266a73e32bdc3339fec42b7d3f40ce0a024155e4e4cf4e8898e3b
|
data/CHANGELOG.md
CHANGED
data/lib/zk_recipes/cache.rb
CHANGED
@@ -55,13 +55,13 @@ module ZkRecipes
|
|
55
55
|
@registered_values.each do |path, _value|
|
56
56
|
@watches[path] = @zk.register(path) do |event|
|
57
57
|
if event.node_event?
|
58
|
-
debug
|
58
|
+
debug { "node event path=#{event.path} #{event.event_name} #{event.state_name}" }
|
59
59
|
unless update_cache(event.path)
|
60
60
|
@pending_updates[path] = nil
|
61
61
|
@zk.defer { process_pending_updates }
|
62
62
|
end
|
63
63
|
else
|
64
|
-
warn
|
64
|
+
warn { "session event #{event.event_name} #{event.state_name}" }
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
@@ -82,16 +82,16 @@ module ZkRecipes
|
|
82
82
|
end
|
83
83
|
|
84
84
|
@zk.on_exception do |e|
|
85
|
-
error
|
85
|
+
error { "on_exception exception=#{e.inspect} backtrace=#{e.backtrace.inspect}" }
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
89
|
def wait_for_warm_cache(timeout = 30)
|
90
|
-
debug
|
90
|
+
debug { "waiting for cache to warm timeout=#{timeout.inspect}" }
|
91
91
|
if @latch.wait(timeout)
|
92
92
|
true
|
93
93
|
else
|
94
|
-
warn
|
94
|
+
warn { "didn't warm cache before timeout connected=#{@zk.connected?} timeout=#{timeout.inspect}" }
|
95
95
|
false
|
96
96
|
end
|
97
97
|
end
|
@@ -135,7 +135,7 @@ module ZkRecipes
|
|
135
135
|
def connect(host, zk_opts)
|
136
136
|
raise Error, "already connected" if @zk
|
137
137
|
|
138
|
-
debug
|
138
|
+
debug { "connecting host=#{host.inspect}" }
|
139
139
|
ZK.new(host, **zk_opts) do |zk|
|
140
140
|
setup_callbacks(zk)
|
141
141
|
end
|
@@ -150,7 +150,7 @@ module ZkRecipes
|
|
150
150
|
unless stat.exists?
|
151
151
|
value = @registered_values.fetch(path).default_value
|
152
152
|
@cache[path] = CachedPath.new(value, stat: stat)
|
153
|
-
debug
|
153
|
+
debug { "no node, setting watch path=#{path}" }
|
154
154
|
instrument_params[:value] = value
|
155
155
|
ActiveSupport::Notifications.instrument(AS_NOTIFICATION, instrument_params)
|
156
156
|
return true
|
@@ -167,29 +167,34 @@ module ZkRecipes
|
|
167
167
|
registered_value = @registered_values.fetch(path)
|
168
168
|
instrument_params[:value] = registered_value.deserialize(raw_value)
|
169
169
|
rescue => e
|
170
|
-
error
|
170
|
+
error { "deserialization error path=#{path} stat=#{stat.inspect} exception=#{e.inspect} #{e.backtrace.inspect}" }
|
171
171
|
instrument_params[:error] = e
|
172
172
|
instrument_params[:raw_value] = raw_value
|
173
173
|
valid = false
|
174
174
|
registered_value.default_value
|
175
175
|
end
|
176
176
|
|
177
|
+
if value == USE_DEFAULT
|
178
|
+
valid = false
|
179
|
+
value = registered_value.default_value
|
180
|
+
end
|
181
|
+
|
177
182
|
@cache[path] = CachedPath.new(value, stat: stat, valid: valid)
|
178
183
|
|
179
184
|
ActiveSupport::Notifications.instrument(AS_NOTIFICATION, instrument_params)
|
180
185
|
debug { "update_cache path=#{path} raw_value=#{raw_value.inspect} value=#{value.inspect} stat=#{stat.inspect}" }
|
181
186
|
true
|
182
187
|
rescue ::ZK::Exceptions::ZKError => e
|
183
|
-
warn
|
188
|
+
warn { "update_cache path=#{path} exception=#{e.inspect}, retrying" }
|
184
189
|
retry
|
185
190
|
rescue ::ZK::Exceptions::KeeperException, ::Zookeeper::Exceptions::ZookeeperException => e
|
186
|
-
error
|
191
|
+
error { "update_cache path=#{path} exception=#{e.inspect}" }
|
187
192
|
false
|
188
193
|
end
|
189
194
|
|
190
195
|
def process_pending_updates
|
191
196
|
return if @pending_updates.empty?
|
192
|
-
debug
|
197
|
+
debug { "processing pending updates=#{@pending_updates.size}" }
|
193
198
|
@pending_updates.reject! do |missed_path, _|
|
194
199
|
update_cache(missed_path)
|
195
200
|
end
|
@@ -204,6 +209,8 @@ module ZkRecipes
|
|
204
209
|
EOM
|
205
210
|
end
|
206
211
|
|
212
|
+
USE_DEFAULT = Object.new
|
213
|
+
|
207
214
|
class CachedPath
|
208
215
|
attr_reader :value, :stat
|
209
216
|
def initialize(value, stat: nil, valid: false)
|
data/lib/zk_recipes/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zk_recipes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Lazarus
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.6.
|
96
|
+
rubygems_version: 2.6.13
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: Common Recipes for Zookeeper
|