redis_queued_locks 1.8.0 → 1.9.0
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/.ruby-version +1 -1
- data/CHANGELOG.md +51 -0
- data/README.md +402 -46
- data/lib/redis_queued_locks/acquier/acquire_lock/dequeue_from_lock_queue/log_visitor.rb +4 -0
- data/lib/redis_queued_locks/acquier/acquire_lock/dequeue_from_lock_queue.rb +4 -1
- data/lib/redis_queued_locks/acquier/acquire_lock/instr_visitor.rb +20 -5
- data/lib/redis_queued_locks/acquier/acquire_lock/log_visitor.rb +24 -0
- data/lib/redis_queued_locks/acquier/acquire_lock/try_to_lock/log_visitor.rb +56 -0
- data/lib/redis_queued_locks/acquier/acquire_lock/try_to_lock.rb +37 -30
- data/lib/redis_queued_locks/acquier/acquire_lock/yield_expire/log_visitor.rb +8 -0
- data/lib/redis_queued_locks/acquier/acquire_lock/yield_expire.rb +13 -9
- data/lib/redis_queued_locks/acquier/acquire_lock.rb +44 -20
- data/lib/redis_queued_locks/acquier/clear_dead_requests.rb +5 -1
- data/lib/redis_queued_locks/acquier/extend_lock_ttl.rb +5 -1
- data/lib/redis_queued_locks/acquier/lock_info.rb +4 -3
- data/lib/redis_queued_locks/acquier/locks.rb +2 -2
- data/lib/redis_queued_locks/acquier/queue_info.rb +2 -2
- data/lib/redis_queued_locks/acquier/release_all_locks.rb +12 -2
- data/lib/redis_queued_locks/acquier/release_lock.rb +12 -2
- data/lib/redis_queued_locks/client.rb +284 -34
- data/lib/redis_queued_locks/errors.rb +8 -0
- data/lib/redis_queued_locks/instrument.rb +8 -1
- data/lib/redis_queued_locks/logging.rb +8 -1
- data/lib/redis_queued_locks/resource.rb +59 -1
- data/lib/redis_queued_locks/swarm/acquirers.rb +44 -0
- data/lib/redis_queued_locks/swarm/flush_zombies.rb +133 -0
- data/lib/redis_queued_locks/swarm/probe_hosts.rb +69 -0
- data/lib/redis_queued_locks/swarm/redis_client_builder.rb +67 -0
- data/lib/redis_queued_locks/swarm/supervisor.rb +83 -0
- data/lib/redis_queued_locks/swarm/swarm_element/isolated.rb +287 -0
- data/lib/redis_queued_locks/swarm/swarm_element/threaded.rb +351 -0
- data/lib/redis_queued_locks/swarm/swarm_element.rb +8 -0
- data/lib/redis_queued_locks/swarm/zombie_info.rb +145 -0
- data/lib/redis_queued_locks/swarm.rb +241 -0
- data/lib/redis_queued_locks/utilities/lock.rb +22 -0
- data/lib/redis_queued_locks/utilities.rb +75 -0
- data/lib/redis_queued_locks/version.rb +2 -2
- data/lib/redis_queued_locks.rb +2 -0
- metadata +14 -4
- data/lib/redis_queued_locks/watcher.rb +0 -1
@@ -19,6 +19,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::YieldExpire
|
|
19
19
|
# @param logger [::Logger,#debug] Logger object.
|
20
20
|
# @param lock_key [String] Obtained lock key that should be expired.
|
21
21
|
# @param acquier_id [String] Acquier identifier.
|
22
|
+
# @param host_id [String] Host identifier.
|
22
23
|
# @param access_strategy [Symbol] Lock obtaining strategy.
|
23
24
|
# @param timed [Boolean] Should the lock be wrapped by Timeout with with lock's ttl
|
24
25
|
# @param ttl_shift [Float] Lock's TTL shifting. Should affect block's ttl. In millisecodns.
|
@@ -36,13 +37,14 @@ module RedisQueuedLocks::Acquier::AcquireLock::YieldExpire
|
|
36
37
|
#
|
37
38
|
# @api private
|
38
39
|
# @since 1.3.0
|
39
|
-
# @version 1.
|
40
|
+
# @version 1.9.0
|
40
41
|
# rubocop:disable Metrics/MethodLength
|
41
42
|
def yield_expire(
|
42
43
|
redis,
|
43
44
|
logger,
|
44
45
|
lock_key,
|
45
46
|
acquier_id,
|
47
|
+
host_id,
|
46
48
|
access_strategy,
|
47
49
|
timed,
|
48
50
|
ttl_shift,
|
@@ -64,7 +66,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::YieldExpire
|
|
64
66
|
end
|
65
67
|
|
66
68
|
if timed && ttl != nil
|
67
|
-
yield_with_timeout(timeout, lock_key, ttl, acquier_id, meta, &block)
|
69
|
+
yield_with_timeout(timeout, lock_key, ttl, acquier_id, host_id, meta, &block)
|
68
70
|
else
|
69
71
|
yield
|
70
72
|
end
|
@@ -72,8 +74,8 @@ module RedisQueuedLocks::Acquier::AcquireLock::YieldExpire
|
|
72
74
|
ensure
|
73
75
|
if should_expire
|
74
76
|
LogVisitor.expire_lock(
|
75
|
-
logger, log_sampled,
|
76
|
-
|
77
|
+
logger, log_sampled, lock_key,
|
78
|
+
queue_ttl, acquier_id, host_id, access_strategy
|
77
79
|
)
|
78
80
|
redis.call('EXPIRE', lock_key, '0')
|
79
81
|
elsif should_decrease
|
@@ -83,8 +85,8 @@ module RedisQueuedLocks::Acquier::AcquireLock::YieldExpire
|
|
83
85
|
|
84
86
|
if decreased_ttl > 0
|
85
87
|
LogVisitor.decrease_lock(
|
86
|
-
logger, log_sampled,
|
87
|
-
|
88
|
+
logger, log_sampled, lock_key,
|
89
|
+
decreased_ttl, queue_ttl, acquier_id, host_id, access_strategy
|
88
90
|
)
|
89
91
|
# NOTE:# NOTE: EVAL signature -> <lua script>, (number of keys), *(keys), *(arguments)
|
90
92
|
redis.call('EVAL', DECREASE_LOCK_PTTL, 1, lock_key, decreased_ttl)
|
@@ -100,14 +102,15 @@ module RedisQueuedLocks::Acquier::AcquireLock::YieldExpire
|
|
100
102
|
# @parma lock_key [String]
|
101
103
|
# @param lock_ttl [Integer,NilClass]
|
102
104
|
# @param acquier_id [String]
|
105
|
+
# @param host_id [String]
|
103
106
|
# @param meta [NilClass,Hash<Symbol|String,Any>]
|
104
107
|
# @param block [Blcok]
|
105
108
|
# @return [Any]
|
106
109
|
#
|
107
110
|
# @api private
|
108
111
|
# @since 1.3.0
|
109
|
-
# @version 1.
|
110
|
-
def yield_with_timeout(timeout, lock_key, lock_ttl, acquier_id, meta, &block)
|
112
|
+
# @version 1.9.0
|
113
|
+
def yield_with_timeout(timeout, lock_key, lock_ttl, acquier_id, host_id, meta, &block)
|
111
114
|
::Timeout.timeout(timeout, &block)
|
112
115
|
rescue ::Timeout::Error
|
113
116
|
raise(
|
@@ -116,7 +119,8 @@ module RedisQueuedLocks::Acquier::AcquireLock::YieldExpire
|
|
116
119
|
"(lock: \"#{lock_key}\", " \
|
117
120
|
"ttl: #{lock_ttl}, " \
|
118
121
|
"meta: #{meta ? meta.inspect : '<no-meta>'}, " \
|
119
|
-
"acq_id: \"#{acquier_id}\"
|
122
|
+
"acq_id: \"#{acquier_id}\", " \
|
123
|
+
"hst_id: \"#{host_id}\")"
|
120
124
|
)
|
121
125
|
end
|
122
126
|
end
|
@@ -121,6 +121,9 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
121
121
|
# - you can provide your own log sampler with bettter algorithm that should realize
|
122
122
|
# `sampling_happened?(percent) => boolean` interface
|
123
123
|
# (see `RedisQueuedLocks::Logging::Sampler` for example);
|
124
|
+
# @option log_sample_this [Boolean]
|
125
|
+
# - marks the method that everything should be logged despite the enabled log sampling;
|
126
|
+
# - makes sense when log sampling is enabled;
|
124
127
|
# @option instr_sampling_enabled [Boolean]
|
125
128
|
# - enables <instrumentaion sampling>: only the configured percent
|
126
129
|
# of RQL cases will be instrumented;
|
@@ -139,6 +142,10 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
139
142
|
# - you can provide your own log sampler with bettter algorithm that should realize
|
140
143
|
# `sampling_happened?(percent) => boolean` interface
|
141
144
|
# (see `RedisQueuedLocks::Instrument::Sampler` for example);
|
145
|
+
# @option instr_sample_this [Boolean]
|
146
|
+
# - marks the method that everything should be instrumneted
|
147
|
+
# despite the enabled instrumentation sampling;
|
148
|
+
# - makes sense when instrumentation sampling is enabled;
|
142
149
|
# @param [Block]
|
143
150
|
# A block of code that should be executed after the successfully acquired lock.
|
144
151
|
# @return [RedisQueuedLocks::Data,Hash<Symbol,Any>,yield]
|
@@ -147,7 +154,7 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
147
154
|
#
|
148
155
|
# @api private
|
149
156
|
# @since 1.0.0
|
150
|
-
# @version 1.
|
157
|
+
# @version 1.9.0
|
151
158
|
def acquire_lock(
|
152
159
|
redis,
|
153
160
|
lock_name,
|
@@ -176,9 +183,11 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
176
183
|
log_sampling_enabled:,
|
177
184
|
log_sampling_percent:,
|
178
185
|
log_sampler:,
|
186
|
+
log_sample_this:,
|
179
187
|
instr_sampling_enabled:,
|
180
188
|
instr_sampling_percent:,
|
181
189
|
instr_sampler:,
|
190
|
+
instr_sample_this:,
|
182
191
|
&block
|
183
192
|
)
|
184
193
|
# Step 0: Prevent argument type incompatabilities
|
@@ -195,6 +204,7 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
195
204
|
# Step 0.2: prevent :meta incompatabiltiies (structure)
|
196
205
|
if meta.is_a?(::Hash) && (meta.any? do |key, _value|
|
197
206
|
key == 'acq_id' ||
|
207
|
+
key == 'hst_id' ||
|
198
208
|
key == 'ts' ||
|
199
209
|
key == 'ini_ttl' ||
|
200
210
|
key == 'lock_key' ||
|
@@ -208,7 +218,7 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
208
218
|
raise(
|
209
219
|
RedisQueuedLocks::ArgumentError,
|
210
220
|
'`:meta` keys can not overlap reserved lock data keys ' \
|
211
|
-
'"acq_id", "ts", "ini_ttl", "lock_key", "rem_ttl", "spc_cnt", ' \
|
221
|
+
'"acq_id", "hst_id", "ts", "ini_ttl", "lock_key", "rem_ttl", "spc_cnt", ' \
|
212
222
|
'"spc_ext_ttl", "l_spc_ext_ini_ttl", "l_spc_ext_ts", "l_spc_ts"'
|
213
223
|
)
|
214
224
|
end
|
@@ -221,6 +231,12 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
221
231
|
ractor_id,
|
222
232
|
identity
|
223
233
|
)
|
234
|
+
host_id = RedisQueuedLocks::Resource.host_identifier(
|
235
|
+
process_id,
|
236
|
+
thread_id,
|
237
|
+
ractor_id,
|
238
|
+
identity
|
239
|
+
)
|
224
240
|
lock_ttl = ttl
|
225
241
|
lock_key = RedisQueuedLocks::Resource.prepare_lock_key(lock_name)
|
226
242
|
lock_key_queue = RedisQueuedLocks::Resource.prepare_lock_queue(lock_name)
|
@@ -228,11 +244,13 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
228
244
|
|
229
245
|
log_sampled = RedisQueuedLocks::Logging.should_log?(
|
230
246
|
log_sampling_enabled,
|
247
|
+
log_sample_this,
|
231
248
|
log_sampling_percent,
|
232
249
|
log_sampler
|
233
250
|
)
|
234
251
|
instr_sampled = RedisQueuedLocks::Instrument.should_instrument?(
|
235
252
|
instr_sampling_enabled,
|
253
|
+
instr_sample_this,
|
236
254
|
instr_sampling_percent,
|
237
255
|
instr_sampler
|
238
256
|
)
|
@@ -257,6 +275,7 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
257
275
|
lock_key_queue,
|
258
276
|
queue_ttl,
|
259
277
|
acquier_id,
|
278
|
+
host_id,
|
260
279
|
access_strategy,
|
261
280
|
log_sampled,
|
262
281
|
instr_sampled
|
@@ -264,8 +283,8 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
264
283
|
end
|
265
284
|
|
266
285
|
LogVisitor.start_lock_obtaining(
|
267
|
-
logger, log_sampled,
|
268
|
-
|
286
|
+
logger, log_sampled, lock_key,
|
287
|
+
queue_ttl, acquier_id, host_id, access_strategy
|
269
288
|
)
|
270
289
|
|
271
290
|
# Step 2: try to lock with timeout
|
@@ -284,8 +303,8 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
284
303
|
while acq_process[:should_try]
|
285
304
|
|
286
305
|
LogVisitor.start_try_to_lock_cycle(
|
287
|
-
logger, log_sampled,
|
288
|
-
|
306
|
+
logger, log_sampled, lock_key,
|
307
|
+
queue_ttl, acquier_id, host_id, access_strategy
|
289
308
|
)
|
290
309
|
|
291
310
|
# Step 2.X: check the actual score: is it in queue ttl limit or not?
|
@@ -294,8 +313,8 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
294
313
|
acquier_position = RedisQueuedLocks::Resource.calc_initial_acquier_position
|
295
314
|
|
296
315
|
LogVisitor.dead_score_reached__reset_acquier_position(
|
297
|
-
logger, log_sampled,
|
298
|
-
|
316
|
+
logger, log_sampled, lock_key,
|
317
|
+
queue_ttl, acquier_id, host_id, access_strategy
|
299
318
|
)
|
300
319
|
end
|
301
320
|
|
@@ -306,6 +325,7 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
306
325
|
lock_key,
|
307
326
|
lock_key_queue,
|
308
327
|
acquier_id,
|
328
|
+
host_id,
|
309
329
|
acquier_position,
|
310
330
|
lock_ttl,
|
311
331
|
queue_ttl,
|
@@ -330,35 +350,35 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
330
350
|
if acq_process[:result][:process] == :extendable_conflict_work_through
|
331
351
|
# instrumetnation: (reentrant lock with ttl extension)
|
332
352
|
LogVisitor.extendable_reentrant_lock_obtained(
|
333
|
-
logger, log_sampled,
|
334
|
-
|
353
|
+
logger, log_sampled, result[:lock_key],
|
354
|
+
queue_ttl, acquier_id, host_id, acq_time, access_strategy
|
335
355
|
)
|
336
356
|
InstrVisitor.extendable_reentrant_lock_obtained(
|
337
|
-
instrumenter, instr_sampled,
|
338
|
-
result[:
|
357
|
+
instrumenter, instr_sampled, result[:lock_key],
|
358
|
+
result[:ttl], result[:acq_id], result[:hst_id], result[:ts], acq_time,
|
339
359
|
instrument
|
340
360
|
)
|
341
361
|
elsif acq_process[:result][:process] == :conflict_work_through
|
342
362
|
# instrumetnation: (reentrant lock without ttl extension)
|
343
363
|
LogVisitor.reentrant_lock_obtained(
|
344
|
-
logger, log_sampled,
|
345
|
-
|
364
|
+
logger, log_sampled, result[:lock_key],
|
365
|
+
queue_ttl, acquier_id, host_id, acq_time, access_strategy
|
346
366
|
)
|
347
367
|
InstrVisitor.reentrant_lock_obtained(
|
348
|
-
instrumenter, instr_sampled,
|
349
|
-
result[:
|
368
|
+
instrumenter, instr_sampled, result[:lock_key],
|
369
|
+
result[:ttl], result[:acq_id], result[:hst_id], result[:ts], acq_time,
|
350
370
|
instrument
|
351
371
|
)
|
352
372
|
else
|
353
373
|
# instrumentation: (classic lock obtain)
|
354
374
|
# NOTE: classic is: acq_process[:result][:process] == :lock_obtaining
|
355
375
|
LogVisitor.lock_obtained(
|
356
|
-
logger, log_sampled,
|
357
|
-
|
376
|
+
logger, log_sampled, result[:lock_key],
|
377
|
+
queue_ttl, acquier_id, host_id, acq_time, access_strategy
|
358
378
|
)
|
359
379
|
InstrVisitor.lock_obtained(
|
360
|
-
instrumenter, instr_sampled,
|
361
|
-
result[:
|
380
|
+
instrumenter, instr_sampled, result[:lock_key],
|
381
|
+
result[:ttl], result[:acq_id], result[:hst_id], result[:ts], acq_time,
|
362
382
|
instrument
|
363
383
|
)
|
364
384
|
end
|
@@ -367,6 +387,7 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
367
387
|
acq_process[:lock_info] = {
|
368
388
|
lock_key: result[:lock_key],
|
369
389
|
acq_id: result[:acq_id],
|
390
|
+
hst_id: result[:hst_id],
|
370
391
|
ts: result[:ts],
|
371
392
|
ttl: result[:ttl],
|
372
393
|
process: result[:process]
|
@@ -464,6 +485,7 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
464
485
|
logger,
|
465
486
|
lock_key,
|
466
487
|
acquier_id,
|
488
|
+
host_id,
|
467
489
|
access_strategy,
|
468
490
|
timed,
|
469
491
|
ttl_shift,
|
@@ -493,6 +515,7 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
493
515
|
acq_process[:lock_info][:lock_key],
|
494
516
|
acq_process[:lock_info][:ttl],
|
495
517
|
acq_process[:lock_info][:acq_id],
|
518
|
+
acq_process[:lock_info][:hst_id],
|
496
519
|
acq_process[:lock_info][:ts],
|
497
520
|
acq_process[:acq_time],
|
498
521
|
acq_process[:hold_time],
|
@@ -506,6 +529,7 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
506
529
|
acq_process[:lock_info][:lock_key],
|
507
530
|
acq_process[:lock_info][:ttl],
|
508
531
|
acq_process[:lock_info][:acq_id],
|
532
|
+
acq_process[:lock_info][:hst_id],
|
509
533
|
acq_process[:lock_info][:ts],
|
510
534
|
acq_process[:lock_info][:lock_key],
|
511
535
|
acq_process[:acq_time],
|
@@ -13,9 +13,11 @@ module RedisQueuedLocks::Acquier::ClearDeadRequests
|
|
13
13
|
# @param log_sampling_enabled [Boolean]
|
14
14
|
# @param log_sampling_percent [Integer]
|
15
15
|
# @param log_sampler [#sampling_happened?,Module<RedisQueuedLocks::Logging::Sampler>]
|
16
|
+
# @param log_sample_this [Boolean]
|
16
17
|
# @param instr_sampling_enabled [Boolean]
|
17
18
|
# @param instr_sampling_percent [Integer]
|
18
19
|
# @param instr_sampler [#sampling_happened?,Module<RedisQueuedLocks::Instrument::Sampler>]
|
20
|
+
# @param instr_sample_this [Boolean]
|
19
21
|
# @return [Hash<Symbol,Boolean|Hash<Symbol,Set<String>>>]
|
20
22
|
#
|
21
23
|
# @api private
|
@@ -31,9 +33,11 @@ module RedisQueuedLocks::Acquier::ClearDeadRequests
|
|
31
33
|
log_sampling_enabled,
|
32
34
|
log_sampling_percent,
|
33
35
|
log_sampler,
|
36
|
+
log_sample_this,
|
34
37
|
instr_sampling_enabled,
|
35
38
|
instr_sampling_percent,
|
36
|
-
instr_sampler
|
39
|
+
instr_sampler,
|
40
|
+
instr_sample_this
|
37
41
|
)
|
38
42
|
dead_score = RedisQueuedLocks::Resource.acquier_dead_score(dead_ttl / 1_000.0)
|
39
43
|
|
@@ -22,9 +22,11 @@ module RedisQueuedLocks::Acquier::ExtendLockTTL
|
|
22
22
|
# @param log_sampling_enabled [Boolean]
|
23
23
|
# @param log_sampling_percent [Integer]
|
24
24
|
# @param log_sampler [#sampling_happened?,Module<RedisQueuedLocks::Logging::Sampler>]
|
25
|
+
# @param log_sample_this [Boolean]
|
25
26
|
# @param instr_sampling_enabled [Boolean]
|
26
27
|
# @param instr_sampling_percent [Integer]
|
27
28
|
# @param instr_sampler [#sampling_happened?,Module<RedisQueuedLocks::Instrument::Sampler>]
|
29
|
+
# @param instr_sample_this [Boolean]
|
28
30
|
# @return [Hash<Symbol,Boolean|Symbol>]
|
29
31
|
#
|
30
32
|
# @api private
|
@@ -40,9 +42,11 @@ module RedisQueuedLocks::Acquier::ExtendLockTTL
|
|
40
42
|
log_sampling_enabled,
|
41
43
|
log_sampling_percent,
|
42
44
|
log_sampler,
|
45
|
+
log_sample_this,
|
43
46
|
instr_sampling_enabled,
|
44
47
|
instr_sampling_percent,
|
45
|
-
instr_sampler
|
48
|
+
instr_sampler,
|
49
|
+
instr_sample_this
|
46
50
|
)
|
47
51
|
lock_key = RedisQueuedLocks::Resource.prepare_lock_key(lock_name)
|
48
52
|
|
@@ -10,7 +10,8 @@ module RedisQueuedLocks::Acquier::LockInfo
|
|
10
10
|
# - `nil` is returned when lock key does not exist or expired;
|
11
11
|
# - result format: {
|
12
12
|
# 'lock_key' => "rql:lock:your_lockname", # acquired lock key
|
13
|
-
# 'acq_id' => "rql:acq:
|
13
|
+
# 'acq_id' => "rql:acq:123/456/789/987/uniqstring", # lock acquier identifier
|
14
|
+
# 'hst_id' => "rql:hst:123/456/987/uniqstring", # lock host identifier
|
14
15
|
# 'ts' => 123456789.2649841, # <locked at> time stamp (epoch, seconds.microseconds)
|
15
16
|
# 'ini_ttl' => 123456789, # initial lock key ttl (milliseconds)
|
16
17
|
# 'rem_ttl' => 123456789, # remaining lock key ttl (milliseconds)
|
@@ -24,7 +25,7 @@ module RedisQueuedLocks::Acquier::LockInfo
|
|
24
25
|
#
|
25
26
|
# @api private
|
26
27
|
# @since 1.0.0
|
27
|
-
# @version 1.
|
28
|
+
# @version 1.9.0
|
28
29
|
# rubocop:disable Metrics/MethodLength
|
29
30
|
def lock_info(redis_client, lock_name)
|
30
31
|
lock_key = RedisQueuedLocks::Resource.prepare_lock_key(lock_name)
|
@@ -55,7 +56,7 @@ module RedisQueuedLocks::Acquier::LockInfo
|
|
55
56
|
lock_data['lock_key'] = lock_key
|
56
57
|
lock_data['ts'] = Float(lock_data['ts'])
|
57
58
|
lock_data['ini_ttl'] = Integer(lock_data['ini_ttl'])
|
58
|
-
lock_data['rem_ttl'] = ((pttl_cmd_res == -1) ?
|
59
|
+
lock_data['rem_ttl'] = ((pttl_cmd_res == -1) ? Float::INFINITY : pttl_cmd_res)
|
59
60
|
lock_data['spc_cnt'] = Integer(lock_data['spc_cnt']) if lock_data['spc_cnt']
|
60
61
|
lock_data['l_spc_ts'] = Float(lock_data['l_spc_ts']) if lock_data['l_spc_ts']
|
61
62
|
lock_data['spc_ext_ttl'] = Integer(lock_data['spc_ext_ttl']) if lock_data['spc_ext_ttl']
|
@@ -45,7 +45,7 @@ module RedisQueuedLocks::Acquier::Locks
|
|
45
45
|
#
|
46
46
|
# @api private
|
47
47
|
# @since 1.0.0
|
48
|
-
# @version 1.
|
48
|
+
# @version 1.9.0
|
49
49
|
# rubocop:disable Metrics/MethodLength
|
50
50
|
def extract_locks_info(redis_client, lock_keys)
|
51
51
|
# TODO: refactor with RedisQueuedLocks::Acquier::LockInfo
|
@@ -72,7 +72,7 @@ module RedisQueuedLocks::Acquier::Locks
|
|
72
72
|
hget_cmd_res.tap do |lock_data|
|
73
73
|
lock_data['ts'] = Float(lock_data['ts'])
|
74
74
|
lock_data['ini_ttl'] = Integer(lock_data['ini_ttl'])
|
75
|
-
lock_data['rem_ttl'] = ((pttl_cmd_res == -1) ?
|
75
|
+
lock_data['rem_ttl'] = ((pttl_cmd_res == -1) ? Float::INFINITY : pttl_cmd_res)
|
76
76
|
lock_data['spc_cnt'] = Integer(lock_data['spc_cnt']) if lock_data['spc_cnt']
|
77
77
|
lock_data['l_spc_ts'] = Float(lock_data['l_spc_ts']) if lock_data['l_spc_ts']
|
78
78
|
lock_data['spc_ext_ttl'] =
|
@@ -17,8 +17,8 @@ module RedisQueuedLocks::Acquier::QueueInfo
|
|
17
17
|
# - result format: {
|
18
18
|
# "lock_queue" => "rql:lock_queue:your_lock_name", # lock queue key in redis,
|
19
19
|
# queue: [
|
20
|
-
# { "acq_id" => "rql:acq:
|
21
|
-
# { "acq_id" => "rql:acq:
|
20
|
+
# { "acq_id" => "rql:acq:123/456/789/987/identity", "score" => 123 },
|
21
|
+
# { "acq_id" => "rql:acq:123/686/789/987/identity", "score" => 456 },
|
22
22
|
# ] # ordered set (by score) with information about an acquier and their position in queue
|
23
23
|
# }
|
24
24
|
#
|
@@ -40,6 +40,9 @@ module RedisQueuedLocks::Acquier::ReleaseAllLocks
|
|
40
40
|
# - you can provide your own log sampler with bettter algorithm that should realize
|
41
41
|
# `sampling_happened?(percent) => boolean` interface
|
42
42
|
# (see `RedisQueuedLocks::Logging::Sampler` for example);
|
43
|
+
# @param log_sample_this [Boolean]
|
44
|
+
# - marks the method that everything should be logged despite the enabled log sampling;
|
45
|
+
# - makes sense when log sampling is enabled;
|
43
46
|
# @param instr_sampling_enabled [Boolean]
|
44
47
|
# - enables <instrumentaion sampling>: only the configured percent
|
45
48
|
# of RQL cases will be instrumented;
|
@@ -58,6 +61,10 @@ module RedisQueuedLocks::Acquier::ReleaseAllLocks
|
|
58
61
|
# - you can provide your own log sampler with bettter algorithm that should realize
|
59
62
|
# `sampling_happened?(percent) => boolean` interface
|
60
63
|
# (see `RedisQueuedLocks::Instrument::Sampler` for example);
|
64
|
+
# @param instr_sample_this [Boolean]
|
65
|
+
# - marks the method that everything should be instrumneted
|
66
|
+
# despite the enabled instrumentation sampling;
|
67
|
+
# - makes sense when instrumentation sampling is enabled;
|
61
68
|
# @return [RedisQueuedLocks::Data,Hash<Symbol,Any>]
|
62
69
|
# Format: { ok: true, result: Hash<Symbol,Numeric> }
|
63
70
|
#
|
@@ -73,18 +80,21 @@ module RedisQueuedLocks::Acquier::ReleaseAllLocks
|
|
73
80
|
log_sampling_enabled,
|
74
81
|
log_sampling_percent,
|
75
82
|
log_sampler,
|
83
|
+
log_sample_this,
|
76
84
|
instr_sampling_enabled,
|
77
85
|
instr_sampling_percent,
|
78
|
-
instr_sampler
|
86
|
+
instr_sampler,
|
87
|
+
instr_sample_this
|
79
88
|
)
|
80
89
|
rel_start_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :microsecond)
|
81
90
|
fully_release_all_locks(redis, batch_size) => { ok:, result: }
|
82
91
|
time_at = Time.now.to_f
|
83
92
|
rel_end_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :microsecond)
|
84
|
-
rel_time = ((rel_end_time - rel_start_time) / 1_000).ceil(2)
|
93
|
+
rel_time = ((rel_end_time - rel_start_time) / 1_000.0).ceil(2)
|
85
94
|
|
86
95
|
instr_sampled = RedisQueuedLocks::Instrument.should_instrument?(
|
87
96
|
instr_sampling_enabled,
|
97
|
+
instr_sample_this,
|
88
98
|
instr_sampling_percent,
|
89
99
|
instr_sampler
|
90
100
|
)
|
@@ -40,6 +40,9 @@ module RedisQueuedLocks::Acquier::ReleaseLock
|
|
40
40
|
# - you can provide your own log sampler with bettter algorithm that should realize
|
41
41
|
# `sampling_happened?(percent) => boolean` interface
|
42
42
|
# (see `RedisQueuedLocks::Logging::Sampler` for example);
|
43
|
+
# @param log_sample_this [Boolean]
|
44
|
+
# - marks the method that everything should be logged despite the enabled log sampling;
|
45
|
+
# - makes sense when log sampling is enabled;
|
43
46
|
# @param instr_sampling_enabled [Boolean]
|
44
47
|
# - enables <instrumentaion sampling>: only the configured percent
|
45
48
|
# of RQL cases will be instrumented;
|
@@ -58,6 +61,10 @@ module RedisQueuedLocks::Acquier::ReleaseLock
|
|
58
61
|
# - you can provide your own log sampler with bettter algorithm that should realize
|
59
62
|
# `sampling_happened?(percent) => boolean` interface
|
60
63
|
# (see `RedisQueuedLocks::Instrument::Sampler` for example);
|
64
|
+
# @param instr_sample_this [Boolean]
|
65
|
+
# - marks the method that everything should be instrumneted
|
66
|
+
# despite the enabled instrumentation sampling;
|
67
|
+
# - makes sense when instrumentation sampling is enabled;
|
61
68
|
# @return [RedisQueuedLocks::Data,Hash<Symbol,Boolean<Hash<Symbol,Numeric|String|Symbol>>]
|
62
69
|
# Format: { ok: true/false, result: Hash<Symbol,Numeric|String|Symbol> }
|
63
70
|
#
|
@@ -73,9 +80,11 @@ module RedisQueuedLocks::Acquier::ReleaseLock
|
|
73
80
|
log_sampling_enabled,
|
74
81
|
log_sampling_percent,
|
75
82
|
log_sampler,
|
83
|
+
log_sample_this,
|
76
84
|
instr_sampling_enabled,
|
77
85
|
instr_sampling_percent,
|
78
|
-
instr_sampler
|
86
|
+
instr_sampler,
|
87
|
+
instr_sample_this
|
79
88
|
)
|
80
89
|
lock_key = RedisQueuedLocks::Resource.prepare_lock_key(lock_name)
|
81
90
|
lock_key_queue = RedisQueuedLocks::Resource.prepare_lock_queue(lock_name)
|
@@ -84,10 +93,11 @@ module RedisQueuedLocks::Acquier::ReleaseLock
|
|
84
93
|
fully_release_lock(redis, lock_key, lock_key_queue) => { ok:, result: }
|
85
94
|
time_at = Time.now.to_f
|
86
95
|
rel_end_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :microsecond)
|
87
|
-
rel_time = ((rel_end_time - rel_start_time) / 1_000).ceil(2)
|
96
|
+
rel_time = ((rel_end_time - rel_start_time) / 1_000.0).ceil(2)
|
88
97
|
|
89
98
|
instr_sampled = RedisQueuedLocks::Instrument.should_instrument?(
|
90
99
|
instr_sampling_enabled,
|
100
|
+
instr_sample_this,
|
91
101
|
instr_sampling_percent,
|
92
102
|
instr_sampler
|
93
103
|
)
|