zk_recipes 0.2.0.pre1 → 0.2.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -1
- data/lib/zk_recipes/cache.rb +10 -20
- data/lib/zk_recipes/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b8809248fbdaf59b179335291fb0dbd4c720a5d
|
4
|
+
data.tar.gz: 94272b92ac88c8f58370d3d6e9f4a8d8ce2df2c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efb4cd174c22e51ea51258de0e25a3b34b97ac9ae1e779798f38023bd326fdd314571c95e7b3bbd0caaede333d2e77018c9f8be1f4b16dd3d678d6fc50501707
|
7
|
+
data.tar.gz: ada75f39f7481da1daa5fed9dcd5b9e2de7615befc8c59045e11893bb7bc690097452f5ae5b788a65ce87789a25690888764d07cfa8df6c71ed42bdf98001dfb
|
data/CHANGELOG.md
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
## 0.2.0
|
4
4
|
|
5
|
-
BREAKING CHANGES
|
5
|
+
This version includes BREAKING CHANGES. See below
|
6
6
|
|
7
|
+
- cleanup logging
|
7
8
|
- Make `on_connected` lighter: `on_connected` gets called for every watch when
|
8
9
|
a connection flaps. Make the happy path `on_connected` faster.
|
9
10
|
- Add `ZkRecipes::Cache#reopen` for resetting the cache after a `fork`
|
data/lib/zk_recipes/cache.rb
CHANGED
@@ -37,7 +37,7 @@ module ZkRecipes
|
|
37
37
|
def register(path, default_value, &block)
|
38
38
|
raise Error, "register only allowed before setup_callbacks called" unless @registerable
|
39
39
|
|
40
|
-
debug
|
40
|
+
debug { "added path=#{path} default_value=#{default_value.inspect}" }
|
41
41
|
@cache[path] = CachedPath.new(default_value)
|
42
42
|
@registered_values[path] = RegisteredPath.new(default_value, block)
|
43
43
|
ActiveSupport::Notifications.instrument(AS_NOTIFICATION, path: path, value: default_value)
|
@@ -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("node event=#{event.
|
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("session event
|
64
|
+
warn("session event #{event.event_name} #{event.state_name}")
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
@@ -87,11 +87,11 @@ module ZkRecipes
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def wait_for_warm_cache(timeout = 30)
|
90
|
-
debug("waiting for cache to warm timeout=#{timeout}")
|
90
|
+
debug("waiting for cache to warm timeout=#{timeout.inspect}")
|
91
91
|
if @latch.wait(timeout)
|
92
92
|
true
|
93
93
|
else
|
94
|
-
warn("didn't warm cache before timeout connected=#{@zk.connected?} timeout=#{timeout}")
|
94
|
+
warn("didn't warm cache before timeout connected=#{@zk.connected?} timeout=#{timeout.inspect}")
|
95
95
|
false
|
96
96
|
end
|
97
97
|
end
|
@@ -143,8 +143,6 @@ module ZkRecipes
|
|
143
143
|
|
144
144
|
# only called from ZK thread
|
145
145
|
def update_cache(path)
|
146
|
-
debug("update_cache path=#{path}")
|
147
|
-
|
148
146
|
stat = @zk.stat(path, watch: true)
|
149
147
|
|
150
148
|
instrument_params = { path: path }
|
@@ -168,10 +166,7 @@ module ZkRecipes
|
|
168
166
|
registered_value = @registered_values.fetch(path)
|
169
167
|
instrument_params[:value] = registered_value.deserialize(raw_value)
|
170
168
|
rescue => e
|
171
|
-
error(
|
172
|
-
"deserialization error raw_zookeeper_value=#{raw_value.inspect} zookeeper_stat=#{stat.inspect} "\
|
173
|
-
"exception=#{e.inspect} #{e.backtrace.inspect}"
|
174
|
-
)
|
169
|
+
error("deserialization error path=#{path} stat=#{stat.inspect} exception=#{e.inspect} #{e.backtrace.inspect}")
|
175
170
|
instrument_params[:error] = e
|
176
171
|
instrument_params[:raw_value] = raw_value
|
177
172
|
registered_value.default_value
|
@@ -180,11 +175,8 @@ module ZkRecipes
|
|
180
175
|
# TODO if there is a deserialization error, do we want to indicate that on the CachedPath?
|
181
176
|
@cache[path] = CachedPath.new(value, stat)
|
182
177
|
|
183
|
-
debug(
|
184
|
-
"updated cache path=#{path} raw_value=#{raw_value.inspect} "\
|
185
|
-
"value=#{value.inspect} stat=#{stat.inspect}"
|
186
|
-
)
|
187
178
|
ActiveSupport::Notifications.instrument(AS_NOTIFICATION, instrument_params)
|
179
|
+
debug { "update_cache path=#{path} raw_value=#{raw_value.inspect} value=#{value.inspect} stat=#{stat.inspect}" }
|
188
180
|
true
|
189
181
|
rescue ::ZK::Exceptions::ZKError => e
|
190
182
|
warn("update_cache path=#{path} exception=#{e.inspect}, retrying")
|
@@ -196,19 +188,17 @@ module ZkRecipes
|
|
196
188
|
|
197
189
|
def process_pending_updates
|
198
190
|
return if @pending_updates.empty?
|
199
|
-
|
191
|
+
debug("processing pending updates=#{@pending_updates.size}")
|
200
192
|
@pending_updates.reject! do |missed_path, _|
|
201
|
-
debug("update_cache with previously missed update path=#{missed_path}")
|
202
193
|
update_cache(missed_path)
|
203
194
|
end
|
204
|
-
info("pending updates not processed=#{@pending_updates.size}")
|
205
195
|
end
|
206
196
|
|
207
197
|
%w(debug info warn error).each do |m|
|
208
198
|
module_eval <<~EOM, __FILE__, __LINE__
|
209
|
-
def #{m}(msg)
|
199
|
+
def #{m}(msg = nil)
|
210
200
|
return unless @logger
|
211
|
-
@logger.#{m}("ZkRecipes::Cache") { msg }
|
201
|
+
@logger.#{m}("ZkRecipes::Cache") { msg || yield }
|
212
202
|
end
|
213
203
|
EOM
|
214
204
|
end
|
data/lib/zk_recipes/version.rb
CHANGED