redis_queued_locks 0.0.23 → 0.0.25
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 +9 -1
- data/README.md +17 -0
- data/lib/redis_queued_locks/acquier/acquire_lock/try_to_lock.rb +21 -0
- data/lib/redis_queued_locks/acquier/acquire_lock/yield_with_expire.rb +1 -1
- data/lib/redis_queued_locks/acquier/acquire_lock.rb +10 -3
- data/lib/redis_queued_locks/acquier/extend_lock_ttl.rb +1 -1
- data/lib/redis_queued_locks/acquier/release_all_locks.rb +1 -1
- data/lib/redis_queued_locks/acquier/release_lock.rb +1 -1
- data/lib/redis_queued_locks/client.rb +15 -1
- data/lib/redis_queued_locks/logging.rb +1 -1
- 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: 4c22d05a7cd7efbb64d23815a549ac668643635c764055cd74d4b935676e2c1f
|
4
|
+
data.tar.gz: 97325d6296b8cb5754bbad368226a9a5effe60528d7962419f5b4dbbd97f3b2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cffa3d5acfc3ec669d102eeec79ab81e1b3ccdd20cfe8ea3e6625a8acb3d847d0d8ed8343039ed042dfedb8ab5c0e4b928d3fca05c27ce0d75991772a0ebd77
|
7
|
+
data.tar.gz: 88702b3fecaac8f2e1857aed831e8d8ab5b1f871ee2248b76f27969257d695d9df8b0edb456995d39e985e05236068c95fd4b510bb25df6d7611f6eb6d9b9694
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.0.25] - 2024-03-21
|
4
|
+
### Changed
|
5
|
+
- Minor logs stylization;
|
6
|
+
|
7
|
+
## [0.0.24] - 2024-03-21
|
8
|
+
### Added
|
9
|
+
- An optional ability to log each try of lock obtaining (see `RedisQueuedLocks::Acquier::AcquireLock::TryToLock.try_to_lock`);
|
10
|
+
|
3
11
|
## [0.0.23] - 2024-03-21
|
4
12
|
### Changed
|
5
13
|
- Composed redis commands are invoked on the one conenction
|
6
|
-
(instead of mutiple connection
|
14
|
+
(instead of mutiple connection fetching from redis connection pool on each redis command);
|
7
15
|
|
8
16
|
## [0.0.22] - 2024-03-21
|
9
17
|
### Added
|
data/README.md
CHANGED
@@ -144,6 +144,11 @@ clinet = RedisQueuedLocks::Client.new(redis_client) do |config|
|
|
144
144
|
# - start of the lock expiration after `yield`: "[redis_queud_locks.expire_lock] lock_key => 'rql:lock:your_lock'"
|
145
145
|
# - by default uses VoidLogger that does nothing;
|
146
146
|
config.logger = RedisQueuedLocks::Logging::VoidLogger
|
147
|
+
|
148
|
+
# (default: false)
|
149
|
+
# - should be logged the each try of lock acquiring (a lot of logs can be generated depending on your retry configurations);
|
150
|
+
# - if logger is not cofnigured this option does not lead to any effect;
|
151
|
+
config.log_lock_try = false
|
147
152
|
end
|
148
153
|
```
|
149
154
|
|
@@ -187,6 +192,8 @@ def lock(
|
|
187
192
|
fail_fast: false,
|
188
193
|
identity: uniq_identity, # (attr_accessor) calculated during client instantiation via config[:uniq_identifier] proc;
|
189
194
|
metadata: nil,
|
195
|
+
logger: config[:logger],
|
196
|
+
log_lock_try: config[:log_lock_try],
|
190
197
|
&block
|
191
198
|
)
|
192
199
|
```
|
@@ -224,6 +231,12 @@ def lock(
|
|
224
231
|
ivar (accessed via `uniq_dentity` accessor method);
|
225
232
|
- `metadata` - `[NilClass,Any]`
|
226
233
|
- A custom metadata wich will be passed to the instrumenter's payload with `:meta` key;
|
234
|
+
- `logger` - `[::Logger,#debug]`
|
235
|
+
- Logger object used from the configuration layer (see config[:logger]);
|
236
|
+
- See `RedisQueuedLocks::Logging::VoidLogger` for example;
|
237
|
+
- `log_lock_try` - `[Boolean]`
|
238
|
+
- should be logged the each try of lock acquiring (a lot of logs can be generated depending on your retry configurations);
|
239
|
+
- see `config[:log_lock_try]`;
|
227
240
|
- `block` - `[Block]`
|
228
241
|
- A block of code that should be executed after the successfully acquired lock.
|
229
242
|
- If block is **passed** the obtained lock will be released after the block execution or it's ttl (what will happen first);
|
@@ -278,6 +291,8 @@ def lock!(
|
|
278
291
|
identity: uniq_identity,
|
279
292
|
fail_fast: false,
|
280
293
|
metadata: nil,
|
294
|
+
logger: config[:logger],
|
295
|
+
log_lock_try: config[:log_lock_try],
|
281
296
|
&block
|
282
297
|
)
|
283
298
|
```
|
@@ -597,6 +612,8 @@ Detalized event semantics and payload structure:
|
|
597
612
|
- `RedisQueuedLocks::Acquier::Try.try_to_lock` - detailed successful result analization;
|
598
613
|
- better code stylization and interesting refactorings;
|
599
614
|
- lock queue expiration (dead queue cleanup);
|
615
|
+
- support for `Dragonfly` DB backend;
|
616
|
+
- support for `Garnet` DB backend;
|
600
617
|
|
601
618
|
---
|
602
619
|
|
@@ -2,8 +2,14 @@
|
|
2
2
|
|
3
3
|
# @api private
|
4
4
|
# @since 0.1.0
|
5
|
+
# rubocop:disable Metrics/ModuleLength
|
5
6
|
module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
7
|
+
# @since 0.1.0
|
8
|
+
extend RedisQueuedLocks::Utilities
|
9
|
+
|
6
10
|
# @param redis [RedisClient]
|
11
|
+
# @param logger [::Logger,#debug]
|
12
|
+
# @param log_lock_try [Boolean]
|
7
13
|
# @param lock_key [String]
|
8
14
|
# @param lock_key_queue [String]
|
9
15
|
# @param acquier_id [String]
|
@@ -18,6 +24,8 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
18
24
|
# rubocop:disable Metrics/MethodLength
|
19
25
|
def try_to_lock(
|
20
26
|
redis,
|
27
|
+
logger,
|
28
|
+
log_lock_try,
|
21
29
|
lock_key,
|
22
30
|
lock_key_queue,
|
23
31
|
acquier_id,
|
@@ -30,8 +38,20 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
30
38
|
inter_result = nil
|
31
39
|
timestamp = nil
|
32
40
|
|
41
|
+
if log_lock_try
|
42
|
+
run_non_critical do
|
43
|
+
logger.debug("[redis_queued_locks.try_lock_start] lock_key => '#{lock_key}'")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
33
47
|
# Step 0: watch the lock key changes (and discard acquirement if lock is already acquired)
|
34
48
|
result = redis.with do |rconn|
|
49
|
+
if log_lock_try
|
50
|
+
run_non_critical do
|
51
|
+
logger.debug("[redis_queued_locks.try_lock_rconn_fetched] lock_key => '#{lock_key}'")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
35
55
|
rconn.multi(watch: [lock_key]) do |transact|
|
36
56
|
# Fast-Step X0: fail-fast check
|
37
57
|
if fail_fast && rconn.call('HGET', lock_key, 'acq_id')
|
@@ -182,3 +202,4 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
|
|
182
202
|
RedisQueuedLocks::Data[ok: true, result: result]
|
183
203
|
end
|
184
204
|
end
|
205
|
+
# rubocop:enable Metrics/ModuleLength
|
@@ -7,7 +7,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::YieldWithExpire
|
|
7
7
|
extend RedisQueuedLocks::Utilities
|
8
8
|
|
9
9
|
# @param redis [RedisClient] Redis connection manager.
|
10
|
-
# @param logger [
|
10
|
+
# @param logger [::Logger,#debug] Logger object.
|
11
11
|
# @param lock_key [String] Lock key to be expired.
|
12
12
|
# @param timed [Boolean] Should the lock be wrapped by Tiemlout with with lock's ttl
|
13
13
|
# @param ttl_shift [Float] Lock's TTL shifting. Should affect block's ttl. In millisecodns.
|
@@ -69,9 +69,13 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
69
69
|
# already obtained.
|
70
70
|
# @option metadata [NilClass,Any]
|
71
71
|
# - A custom metadata wich will be passed to the instrumenter's payload with :meta key;
|
72
|
-
# @option logger [
|
73
|
-
# - Logger object used from
|
72
|
+
# @option logger [::Logger,#debug]
|
73
|
+
# - Logger object used from the configuration layer (see config[:logger]);
|
74
74
|
# - See RedisQueuedLocks::Logging::VoidLogger for example;
|
75
|
+
# @option log_lock_try [Boolean]
|
76
|
+
# - should be logged the each try of lock acquiring (a lot of logs can be generated depending
|
77
|
+
# on your retry configurations);
|
78
|
+
# - see `config[:log_lock_try]`;
|
75
79
|
# @param [Block]
|
76
80
|
# A block of code that should be executed after the successfully acquired lock.
|
77
81
|
# @return [RedisQueuedLocks::Data,Hash<Symbol,Any>,yield]
|
@@ -100,6 +104,7 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
100
104
|
fail_fast:,
|
101
105
|
metadata:,
|
102
106
|
logger:,
|
107
|
+
log_lock_try:,
|
103
108
|
&block
|
104
109
|
)
|
105
110
|
# Step 1: prepare lock requirements (generate lock name, calc lock ttl, etc).
|
@@ -146,6 +151,8 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
146
151
|
while acq_process[:should_try]
|
147
152
|
try_to_lock(
|
148
153
|
redis,
|
154
|
+
logger,
|
155
|
+
log_lock_try,
|
149
156
|
lock_key,
|
150
157
|
lock_key_queue,
|
151
158
|
acquier_id,
|
@@ -167,7 +174,7 @@ module RedisQueuedLocks::Acquier::AcquireLock
|
|
167
174
|
run_non_critical do
|
168
175
|
logger.debug(
|
169
176
|
"[redis_queued_locks.lock_obtained] " \
|
170
|
-
"lock_key => '#{result[:lock_key]}'" \
|
177
|
+
"lock_key => '#{result[:lock_key]}' " \
|
171
178
|
"acq_time => #{acq_time} (ms)"
|
172
179
|
)
|
173
180
|
end
|
@@ -17,7 +17,7 @@ module RedisQueuedLocks::Acquier::ReleaseAllLocks
|
|
17
17
|
# The number of lock keys that should be released in a time.
|
18
18
|
# @param isntrumenter [#notify]
|
19
19
|
# See RedisQueuedLocks::Instrument::ActiveSupport for example.
|
20
|
-
# @param logger [
|
20
|
+
# @param logger [::Logger,#debug]
|
21
21
|
# - Logger object used from `configuration` layer (see config[:logger]);
|
22
22
|
# - See RedisQueuedLocks::Logging::VoidLogger for example;
|
23
23
|
# @return [RedisQueuedLocks::Data,Hash<Symbol,Any>]
|
@@ -20,7 +20,7 @@ module RedisQueuedLocks::Acquier::ReleaseLock
|
|
20
20
|
# The lock name that should be released.
|
21
21
|
# @param isntrumenter [#notify]
|
22
22
|
# See RedisQueuedLocks::Instrument::ActiveSupport for example.
|
23
|
-
# @param logger [
|
23
|
+
# @param logger [::Logger,#debug]
|
24
24
|
# - Logger object used from `configuration` layer (see config[:logger]);
|
25
25
|
# - See RedisQueuedLocks::Logging::VoidLogger for example;
|
26
26
|
# @return [RedisQueuedLocks::Data,Hash<Symbol,Any>]
|
@@ -19,6 +19,7 @@ class RedisQueuedLocks::Client
|
|
19
19
|
setting :instrumenter, RedisQueuedLocks::Instrument::VoidNotifier
|
20
20
|
setting :uniq_identifier, -> { RedisQueuedLocks::Resource.calc_uniq_identity }
|
21
21
|
setting :logger, RedisQueuedLocks::Logging::VoidLogger
|
22
|
+
setting :log_lock_try, false
|
22
23
|
|
23
24
|
validate('retry_count') { |val| val == nil || (val.is_a?(::Integer) && val >= 0) }
|
24
25
|
validate('retry_delay') { |val| val.is_a?(::Integer) && val >= 0 }
|
@@ -28,8 +29,9 @@ class RedisQueuedLocks::Client
|
|
28
29
|
validate('default_queue_ttl', :integer)
|
29
30
|
validate('lock_release_batch_size', :integer)
|
30
31
|
validate('instrumenter') { |val| RedisQueuedLocks::Instrument.valid_interface?(val) }
|
31
|
-
validate('logger') { |val| RedisQueuedLocks::Logging.valid_interface?(val) }
|
32
32
|
validate('uniq_identifier', :proc)
|
33
|
+
validate('logger') { |val| RedisQueuedLocks::Logging.valid_interface?(val) }
|
34
|
+
validate('log_lock_try', :boolean)
|
33
35
|
end
|
34
36
|
|
35
37
|
# @return [RedisClient]
|
@@ -93,6 +95,13 @@ class RedisQueuedLocks::Client
|
|
93
95
|
# by another process while the lock request queue was initially empty;
|
94
96
|
# @option metadata [NilClass,Any]
|
95
97
|
# - A custom metadata wich will be passed to the instrumenter's payload with :meta key;
|
98
|
+
# @option logger [::Logger,#debug]
|
99
|
+
# - Logger object used from the configuration layer (see config[:logger]);
|
100
|
+
# - See `RedisQueuedLocks::Logging::VoidLogger` for example;
|
101
|
+
# @option log_lock_try [Boolean]
|
102
|
+
# - should be logged the each try of lock acquiring (a lot of logs can
|
103
|
+
# be generated depending on your retry configurations);
|
104
|
+
# - see `config[:log_lock_try]`;
|
96
105
|
# @param block [Block]
|
97
106
|
# A block of code that should be executed after the successfully acquired lock.
|
98
107
|
# @return [RedisQueuedLocks::Data,Hash<Symbol,Any>,yield]
|
@@ -114,6 +123,8 @@ class RedisQueuedLocks::Client
|
|
114
123
|
fail_fast: false,
|
115
124
|
identity: uniq_identity,
|
116
125
|
metadata: nil,
|
126
|
+
logger: config[:logger],
|
127
|
+
log_lock_try: config[:log_lock_try],
|
117
128
|
&block
|
118
129
|
)
|
119
130
|
RedisQueuedLocks::Acquier::AcquireLock.acquire_lock(
|
@@ -136,6 +147,7 @@ class RedisQueuedLocks::Client
|
|
136
147
|
fail_fast:,
|
137
148
|
metadata:,
|
138
149
|
logger: config[:logger],
|
150
|
+
log_lock_try: config[:log_lock_try],
|
139
151
|
&block
|
140
152
|
)
|
141
153
|
end
|
@@ -156,6 +168,8 @@ class RedisQueuedLocks::Client
|
|
156
168
|
fail_fast: false,
|
157
169
|
identity: uniq_identity,
|
158
170
|
metadata: nil,
|
171
|
+
logger: config[:logger],
|
172
|
+
log_lock_try: config[:log_lock_try],
|
159
173
|
&block
|
160
174
|
)
|
161
175
|
lock(
|