redis_queued_locks 0.0.5 → 0.0.6
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 +8 -1
- data/README.md +29 -9
- data/lib/redis_queued_locks/acquier.rb +17 -9
- data/lib/redis_queued_locks/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e98a72e1519c54d21a6273176a7d8a3bd9fa3033b7f30ca73fdca5a4335341d
|
4
|
+
data.tar.gz: b2cf62db6016bd456a379feb3703989cc4a481f2eed4103c5c27a60bec624d46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d90c848b5fb00614c3f61719d470d7a2dae008d3b6349c395674fe7bf262feea09795dafc74756a16426f499652e9cb0dcb4eef8b0dc9e2c1cc8abff2a1345d1
|
7
|
+
data.tar.gz: ccc6e73175a2c41988303e3ea73feeacf95833b8d318dc1318c91f800d656ea157aeca62d7eba491ca489253a01ba4489f6a4c254c32f54ef3a540c9312ca179
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.0.6] - 2024-02-27
|
4
|
+
### Changed
|
5
|
+
- Major documentation updates;
|
6
|
+
- `RedisQueuedLock#release_lock!` now returns detaield semantic result;
|
7
|
+
- `RediSQueuedLock#release_all_locks!` now returns detailed semantic result;
|
8
|
+
|
3
9
|
## [0.0.5] - 2024-02-26
|
4
|
-
|
10
|
+
### Changed
|
11
|
+
- Minor gem update with documentation and configuration updates inside.
|
5
12
|
|
6
13
|
## [0.0.4] - 2024-02-26
|
7
14
|
### Changed
|
data/README.md
CHANGED
@@ -127,7 +127,7 @@ end
|
|
127
127
|
|
128
128
|
---
|
129
129
|
|
130
|
-
#### lock - obtain a lock
|
130
|
+
#### #lock - obtain a lock
|
131
131
|
|
132
132
|
```ruby
|
133
133
|
def lock(
|
@@ -186,9 +186,8 @@ Return value:
|
|
186
186
|
```
|
187
187
|
- for failed lock obtaining:
|
188
188
|
```ruby
|
189
|
-
{ ok: false, result: :
|
190
|
-
{ ok: false, result: :
|
191
|
-
{ ok: false, result: :lock_is_acquired_during_acquire_race }
|
189
|
+
{ ok: false, result: :timeout_reached }
|
190
|
+
{ ok: false, result: :retry_count_reached }
|
192
191
|
{ ok: false, result: :unknown }
|
193
192
|
```
|
194
193
|
|
@@ -197,9 +196,9 @@ Return value:
|
|
197
196
|
|
198
197
|
#### #lock! - exceptional lock obtaining
|
199
198
|
|
200
|
-
- fails when:
|
201
|
-
- `timeout` limit reached before lock is obtained;
|
202
|
-
- `retry_count` limit reached before lock is obtained;
|
199
|
+
- fails when (and with):
|
200
|
+
- (`RedisQueuedLocks::LockAcquiermentTimeoutError`) `timeout` limit reached before lock is obtained;
|
201
|
+
- (`RedisQueuedLocks::LockAcquiermentRetryLimitError`) `retry_count` limit reached before lock is obtained;
|
203
202
|
|
204
203
|
```ruby
|
205
204
|
def lock!(
|
@@ -233,7 +232,18 @@ def unlock(lock_name)
|
|
233
232
|
- the lock name that should be released.
|
234
233
|
|
235
234
|
Return:
|
236
|
-
- `[Hash<Symbol,Any>]` - Format: `{ ok: true/false, result: Symbol
|
235
|
+
- `[Hash<Symbol,Any>]` - Format: `{ ok: true/false, result: Hash<Symbol,Numeric|String> }`;
|
236
|
+
|
237
|
+
```ruby
|
238
|
+
{
|
239
|
+
ok: true,
|
240
|
+
result: {
|
241
|
+
rel_time: 0.02, # time spent to lock release (in seconds)
|
242
|
+
rel_key: "rql:lock:your_lock_name", # released lock key
|
243
|
+
rel_queue: "rql:lock_queue:your_lock_name" # released lock key queue
|
244
|
+
}
|
245
|
+
}
|
246
|
+
```
|
237
247
|
|
238
248
|
---
|
239
249
|
|
@@ -250,7 +260,17 @@ def clear_locks(batch_size: config[:lock_release_batch_size])
|
|
250
260
|
- batch of cleared locks and lock queus unde the one pipelined redis command;
|
251
261
|
|
252
262
|
Return:
|
253
|
-
- `[Hash<Symbol,Any>]` - Format: `{ ok: true/false, result: Symbol
|
263
|
+
- `[Hash<Symbol,Any>]` - Format: `{ ok: true/false, result: Hash<Symbol,Numeric> }`;
|
264
|
+
|
265
|
+
```ruby
|
266
|
+
{
|
267
|
+
ok: true,
|
268
|
+
result: {
|
269
|
+
rel_time: 3.07, # time spent to release all locks and related lock queues
|
270
|
+
rel_key_cnt: 100_500 # released redis keys (released locks + released lock queues)
|
271
|
+
}
|
272
|
+
}
|
273
|
+
```
|
254
274
|
|
255
275
|
---
|
256
276
|
|
@@ -60,7 +60,7 @@ module RedisQueuedLocks::Acquier
|
|
60
60
|
#
|
61
61
|
# @api private
|
62
62
|
# @since 0.1.0
|
63
|
-
# rubocop:disable Metrics/MethodLength
|
63
|
+
# rubocop:disable Metrics/MethodLength, Metrics/BlockNesting
|
64
64
|
def acquire_lock!(
|
65
65
|
redis,
|
66
66
|
lock_name,
|
@@ -147,6 +147,7 @@ module RedisQueuedLocks::Acquier
|
|
147
147
|
if retry_count != nil && acq_process[:tries] >= retry_count
|
148
148
|
# NOTE: reached the retry limit => quit from the loop
|
149
149
|
acq_process[:should_try] = false
|
150
|
+
acq_process[:result] = :retry_limit_reached
|
150
151
|
# NOTE: reached the retry limit => dequeue from the lock queue
|
151
152
|
acq_dequeue.call
|
152
153
|
# NOTE: check and raise an error
|
@@ -154,10 +155,11 @@ module RedisQueuedLocks::Acquier
|
|
154
155
|
Failed to acquire the lock "#{lock_key}"
|
155
156
|
for the given retry_count limit (#{retry_count} times).
|
156
157
|
ERROR_MESSAGE
|
157
|
-
|
158
|
+
else
|
158
159
|
# NOTE:
|
159
160
|
# delay the exceution in order to prevent chaotic attempts
|
160
161
|
# and to allow other processes and threads to obtain the lock too.
|
162
|
+
delay_execution(retry_delay, retry_jitter)
|
161
163
|
end
|
162
164
|
end
|
163
165
|
end
|
@@ -191,12 +193,18 @@ module RedisQueuedLocks::Acquier
|
|
191
193
|
{ ok: true, result: acq_process[:lock_info] }
|
192
194
|
end
|
193
195
|
else
|
194
|
-
|
195
|
-
|
196
|
+
unless acq_process[:result] == :retry_limit_reached
|
197
|
+
# NOTE: we have only two situations if lock is not acquired:
|
198
|
+
# - time limit is reached
|
199
|
+
# - retry count limit is reached
|
200
|
+
# In other cases the lock obtaining time and tries count are infinite.
|
201
|
+
acq_process[:result] = :timeout_reached
|
202
|
+
end
|
203
|
+
# Step 3.b: lock is not acquired (acquier is dequeued by timeout callback)
|
196
204
|
{ ok: false, result: acq_process[:result] }
|
197
205
|
end
|
198
206
|
end
|
199
|
-
# rubocop:enable Metrics/MethodLength
|
207
|
+
# rubocop:enable Metrics/MethodLength, Metrics/BlockNesting
|
200
208
|
|
201
209
|
# Release the concrete lock:
|
202
210
|
# - 1. clear lock queue: al; related processes released
|
@@ -208,7 +216,7 @@ module RedisQueuedLocks::Acquier
|
|
208
216
|
# @param redis [RedisClient] Redis connection client.
|
209
217
|
# @param lock_name [String] The lock name that should be released.
|
210
218
|
# @param isntrumenter [#notify] See RedisQueuedLocks::Instrument::ActiveSupport for example.
|
211
|
-
# @return [Hash<Symbol,Any>] Format: { ok: true/false, result:
|
219
|
+
# @return [Hash<Symbol,Any>] Format: { ok: true/false, result: Hash<Symbil,Numeric|String> }
|
212
220
|
#
|
213
221
|
# @api private
|
214
222
|
# @since 0.1.0
|
@@ -231,7 +239,7 @@ module RedisQueuedLocks::Acquier
|
|
231
239
|
})
|
232
240
|
end
|
233
241
|
|
234
|
-
{ ok: true, result:
|
242
|
+
{ ok: true, result: { rel_time: rel_time, rel_key: lock_key, rel_queue: lock_key_queue } }
|
235
243
|
end
|
236
244
|
|
237
245
|
# Release all locks:
|
@@ -241,7 +249,7 @@ module RedisQueuedLocks::Acquier
|
|
241
249
|
# @param redis [RedisClient] Redis connection client.
|
242
250
|
# @param batch_size [Integer] The number of lock keys that should be released in a time.
|
243
251
|
# @param isntrumenter [#notify] See RedisQueuedLocks::Instrument::ActiveSupport for example.
|
244
|
-
# @return [Hash<Symbol,Any>] Format: { ok: true/false, result:
|
252
|
+
# @return [Hash<Symbol,Any>] Format: { ok: true/false, result: Hash<Symbol,Numeric> }
|
245
253
|
#
|
246
254
|
# @api private
|
247
255
|
# @since 0.1.0
|
@@ -260,7 +268,7 @@ module RedisQueuedLocks::Acquier
|
|
260
268
|
})
|
261
269
|
end
|
262
270
|
|
263
|
-
{ ok: true, result: result }
|
271
|
+
{ ok: true, result: { rel_key_cnt: result[:rel_keys], rel_time: rel_time } }
|
264
272
|
end
|
265
273
|
|
266
274
|
private
|