redis_queued_locks 1.8.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -12,11 +12,13 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
12
12
|
# @param lock_key [String]
|
13
13
|
# @param queue_ttl [Integer]
|
14
14
|
# @param acquier_id [String]
|
15
|
+
# @param host_id [String]
|
15
16
|
# @param access_strategy [Symbol]
|
16
17
|
# @return [void]
|
17
18
|
#
|
18
19
|
# @api private
|
19
20
|
# @since 1.7.0
|
21
|
+
# @version 1.9.0
|
20
22
|
def start(
|
21
23
|
logger,
|
22
24
|
log_sampled,
|
@@ -24,6 +26,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
24
26
|
lock_key,
|
25
27
|
queue_ttl,
|
26
28
|
acquier_id,
|
29
|
+
host_id,
|
27
30
|
access_strategy
|
28
31
|
)
|
29
32
|
return unless log_sampled && log_lock_try
|
@@ -33,6 +36,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
33
36
|
"lock_key => '#{lock_key}' " \
|
34
37
|
"queue_ttl => #{queue_ttl} " \
|
35
38
|
"acq_id => '#{acquier_id}' " \
|
39
|
+
"hst_id => '#{host_id}' " \
|
36
40
|
"acs_strat => '#{access_strategy}'"
|
37
41
|
end rescue nil
|
38
42
|
end
|
@@ -43,11 +47,13 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
43
47
|
# @param lock_key [String]
|
44
48
|
# @param queue_ttl [Integer]
|
45
49
|
# @param acquier_id [String]
|
50
|
+
# @param host_id [String]
|
46
51
|
# @param access_strategy [Symbol]
|
47
52
|
# @return [void]
|
48
53
|
#
|
49
54
|
# @api private
|
50
55
|
# @since 1.7.0
|
56
|
+
# @version 1.9.0
|
51
57
|
def rconn_fetched(
|
52
58
|
logger,
|
53
59
|
log_sampled,
|
@@ -55,6 +61,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
55
61
|
lock_key,
|
56
62
|
queue_ttl,
|
57
63
|
acquier_id,
|
64
|
+
host_id,
|
58
65
|
access_strategy
|
59
66
|
)
|
60
67
|
return unless log_sampled && log_lock_try
|
@@ -64,6 +71,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
64
71
|
"lock_key => '#{lock_key}' " \
|
65
72
|
"queue_ttl => #{queue_ttl} " \
|
66
73
|
"acq_id => '#{acquier_id}' " \
|
74
|
+
"hst_id => '#{host_id}' " \
|
67
75
|
"acs_strat => '#{access_strategy}'"
|
68
76
|
end rescue nil
|
69
77
|
end
|
@@ -74,11 +82,13 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
74
82
|
# @param lock_key [String]
|
75
83
|
# @param queue_ttl [Integer]
|
76
84
|
# @param acquier_id [String]
|
85
|
+
# @param host_id [String]
|
77
86
|
# @param access_strategy [Symbol]
|
78
87
|
# @return [void]
|
79
88
|
#
|
80
89
|
# @api private
|
81
90
|
# @since 1.7.0
|
91
|
+
# @version 1.9.0
|
82
92
|
def same_process_conflict_detected(
|
83
93
|
logger,
|
84
94
|
log_sampled,
|
@@ -86,6 +96,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
86
96
|
lock_key,
|
87
97
|
queue_ttl,
|
88
98
|
acquier_id,
|
99
|
+
host_id,
|
89
100
|
access_strategy
|
90
101
|
)
|
91
102
|
return unless log_sampled && log_lock_try
|
@@ -95,6 +106,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
95
106
|
"lock_key => '#{lock_key}' " \
|
96
107
|
"queue_ttl => #{queue_ttl} " \
|
97
108
|
"acq_id => '#{acquier_id}' " \
|
109
|
+
"hst_id => '#{host_id}' " \
|
98
110
|
"acs_strat => '#{access_strategy}'"
|
99
111
|
end rescue nil
|
100
112
|
end
|
@@ -105,12 +117,14 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
105
117
|
# @param lock_key [String]
|
106
118
|
# @param queue_ttl [Integer]
|
107
119
|
# @param acquier_id [String]
|
120
|
+
# @param host_id [String]
|
108
121
|
# @param access_strategy [Symbol]
|
109
122
|
# @param sp_conflict_status [Symbol]
|
110
123
|
# @return [void]
|
111
124
|
#
|
112
125
|
# @api private
|
113
126
|
# @since 1.7.0
|
127
|
+
# @version 1.9.0
|
114
128
|
def same_process_conflict_analyzed(
|
115
129
|
logger,
|
116
130
|
log_sampled,
|
@@ -118,6 +132,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
118
132
|
lock_key,
|
119
133
|
queue_ttl,
|
120
134
|
acquier_id,
|
135
|
+
host_id,
|
121
136
|
access_strategy,
|
122
137
|
sp_conflict_status
|
123
138
|
)
|
@@ -128,6 +143,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
128
143
|
"lock_key => '#{lock_key}' " \
|
129
144
|
"queue_ttl => #{queue_ttl} " \
|
130
145
|
"acq_id => '#{acquier_id}' " \
|
146
|
+
"hst_id => '#{host_id}' " \
|
131
147
|
"acs_strat => '#{access_strategy}' " \
|
132
148
|
"spc_status => '#{sp_conflict_status}'"
|
133
149
|
end rescue nil
|
@@ -139,6 +155,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
139
155
|
# @param lock_key [String]
|
140
156
|
# @param queue_ttl [Integer]
|
141
157
|
# @param acquier_id [String]
|
158
|
+
# @param host_id [String]
|
142
159
|
# @param access_strategy [Symbol]
|
143
160
|
# @param sp_conflict_status [Symbol]
|
144
161
|
# @param ttl [Integer]
|
@@ -147,6 +164,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
147
164
|
#
|
148
165
|
# @api private
|
149
166
|
# @since 1.7.0
|
167
|
+
# @version 1.9.0
|
150
168
|
def reentrant_lock__extend_and_work_through(
|
151
169
|
logger,
|
152
170
|
log_sampled,
|
@@ -154,6 +172,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
154
172
|
lock_key,
|
155
173
|
queue_ttl,
|
156
174
|
acquier_id,
|
175
|
+
host_id,
|
157
176
|
access_strategy,
|
158
177
|
sp_conflict_status,
|
159
178
|
ttl,
|
@@ -166,6 +185,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
166
185
|
"lock_key => '#{lock_key}' " \
|
167
186
|
"queue_ttl => #{queue_ttl} " \
|
168
187
|
"acq_id => '#{acquier_id}' " \
|
188
|
+
"hst_id => '#{host_id}' " \
|
169
189
|
"acs_strat => '#{access_strategy}' " \
|
170
190
|
"spc_status => '#{sp_conflict_status}' " \
|
171
191
|
"last_ext_ttl => #{ttl} " \
|
@@ -179,6 +199,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
179
199
|
# @param lock_key [String]
|
180
200
|
# @param queue_ttl [Integer]
|
181
201
|
# @param acquier_id [String]
|
202
|
+
# @param host_id [String]
|
182
203
|
# @param access_strategy [Symbol]
|
183
204
|
# @param sp_conflict_status [Symbol]
|
184
205
|
# @param spc_processed_timestamp [Float]
|
@@ -186,6 +207,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
186
207
|
#
|
187
208
|
# @api private
|
188
209
|
# @since 1.7.0
|
210
|
+
# @version 1.9.0
|
189
211
|
def reentrant_lock__work_through(
|
190
212
|
logger,
|
191
213
|
log_sampled,
|
@@ -193,6 +215,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
193
215
|
lock_key,
|
194
216
|
queue_ttl,
|
195
217
|
acquier_id,
|
218
|
+
host_id,
|
196
219
|
access_strategy,
|
197
220
|
sp_conflict_status,
|
198
221
|
spc_processed_timestamp
|
@@ -204,6 +227,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
204
227
|
"lock_key => '#{lock_key}' " \
|
205
228
|
"queue_ttl => #{queue_ttl} " \
|
206
229
|
"acq_id => '#{acquier_id}' " \
|
230
|
+
"hst_id => '#{host_id}' " \
|
207
231
|
"acs_strat => '#{access_strategy}' " \
|
208
232
|
"spc_status => '#{sp_conflict_status}' " \
|
209
233
|
"last_spc_ts => '#{spc_processed_timestamp}'"
|
@@ -216,6 +240,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
216
240
|
# @param lock_key [String]
|
217
241
|
# @param queue_ttl [Integer]
|
218
242
|
# @param acquier_id [String]
|
243
|
+
# @param host_id [String]
|
219
244
|
# @param access_strategy [Symbol]
|
220
245
|
# @param sp_conflict_status [Symbol]
|
221
246
|
# @param spc_processed_timestamp [Float]
|
@@ -223,6 +248,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
223
248
|
#
|
224
249
|
# @api private
|
225
250
|
# @since 1.7.0
|
251
|
+
# @version 1.9.0
|
226
252
|
def single_process_lock_conflict__dead_lock(
|
227
253
|
logger,
|
228
254
|
log_sampled,
|
@@ -230,6 +256,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
230
256
|
lock_key,
|
231
257
|
queue_ttl,
|
232
258
|
acquier_id,
|
259
|
+
host_id,
|
233
260
|
access_strategy,
|
234
261
|
sp_conflict_status,
|
235
262
|
spc_processed_timestamp
|
@@ -241,6 +268,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
241
268
|
"lock_key => '#{lock_key}' " \
|
242
269
|
"queue_ttl => #{queue_ttl} " \
|
243
270
|
"acq_id => '#{acquier_id}' " \
|
271
|
+
"hst_id => '#{host_id}' " \
|
244
272
|
"acs_strat => '#{access_strategy}' " \
|
245
273
|
"spc_status => '#{sp_conflict_status}' " \
|
246
274
|
"last_spc_ts => '#{spc_processed_timestamp}'"
|
@@ -253,11 +281,13 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
253
281
|
# @param lock_key [String]
|
254
282
|
# @param queue_ttl [Integer]
|
255
283
|
# @param acquier_id [String]
|
284
|
+
# @param host_id [String]
|
256
285
|
# @param access_strategy [Symbol]
|
257
286
|
# @return [void]
|
258
287
|
#
|
259
288
|
# @api private
|
260
289
|
# @since 1.7.0
|
290
|
+
# @version 1.9.0
|
261
291
|
def acq_added_to_queue(
|
262
292
|
logger,
|
263
293
|
log_sampled,
|
@@ -265,6 +295,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
265
295
|
lock_key,
|
266
296
|
queue_ttl,
|
267
297
|
acquier_id,
|
298
|
+
host_id,
|
268
299
|
access_strategy
|
269
300
|
)
|
270
301
|
return unless log_sampled && log_lock_try
|
@@ -274,6 +305,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
274
305
|
"lock_key => '#{lock_key}' " \
|
275
306
|
"queue_ttl => #{queue_ttl} " \
|
276
307
|
"acq_id => '#{acquier_id}' " \
|
308
|
+
"hst_id => '#{host_id}' " \
|
277
309
|
"acs_strat => '#{access_strategy}'"
|
278
310
|
end rescue nil
|
279
311
|
end
|
@@ -284,11 +316,13 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
284
316
|
# @param lock_key [String]
|
285
317
|
# @param queue_ttl [Integer]
|
286
318
|
# @param acquier_id [String]
|
319
|
+
# @param host_id [String]
|
287
320
|
# @param access_strategy [Symbol]
|
288
321
|
# @return [void]
|
289
322
|
#
|
290
323
|
# @api private
|
291
324
|
# @since 1.7.0
|
325
|
+
# @version 1.9.0
|
292
326
|
def remove_expired_acqs(
|
293
327
|
logger,
|
294
328
|
log_sampled,
|
@@ -296,6 +330,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
296
330
|
lock_key,
|
297
331
|
queue_ttl,
|
298
332
|
acquier_id,
|
333
|
+
host_id,
|
299
334
|
access_strategy
|
300
335
|
)
|
301
336
|
return unless log_sampled && log_lock_try
|
@@ -305,6 +340,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
305
340
|
"lock_key => '#{lock_key}' " \
|
306
341
|
"queue_ttl => #{queue_ttl} " \
|
307
342
|
"acq_id => '#{acquier_id}' " \
|
343
|
+
"hst_id => '#{host_id}' " \
|
308
344
|
"acs_strat => '#{access_strategy}'"
|
309
345
|
end rescue nil
|
310
346
|
end
|
@@ -315,12 +351,14 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
315
351
|
# @param lock_key [String]
|
316
352
|
# @param queue_ttl [Integer]
|
317
353
|
# @param acquier_id [String]
|
354
|
+
# @param host_id [String]
|
318
355
|
# @param access_strategy [Symbol]
|
319
356
|
# @param waiting_acquier [String]
|
320
357
|
# @return [void]
|
321
358
|
#
|
322
359
|
# @api private
|
323
360
|
# @since 1.7.0
|
361
|
+
# @version 1.9.0
|
324
362
|
def get_first_from_queue(
|
325
363
|
logger,
|
326
364
|
log_sampled,
|
@@ -328,6 +366,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
328
366
|
lock_key,
|
329
367
|
queue_ttl,
|
330
368
|
acquier_id,
|
369
|
+
host_id,
|
331
370
|
access_strategy,
|
332
371
|
waiting_acquier
|
333
372
|
)
|
@@ -338,6 +377,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
338
377
|
"lock_key => '#{lock_key}' " \
|
339
378
|
"queue_ttl => #{queue_ttl} " \
|
340
379
|
"acq_id => '#{acquier_id}' " \
|
380
|
+
"hst_id => '#{host_id}' " \
|
341
381
|
"acs_strat => '#{access_strategy}' " \
|
342
382
|
"first_acq_id_in_queue => '#{waiting_acquier}'"
|
343
383
|
end rescue nil
|
@@ -349,11 +389,13 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
349
389
|
# @param lock_key [String]
|
350
390
|
# @param queue_ttl [Integer]
|
351
391
|
# @param acquier_id [String]
|
392
|
+
# @param host_id [String]
|
352
393
|
# @param access_strategy [Symbol]
|
353
394
|
# @return [void]
|
354
395
|
#
|
355
396
|
# @api private
|
356
397
|
# @since 1.7.0
|
398
|
+
# @version 1.9.0
|
357
399
|
def exit__queue_ttl_reached(
|
358
400
|
logger,
|
359
401
|
log_sampled,
|
@@ -361,6 +403,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
361
403
|
lock_key,
|
362
404
|
queue_ttl,
|
363
405
|
acquier_id,
|
406
|
+
host_id,
|
364
407
|
access_strategy
|
365
408
|
)
|
366
409
|
return unless log_sampled && log_lock_try
|
@@ -370,6 +413,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
370
413
|
"lock_key => '#{lock_key}' " \
|
371
414
|
"queue_ttl => #{queue_ttl} " \
|
372
415
|
"acq_id => '#{acquier_id}' " \
|
416
|
+
"hst_id => '#{host_id}' " \
|
373
417
|
"acs_strat => '#{access_strategy}'"
|
374
418
|
end rescue nil
|
375
419
|
end
|
@@ -380,6 +424,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
380
424
|
# @param lock_key [String]
|
381
425
|
# @param queue_ttl [Integer]
|
382
426
|
# @param acquier_id [String]
|
427
|
+
# @param host_id [String]
|
383
428
|
# @param access_strategy [Symbol]
|
384
429
|
# @param waiting_acquier [String]
|
385
430
|
# @param current_lock_data [Hash<String,Any>]
|
@@ -387,6 +432,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
387
432
|
#
|
388
433
|
# @api private
|
389
434
|
# @since 1.7.0
|
435
|
+
# @version 1.9.0
|
390
436
|
def exit__no_first(
|
391
437
|
logger,
|
392
438
|
log_sampled,
|
@@ -394,6 +440,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
394
440
|
lock_key,
|
395
441
|
queue_ttl,
|
396
442
|
acquier_id,
|
443
|
+
host_id,
|
397
444
|
access_strategy,
|
398
445
|
waiting_acquier,
|
399
446
|
current_lock_data
|
@@ -405,6 +452,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
405
452
|
"lock_key => '#{lock_key}' " \
|
406
453
|
"queue_ttl => #{queue_ttl} " \
|
407
454
|
"acq_id => '#{acquier_id}' " \
|
455
|
+
"hst_id => '#{host_id}' " \
|
408
456
|
"acs_strat => '#{access_strategy}' " \
|
409
457
|
"first_acq_id_in_queue => '#{waiting_acquier}' " \
|
410
458
|
"<current_lock_data> => <<#{current_lock_data}>>"
|
@@ -417,6 +465,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
417
465
|
# @param lock_key [String]
|
418
466
|
# @param queue_ttl [Integer]
|
419
467
|
# @param acquier_id [String]
|
468
|
+
# @param host_id [String]
|
420
469
|
# @param access_strategy [Symbol]
|
421
470
|
# @param waiting_acquier [String]
|
422
471
|
# @param locked_by_acquier [String]
|
@@ -425,6 +474,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
425
474
|
#
|
426
475
|
# @api private
|
427
476
|
# @since 1.7.0
|
477
|
+
# @version 1.9.0
|
428
478
|
def exit__lock_still_obtained(
|
429
479
|
logger,
|
430
480
|
log_sampled,
|
@@ -432,6 +482,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
432
482
|
lock_key,
|
433
483
|
queue_ttl,
|
434
484
|
acquier_id,
|
485
|
+
host_id,
|
435
486
|
access_strategy,
|
436
487
|
waiting_acquier,
|
437
488
|
locked_by_acquier,
|
@@ -444,6 +495,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
444
495
|
"lock_key => '#{lock_key}' " \
|
445
496
|
"queue_ttl => #{queue_ttl} " \
|
446
497
|
"acq_id => '#{acquier_id}' " \
|
498
|
+
"hst_id => '#{host_id}' " \
|
447
499
|
"acs_strat => '#{access_strategy}' " \
|
448
500
|
"first_acq_id_in_queue => '#{waiting_acquier}' " \
|
449
501
|
"locked_by_acq_id => '#{locked_by_acquier}' " \
|
@@ -457,11 +509,13 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
457
509
|
# @param lock_key [String]
|
458
510
|
# @param queue_ttl [Integer]
|
459
511
|
# @param acquier_id [String]
|
512
|
+
# @param host_id [String]
|
460
513
|
# @param access_strategy [Symbol]
|
461
514
|
# @return [void]
|
462
515
|
#
|
463
516
|
# @api private
|
464
517
|
# @since 1.7.0
|
518
|
+
# @version 1.9.0
|
465
519
|
def obtain__free_to_acquire(
|
466
520
|
logger,
|
467
521
|
log_sampled,
|
@@ -469,6 +523,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
469
523
|
lock_key,
|
470
524
|
queue_ttl,
|
471
525
|
acquier_id,
|
526
|
+
host_id,
|
472
527
|
access_strategy
|
473
528
|
)
|
474
529
|
return unless log_sampled && log_lock_try
|
@@ -478,6 +533,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock::LogVisitor
|
|
478
533
|
"lock_key => '#{lock_key}' " \
|
479
534
|
"queue_ttl => #{queue_ttl} " \
|
480
535
|
"acq_id => '#{acquier_id}' " \
|
536
|
+
"hst_id => '#{host_id}' " \
|
481
537
|
"acs_strat => '#{access_strategy}'"
|
482
538
|
end rescue nil
|
483
539
|
end
|
@@ -22,6 +22,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
22
22
|
# @param lock_key [String]
|
23
23
|
# @param lock_key_queue [String]
|
24
24
|
# @param acquier_id [String]
|
25
|
+
# @param host_id [String]
|
25
26
|
# @param acquier_position [Numeric]
|
26
27
|
# @param ttl [Integer]
|
27
28
|
# @param queue_ttl [Integer]
|
@@ -35,7 +36,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
35
36
|
#
|
36
37
|
# @api private
|
37
38
|
# @since 1.0.0
|
38
|
-
# @version 1.
|
39
|
+
# @version 1.9.0
|
39
40
|
# rubocop:disable Metrics/MethodLength
|
40
41
|
def try_to_lock(
|
41
42
|
redis,
|
@@ -44,6 +45,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
44
45
|
lock_key,
|
45
46
|
lock_key_queue,
|
46
47
|
acquier_id,
|
48
|
+
host_id,
|
47
49
|
acquier_position,
|
48
50
|
ttl,
|
49
51
|
queue_ttl,
|
@@ -60,15 +62,15 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
60
62
|
spc_processed_timestamp = nil
|
61
63
|
|
62
64
|
LogVisitor.start(
|
63
|
-
logger, log_sampled, log_lock_try,
|
64
|
-
|
65
|
+
logger, log_sampled, log_lock_try, lock_key,
|
66
|
+
queue_ttl, acquier_id, host_id, access_strategy
|
65
67
|
)
|
66
68
|
|
67
69
|
# Step X: start to work with lock acquiring
|
68
70
|
result = redis.with do |rconn|
|
69
71
|
LogVisitor.rconn_fetched(
|
70
|
-
logger, log_sampled, log_lock_try,
|
71
|
-
|
72
|
+
logger, log_sampled, log_lock_try, lock_key,
|
73
|
+
queue_ttl, acquier_id, host_id, access_strategy
|
72
74
|
)
|
73
75
|
|
74
76
|
# Step 0:
|
@@ -83,8 +85,8 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
83
85
|
# SP-Conflict Step X1: calculate the current deadlock status
|
84
86
|
if current_lock_obtainer != nil && acquier_id == current_lock_obtainer
|
85
87
|
LogVisitor.same_process_conflict_detected(
|
86
|
-
logger, log_sampled, log_lock_try,
|
87
|
-
|
88
|
+
logger, log_sampled, log_lock_try, lock_key,
|
89
|
+
queue_ttl, acquier_id, host_id, access_strategy
|
88
90
|
)
|
89
91
|
|
90
92
|
# SP-Conflict Step X2: self-process dead lock moment started.
|
@@ -113,8 +115,8 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
113
115
|
# rubocop:enable Lint/DuplicateBranch
|
114
116
|
|
115
117
|
LogVisitor.same_process_conflict_analyzed(
|
116
|
-
logger, log_sampled, log_lock_try,
|
117
|
-
|
118
|
+
logger, log_sampled, log_lock_try, lock_key,
|
119
|
+
queue_ttl, acquier_id, host_id, access_strategy, sp_conflict_status
|
118
120
|
)
|
119
121
|
end
|
120
122
|
|
@@ -154,8 +156,8 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
154
156
|
inter_result = :extendable_conflict_work_through
|
155
157
|
|
156
158
|
LogVisitor.reentrant_lock__extend_and_work_through(
|
157
|
-
logger, log_sampled, log_lock_try,
|
158
|
-
|
159
|
+
logger, log_sampled, log_lock_try, lock_key,
|
160
|
+
queue_ttl, acquier_id, host_id, access_strategy,
|
159
161
|
sp_conflict_status, ttl, spc_processed_timestamp
|
160
162
|
)
|
161
163
|
# SP-Conflict-Step X2: switch to dead lock logic or not
|
@@ -179,8 +181,8 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
179
181
|
)
|
180
182
|
|
181
183
|
LogVisitor.reentrant_lock__work_through(
|
182
|
-
logger, log_sampled, log_lock_try,
|
183
|
-
|
184
|
+
logger, log_sampled, log_lock_try, lock_key,
|
185
|
+
queue_ttl, acquier_id, host_id, access_strategy,
|
184
186
|
sp_conflict_status, spc_processed_timestamp
|
185
187
|
)
|
186
188
|
# SP-Conflict-Step X2: switch to dead lock logic or not
|
@@ -189,8 +191,8 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
189
191
|
spc_processed_timestamp = Time.now.to_f
|
190
192
|
|
191
193
|
LogVisitor.single_process_lock_conflict__dead_lock(
|
192
|
-
logger, log_sampled, log_lock_try,
|
193
|
-
|
194
|
+
logger, log_sampled, log_lock_try, lock_key,
|
195
|
+
queue_ttl, acquier_id, host_id, access_strategy,
|
194
196
|
sp_conflict_status, spc_processed_timestamp
|
195
197
|
)
|
196
198
|
# Reached the SP-Non-Conflict Mode (NOTE):
|
@@ -204,8 +206,8 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
204
206
|
rconn.call('ZADD', lock_key_queue, 'NX', acquier_position, acquier_id)
|
205
207
|
|
206
208
|
LogVisitor.acq_added_to_queue(
|
207
|
-
logger, log_sampled, log_lock_try,
|
208
|
-
|
209
|
+
logger, log_sampled, log_lock_try, lock_key,
|
210
|
+
queue_ttl, acquier_id, host_id, access_strategy
|
209
211
|
)
|
210
212
|
|
211
213
|
# Step 2.1: drop expired acquiers from the lock queue
|
@@ -217,24 +219,24 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
217
219
|
)
|
218
220
|
|
219
221
|
LogVisitor.remove_expired_acqs(
|
220
|
-
logger, log_sampled, log_lock_try,
|
221
|
-
|
222
|
+
logger, log_sampled, log_lock_try, lock_key,
|
223
|
+
queue_ttl, acquier_id, host_id, access_strategy
|
222
224
|
)
|
223
225
|
|
224
226
|
# Step 3: get the actual acquier waiting in the queue
|
225
227
|
waiting_acquier = Array(rconn.call('ZRANGE', lock_key_queue, '0', '0')).first
|
226
228
|
|
227
229
|
LogVisitor.get_first_from_queue(
|
228
|
-
logger, log_sampled, log_lock_try,
|
229
|
-
|
230
|
+
logger, log_sampled, log_lock_try, lock_key,
|
231
|
+
queue_ttl, acquier_id, host_id, access_strategy, waiting_acquier
|
230
232
|
)
|
231
233
|
|
232
234
|
# Step PRE-4.x: check if the request time limit is reached
|
233
235
|
# (when the current try self-removes itself from queue (queue ttl has come))
|
234
236
|
if waiting_acquier == nil
|
235
237
|
LogVisitor.exit__queue_ttl_reached(
|
236
|
-
logger, log_sampled, log_lock_try,
|
237
|
-
|
238
|
+
logger, log_sampled, log_lock_try, lock_key,
|
239
|
+
queue_ttl, acquier_id, host_id, access_strategy
|
238
240
|
)
|
239
241
|
|
240
242
|
inter_result = :dead_score_reached
|
@@ -243,8 +245,8 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
243
245
|
elsif access_strategy == :queued && waiting_acquier != acquier_id
|
244
246
|
# Step ROLLBACK 1.1: our time hasn't come yet. retry!
|
245
247
|
LogVisitor.exit__no_first(
|
246
|
-
logger, log_sampled, log_lock_try,
|
247
|
-
|
248
|
+
logger, log_sampled, log_lock_try, lock_key,
|
249
|
+
queue_ttl, acquier_id, host_id, access_strategy, waiting_acquier,
|
248
250
|
rconn.call('HGETALL', lock_key).to_h
|
249
251
|
)
|
250
252
|
inter_result = :acquier_is_not_first_in_queue
|
@@ -260,8 +262,8 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
260
262
|
# Step ROLLBACK 2: required lock is stil acquired. retry!
|
261
263
|
|
262
264
|
LogVisitor.exit__lock_still_obtained(
|
263
|
-
logger, log_sampled, log_lock_try,
|
264
|
-
|
265
|
+
logger, log_sampled, log_lock_try, lock_key,
|
266
|
+
queue_ttl, acquier_id, host_id, access_strategy,
|
265
267
|
waiting_acquier, locked_by_acquier,
|
266
268
|
rconn.call('HGETALL', lock_key).to_h
|
267
269
|
)
|
@@ -272,11 +274,12 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
272
274
|
# Step 6.1: remove our acquier from waiting queue
|
273
275
|
transact.call('ZREM', lock_key_queue, acquier_id)
|
274
276
|
|
275
|
-
# Step 6.2: acquire a lock and store an info about the acquier
|
277
|
+
# Step 6.2: acquire a lock and store an info about the acquier and host
|
276
278
|
transact.call(
|
277
279
|
'HSET',
|
278
280
|
lock_key,
|
279
281
|
'acq_id', acquier_id,
|
282
|
+
'hst_id', host_id,
|
280
283
|
'ts', (timestamp = Time.now.to_f),
|
281
284
|
'ini_ttl', ttl,
|
282
285
|
*(meta.to_a if meta != nil)
|
@@ -286,8 +289,8 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
286
289
|
transact.call('PEXPIRE', lock_key, ttl) # NOTE: in milliseconds
|
287
290
|
|
288
291
|
LogVisitor.obtain__free_to_acquire(
|
289
|
-
logger, log_sampled, log_lock_try,
|
290
|
-
|
292
|
+
logger, log_sampled, log_lock_try, lock_key,
|
293
|
+
queue_ttl, acquier_id, host_id, access_strategy
|
291
294
|
)
|
292
295
|
end
|
293
296
|
end
|
@@ -317,6 +320,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
317
320
|
process: :extendable_conflict_work_through,
|
318
321
|
lock_key: lock_key,
|
319
322
|
acq_id: acquier_id,
|
323
|
+
hst_id: host_id,
|
320
324
|
ts: spc_processed_timestamp,
|
321
325
|
ttl: ttl
|
322
326
|
}]
|
@@ -327,6 +331,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
327
331
|
process: :extendable_conflict_work_through,
|
328
332
|
lock_key: lock_key,
|
329
333
|
acq_id: acquier_id,
|
334
|
+
hst_id: host_id,
|
330
335
|
ts: spc_processed_timestamp,
|
331
336
|
ttl: ttl
|
332
337
|
}]
|
@@ -348,6 +353,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
348
353
|
process: :conflict_work_through,
|
349
354
|
lock_key: lock_key,
|
350
355
|
acq_id: acquier_id,
|
356
|
+
hst_id: host_id,
|
351
357
|
ts: spc_processed_timestamp,
|
352
358
|
ttl: ttl
|
353
359
|
}]
|
@@ -381,6 +387,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
381
387
|
process: :lock_obtaining,
|
382
388
|
lock_key: lock_key,
|
383
389
|
acq_id: acquier_id,
|
390
|
+
hst_id: host_id,
|
384
391
|
ts: timestamp,
|
385
392
|
ttl: ttl
|
386
393
|
}]
|
@@ -10,17 +10,20 @@ module RedisQueuedLocks::Acquier::AcquireLock::YieldExpire::LogVisitor
|
|
10
10
|
# @param lock_key [String]
|
11
11
|
# @param queue_ttl [Integer]
|
12
12
|
# @param acquier_id [String]
|
13
|
+
# @param host_id [String]
|
13
14
|
# @param access_strategy [Symbol]
|
14
15
|
# @return [void]
|
15
16
|
#
|
16
17
|
# @api private
|
17
18
|
# @since 1.7.0
|
19
|
+
# @version 1.9.0
|
18
20
|
def expire_lock(
|
19
21
|
logger,
|
20
22
|
log_sampled,
|
21
23
|
lock_key,
|
22
24
|
queue_ttl,
|
23
25
|
acquier_id,
|
26
|
+
host_id,
|
24
27
|
access_strategy
|
25
28
|
)
|
26
29
|
return unless log_sampled
|
@@ -30,6 +33,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::YieldExpire::LogVisitor
|
|
30
33
|
"lock_key => '#{lock_key}' " \
|
31
34
|
"queue_ttl => #{queue_ttl} " \
|
32
35
|
"acq_id => '#{acquier_id}' " \
|
36
|
+
"hst_id => '#{host_id}' " \
|
33
37
|
"acs_strat => '#{access_strategy}'"
|
34
38
|
end rescue nil
|
35
39
|
end
|
@@ -40,11 +44,13 @@ module RedisQueuedLocks::Acquier::AcquireLock::YieldExpire::LogVisitor
|
|
40
44
|
# @param decreased_ttl [Integer]
|
41
45
|
# @param queue_ttl [Integer]
|
42
46
|
# @param acquier_id [String]
|
47
|
+
# @param host_id [String]
|
43
48
|
# @param access_strategy [Symbol]
|
44
49
|
# @return [void]
|
45
50
|
#
|
46
51
|
# @api private
|
47
52
|
# @since 1.7.0
|
53
|
+
# @version 1.9.0
|
48
54
|
def decrease_lock(
|
49
55
|
logger,
|
50
56
|
log_sampled,
|
@@ -52,6 +58,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::YieldExpire::LogVisitor
|
|
52
58
|
decreased_ttl,
|
53
59
|
queue_ttl,
|
54
60
|
acquier_id,
|
61
|
+
host_id,
|
55
62
|
access_strategy
|
56
63
|
)
|
57
64
|
return unless log_sampled
|
@@ -62,6 +69,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::YieldExpire::LogVisitor
|
|
62
69
|
"decreased_ttl => #{decreased_ttl} " \
|
63
70
|
"queue_ttl => #{queue_ttl} " \
|
64
71
|
"acq_id => '#{acquier_id}' " \
|
72
|
+
"hst_id => '#{host_id}' " \
|
65
73
|
"acs_strat => '#{access_strategy}'"
|
66
74
|
end rescue nil
|
67
75
|
end
|