redis_queued_locks 1.12.1 → 1.14.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.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -1
  3. data/.ruby-version +1 -1
  4. data/CHANGELOG.md +45 -5
  5. data/LICENSE.txt +1 -1
  6. data/README.md +574 -296
  7. data/Rakefile +12 -4
  8. data/Steepfile +15 -0
  9. data/github_ci/ruby3.3.gemfile +17 -0
  10. data/github_ci/ruby3.3.gemfile.lock +217 -0
  11. data/lib/redis_queued_locks/{acquier → acquirer}/acquire_lock/delay_execution.rb +4 -4
  12. data/lib/redis_queued_locks/acquirer/acquire_lock/dequeue_from_lock_queue/log_visitor.rb +40 -0
  13. data/lib/redis_queued_locks/{acquier → acquirer}/acquire_lock/dequeue_from_lock_queue.rb +17 -8
  14. data/lib/redis_queued_locks/acquirer/acquire_lock/instr_visitor.rb +166 -0
  15. data/lib/redis_queued_locks/acquirer/acquire_lock/log_visitor.rb +218 -0
  16. data/lib/redis_queued_locks/acquirer/acquire_lock/try_to_lock/log_visitor.rb +543 -0
  17. data/lib/redis_queued_locks/{acquier → acquirer}/acquire_lock/try_to_lock.rb +126 -92
  18. data/lib/redis_queued_locks/{acquier → acquirer}/acquire_lock/with_acq_timeout.rb +14 -9
  19. data/lib/redis_queued_locks/acquirer/acquire_lock/yield_expire/log_visitor.rb +76 -0
  20. data/lib/redis_queued_locks/{acquier → acquirer}/acquire_lock/yield_expire.rb +42 -19
  21. data/lib/redis_queued_locks/{acquier → acquirer}/acquire_lock.rb +74 -47
  22. data/lib/redis_queued_locks/{acquier → acquirer}/clear_dead_requests.rb +5 -3
  23. data/lib/redis_queued_locks/{acquier → acquirer}/extend_lock_ttl.rb +4 -3
  24. data/lib/redis_queued_locks/{acquier → acquirer}/is_locked.rb +1 -1
  25. data/lib/redis_queued_locks/{acquier → acquirer}/is_queued.rb +1 -1
  26. data/lib/redis_queued_locks/{acquier → acquirer}/keys.rb +5 -5
  27. data/lib/redis_queued_locks/{acquier → acquirer}/lock_info.rb +9 -5
  28. data/lib/redis_queued_locks/{acquier → acquirer}/locks.rb +16 -3
  29. data/lib/redis_queued_locks/{acquier → acquirer}/queue_info.rb +8 -6
  30. data/lib/redis_queued_locks/{acquier → acquirer}/queues.rb +9 -2
  31. data/lib/redis_queued_locks/{acquier → acquirer}/release_all_locks.rb +26 -21
  32. data/lib/redis_queued_locks/{acquier → acquirer}/release_lock.rb +28 -22
  33. data/lib/redis_queued_locks/acquirer/release_locks_of.rb +211 -0
  34. data/lib/redis_queued_locks/acquirer.rb +19 -0
  35. data/lib/redis_queued_locks/client.rb +317 -254
  36. data/lib/redis_queued_locks/config/dsl.rb +94 -0
  37. data/lib/redis_queued_locks/config.rb +236 -0
  38. data/lib/redis_queued_locks/data.rb +2 -0
  39. data/lib/redis_queued_locks/errors.rb +27 -11
  40. data/lib/redis_queued_locks/instrument.rb +11 -4
  41. data/lib/redis_queued_locks/logging/void_logger.rb +38 -1
  42. data/lib/redis_queued_locks/logging.rb +20 -5
  43. data/lib/redis_queued_locks/resource.rb +49 -11
  44. data/lib/redis_queued_locks/swarm/acquirers.rb +17 -16
  45. data/lib/redis_queued_locks/swarm/flush_zombies.rb +26 -25
  46. data/lib/redis_queued_locks/swarm/probe_hosts.rb +20 -19
  47. data/lib/redis_queued_locks/swarm/redis_client_builder.rb +3 -3
  48. data/lib/redis_queued_locks/swarm/supervisor.rb +19 -6
  49. data/lib/redis_queued_locks/swarm/swarm_element/isolated.rb +20 -18
  50. data/lib/redis_queued_locks/swarm/swarm_element/threaded.rb +35 -27
  51. data/lib/redis_queued_locks/swarm/zombie_info.rb +9 -9
  52. data/lib/redis_queued_locks/swarm.rb +20 -41
  53. data/lib/redis_queued_locks/utilities.rb +11 -2
  54. data/lib/redis_queued_locks/version.rb +2 -2
  55. data/lib/redis_queued_locks.rb +2 -3
  56. data/rbs_collection.lock.yaml +28 -0
  57. data/rbs_collection.yaml +17 -0
  58. data/redis_queued_locks.gemspec +22 -23
  59. data/sig/manifest.yml +6 -0
  60. data/sig/redis_queued_locks/acquier.rbs +4 -0
  61. data/sig/redis_queued_locks/acquirer/acquire_lock/delay_execution.rbs +9 -0
  62. data/sig/redis_queued_locks/acquirer/acquire_lock/dequeue_from_lock_queue/log_visitor.rbs +21 -0
  63. data/sig/redis_queued_locks/acquirer/acquire_lock/dequeue_from_lock_queue.rbs +26 -0
  64. data/sig/redis_queued_locks/acquirer/acquire_lock/instr_visitor.rbs +71 -0
  65. data/sig/redis_queued_locks/acquirer/acquire_lock/log_visitor.rbs +72 -0
  66. data/sig/redis_queued_locks/acquirer/acquire_lock/try_to_lock/log_visitor.rbs +179 -0
  67. data/sig/redis_queued_locks/acquirer/acquire_lock/try_to_lock.rbs +48 -0
  68. data/sig/redis_queued_locks/acquirer/acquire_lock/with_acq_timeout.rbs +19 -0
  69. data/sig/redis_queued_locks/acquirer/acquire_lock/yield_expire.rbs +41 -0
  70. data/sig/redis_queued_locks/acquirer/acquire_lock/yield_with_expire/log_visitor.rbs +32 -0
  71. data/sig/redis_queued_locks/acquirer/acquire_lock.rbs +52 -0
  72. data/sig/redis_queued_locks/acquirer/clear_dead_requests.rbs +28 -0
  73. data/sig/redis_queued_locks/acquirer/extend_lock_ttl.rbs +28 -0
  74. data/sig/redis_queued_locks/acquirer/is_locked.rbs +9 -0
  75. data/sig/redis_queued_locks/acquirer/is_queued.rbs +9 -0
  76. data/sig/redis_queued_locks/acquirer/keys.rbs +10 -0
  77. data/sig/redis_queued_locks/acquirer/lock_info.rbs +10 -0
  78. data/sig/redis_queued_locks/acquirer/locks.rbs +16 -0
  79. data/sig/redis_queued_locks/acquirer/queue_info.rbs +13 -0
  80. data/sig/redis_queued_locks/acquirer/queues.rbs +16 -0
  81. data/sig/redis_queued_locks/acquirer/release_all_locks.rbs +30 -0
  82. data/sig/redis_queued_locks/acquirer/release_lock.rbs +38 -0
  83. data/sig/redis_queued_locks/acquirer/release_locks_of.rbs +46 -0
  84. data/sig/redis_queued_locks/client.rbs +235 -0
  85. data/sig/redis_queued_locks/config/dsl.rbs +26 -0
  86. data/sig/redis_queued_locks/config.rbs +23 -0
  87. data/sig/redis_queued_locks/data.rbs +4 -0
  88. data/sig/redis_queued_locks/debugger/interface.rbs +9 -0
  89. data/sig/redis_queued_locks/debugger.rbs +13 -0
  90. data/sig/redis_queued_locks/errors.rbs +43 -0
  91. data/sig/redis_queued_locks/instrument/active_support.rbs +7 -0
  92. data/sig/redis_queued_locks/instrument/sampler.rbs +9 -0
  93. data/sig/redis_queued_locks/instrument/void_notifier.rbs +7 -0
  94. data/sig/redis_queued_locks/instrument.rbs +15 -0
  95. data/sig/redis_queued_locks/logging/sampler.rbs +9 -0
  96. data/sig/redis_queued_locks/logging/void_logger.rbs +15 -0
  97. data/sig/redis_queued_locks/logging.rbs +15 -0
  98. data/sig/redis_queued_locks/resource.rbs +42 -0
  99. data/sig/redis_queued_locks/swarm/acquirers.rbs +10 -0
  100. data/sig/redis_queued_locks/swarm/flush_zombies.rbs +13 -0
  101. data/sig/redis_queued_locks/swarm/probe_hosts.rbs +13 -0
  102. data/sig/redis_queued_locks/swarm/redis_client_builder.rbs +19 -0
  103. data/sig/redis_queued_locks/swarm/supervisor.rbs +26 -0
  104. data/sig/redis_queued_locks/swarm/swarm_element/isolated.rbs +52 -0
  105. data/sig/redis_queued_locks/swarm/swarm_element/threaded.rbs +61 -0
  106. data/sig/redis_queued_locks/swarm/swarm_element.rbs +8 -0
  107. data/sig/redis_queued_locks/swarm/zombie_info.rbs +24 -0
  108. data/sig/redis_queued_locks/swarm.rbs +41 -0
  109. data/sig/redis_queued_locks/utilities/lock.rbs +10 -0
  110. data/sig/redis_queued_locks/utilities.rbs +12 -0
  111. data/sig/redis_queued_locks/version.rbs +3 -0
  112. data/sig/redis_queued_locks.rbs +14 -0
  113. data/sig/vendor/active_support.rbs +9 -0
  114. data/sig/vendor/redis_client.rbs +39 -0
  115. data/sig/vendor/semantic_logger.rbs +4 -0
  116. metadata +98 -54
  117. data/lib/redis_queued_locks/acquier/acquire_lock/dequeue_from_lock_queue/log_visitor.rb +0 -40
  118. data/lib/redis_queued_locks/acquier/acquire_lock/instr_visitor.rb +0 -166
  119. data/lib/redis_queued_locks/acquier/acquire_lock/log_visitor.rb +0 -216
  120. data/lib/redis_queued_locks/acquier/acquire_lock/try_to_lock/log_visitor.rb +0 -541
  121. data/lib/redis_queued_locks/acquier/acquire_lock/yield_expire/log_visitor.rb +0 -76
  122. data/lib/redis_queued_locks/acquier.rb +0 -18
@@ -2,122 +2,9 @@
2
2
 
3
3
  # @api public
4
4
  # @since 1.0.0
5
+ # @version 1.14.0
5
6
  # rubocop:disable Metrics/ClassLength
6
7
  class RedisQueuedLocks::Client
7
- # @since 1.0.0
8
- include Qonfig::Configurable
9
-
10
- configuration do
11
- setting :retry_count, 3
12
- setting :retry_delay, 200 # NOTE: in milliseconds
13
- setting :retry_jitter, 25 # NOTE: in milliseconds
14
- setting :try_to_lock_timeout, 10 # NOTE: in seconds
15
- setting :default_lock_ttl, 5_000 # NOTE: in milliseconds
16
- setting :default_queue_ttl, 15 # NOTE: in seconds
17
- setting :detailed_acq_timeout_error, false
18
- setting :lock_release_batch_size, 100
19
- setting :key_extraction_batch_size, 500
20
- setting :instrumenter, RedisQueuedLocks::Instrument::VoidNotifier
21
- setting :uniq_identifier, -> { RedisQueuedLocks::Resource.calc_uniq_identity }
22
- setting :logger, RedisQueuedLocks::Logging::VoidLogger
23
- setting :log_lock_try, false
24
- setting :dead_request_ttl, (1 * 24 * 60 * 60 * 1000) # NOTE: 1 day in milliseconds
25
- setting :is_timed_by_default, false
26
- setting :default_conflict_strategy, :wait_for_lock
27
- setting :default_access_strategy, :queued
28
- setting :log_sampling_enabled, false
29
- setting :log_sampling_percent, 15
30
- setting :log_sampler, RedisQueuedLocks::Logging::Sampler
31
- setting :instr_sampling_enabled, false
32
- setting :instr_sampling_percent, 15
33
- setting :instr_sampler, RedisQueuedLocks::Instrument::Sampler
34
-
35
- setting :swarm do
36
- setting :auto_swarm, false
37
- setting :supervisor do
38
- setting :liveness_probing_period, 2 # NOTE: in seconds
39
- end
40
- setting :probe_hosts do
41
- setting :enabled_for_swarm, true
42
- setting :redis_config do
43
- setting :sentinel, false
44
- setting :pooled, false
45
- setting :config, {}
46
- setting :pool_config, {}
47
- end
48
- setting :probe_period, 2 # NOTE: in seconds
49
- end
50
- setting :flush_zombies do
51
- setting :enabled_for_swarm, true
52
- setting :redis_config do
53
- setting :sentinel, false
54
- setting :pooled, false
55
- setting :config, {}
56
- setting :pool_config, {}
57
- end
58
- setting :zombie_ttl, 15_000 # NOTE: in milliseconds
59
- setting :zombie_lock_scan_size, 500
60
- setting :zombie_queue_scan_size, 500
61
- setting :zombie_flush_period, 10 # NOTE: in seconds
62
- end
63
- end
64
-
65
- validate('swarm.auto_swarm', :boolean)
66
- validate('swarm.visor.liveness_probing_period', :integer)
67
-
68
- validate('swarm.probe_hosts.enabled_for_swarm', :boolean)
69
- validate('swarm.probe_hosts.redis_config.sentinel', :boolean)
70
- validate('swarm.probe_hosts.redis_config.pooled', :boolean)
71
- validate('swarm.probe_hosts.redis_config.config', :hash)
72
- validate('swarm.probe_hosts.redis_config.pool_config', :hash)
73
- validate('swarm.probe_hosts.probe_period', :integer)
74
-
75
- validate('swarm.flush_zombies.enabled_for_swarm', :boolean)
76
- validate('swarm.flush_zombies.redis_config.sentinel', :boolean)
77
- validate('swarm.flush_zombies.redis_config.pooled', :boolean)
78
- validate('swarm.flush_zombies.redis_config.config', :hash)
79
- validate('swarm.flush_zombies.redis_config.pool_config', :hash)
80
- validate('swarm.flush_zombies.zombie_ttl', :integer)
81
- validate('swarm.flush_zombies.zombie_lock_scan_size', :integer)
82
- validate('swarm.flush_zombies.zombie_queue_scan_size', :integer)
83
- validate('swarm.flush_zombies.zombie_flush_period', :integer)
84
-
85
- validate('retry_count') { |val| val == nil || (val.is_a?(::Integer) && val >= 0) }
86
- validate('retry_delay') { |val| val.is_a?(::Integer) && val >= 0 }
87
- validate('retry_jitter') { |val| val.is_a?(::Integer) && val >= 0 }
88
- validate('try_to_lock_timeout') { |val| val == nil || (val.is_a?(::Integer) && val >= 0) }
89
- validate('default_lock_tt', :integer)
90
- validate('default_queue_ttl', :integer)
91
- validate('detailed_acq_timeout_error', :boolean)
92
- validate('lock_release_batch_size', :integer)
93
- validate('instrumenter') { |val| RedisQueuedLocks::Instrument.valid_interface?(val) }
94
- validate('uniq_identifier', :proc)
95
- validate('logger') { |val| RedisQueuedLocks::Logging.valid_interface?(val) }
96
- validate('log_lock_try', :boolean)
97
- validate('dead_request_ttl') { |val| val.is_a?(::Integer) && val > 0 }
98
- validate('is_timed_by_default', :boolean)
99
- validate('log_sampler') { |val| RedisQueuedLocks::Logging.valid_sampler?(val) }
100
- validate('log_sampling_enabled', :boolean)
101
- validate('log_sampling_percent') { |val| val.is_a?(::Integer) && val >= 0 && val <= 100 }
102
- validate('instr_sampling_enabled', :boolean)
103
- validate('instr_sampling_percent') { |val| val.is_a?(::Integer) && val >= 0 && val <= 100 }
104
- validate('instr_sampler') { |val| RedisQueuedLocks::Instrument.valid_sampler?(val) }
105
- validate('default_conflict_strategy') do |val|
106
- # rubocop:disable Layout/MultilineOperationIndentation
107
- val == :work_through ||
108
- val == :extendable_work_through ||
109
- val == :wait_for_lock ||
110
- val == :dead_locking
111
- # rubocop:enable Layout/MultilineOperationIndentation
112
- end
113
- validate('default_access_strategy') do |val|
114
- # rubocop:disable Layout/MultilineOperationIndentation
115
- val == :queued ||
116
- val == :random
117
- # rubocop:enable Layout/MultilineOperationIndentation
118
- end
119
- end
120
-
121
8
  # @return [RedisClient]
122
9
  #
123
10
  # @api private
@@ -138,20 +25,37 @@ class RedisQueuedLocks::Client
138
25
  # @since 1.9.0
139
26
  attr_reader :swarm
140
27
 
28
+ # @return [RedisQueuedLocks::Config]
29
+ #
30
+ # @api public
31
+ # @since 1.13.0
32
+ attr_reader :config
33
+
141
34
  # @param redis_client [RedisClient]
142
- # Redis connection manager, which will be used for the lock acquierment and distribution.
35
+ # Redis connection manager, which will be used for the lock acquirerment and distribution.
143
36
  # It should be an instance of RedisClient.
144
- # @param configs [Block]
37
+ # @param configuration [Block]
145
38
  # Custom configs for in-runtime configuration.
146
39
  # @return [void]
147
40
  #
148
41
  # @api public
149
42
  # @since 1.0.0
150
- def initialize(redis_client, &configs)
151
- configure(&configs)
152
- @uniq_identity = config[:uniq_identifier].call
43
+ # @version 1.13.0
44
+ def initialize(redis_client, &configuration)
45
+ @config = RedisQueuedLocks::Config.new(&configuration)
46
+ @uniq_identity = config['uniq_identifier'].call #: String
153
47
  @redis_client = redis_client
154
- @swarm = RedisQueuedLocks::Swarm.new(self).tap { |s| s.swarm! if config[:swarm][:auto_swarm] }
48
+ @swarm = RedisQueuedLocks::Swarm.new(self)
49
+ @swarm.swarm! if config['swarm.auto_swarm']
50
+ end
51
+
52
+ # @param configuration [Block]
53
+ # @return [void]
54
+ #
55
+ # @api public
56
+ # @since 1.13.0
57
+ def configure(&configuration)
58
+ config.configure(&configuration)
155
59
  end
156
60
 
157
61
  # @return [Hash<Symbol,Boolean|Symbol>]
@@ -175,7 +79,7 @@ class RedisQueuedLocks::Client
175
79
  #
176
80
  # @api public
177
81
  # @since 1.9.0
178
- def swarm_info(zombie_ttl: config[:swarm][:flush_zombies][:zombie_ttl])
82
+ def swarm_info(zombie_ttl: config['swarm.flush_zombies.zombie_ttl']) # steep:ignore
179
83
  swarm.swarm_info(zombie_ttl:)
180
84
  end
181
85
 
@@ -204,9 +108,9 @@ class RedisQueuedLocks::Client
204
108
  # @api public
205
109
  # @since 1.9.0
206
110
  def flush_zombies(
207
- zombie_ttl: config[:swarm][:flush_zombies][:zombie_ttl],
208
- lock_scan_size: config[:swarm][:flush_zombies][:zombie_lock_scan_size],
209
- queue_scan_size: config[:swarm][:flush_zombies][:zombie_queue_scan_size]
111
+ zombie_ttl: config['swarm.flush_zombies.zombie_ttl'], # steep:ignore
112
+ lock_scan_size: config['swarm.flush_zombies.zombie_lock_scan_size'], # steep:ignore
113
+ queue_scan_size: config['swarm.flush_zombies.zombie_queue_scan_size'] # steep:ignore
210
114
  )
211
115
  swarm.flush_zombies(zombie_ttl:, lock_scan_size:, queue_scan_size:)
212
116
  end
@@ -218,8 +122,8 @@ class RedisQueuedLocks::Client
218
122
  # @api public
219
123
  # @since 1.9.0
220
124
  def zombie_locks(
221
- zombie_ttl: config[:swarm][:flush_zombies][:zombie_ttl],
222
- lock_scan_size: config[:swarm][:flush_zombies][:zombie_lock_scan_size]
125
+ zombie_ttl: config['swarm.flush_zombies.zombie_ttl'], # steep:ignore
126
+ lock_scan_size: config['swarm.flush_zombies.zombie_lock_scan_size'] # steep:ignore
223
127
  )
224
128
  swarm.zombie_locks(zombie_ttl:, lock_scan_size:)
225
129
  end
@@ -230,11 +134,11 @@ class RedisQueuedLocks::Client
230
134
  #
231
135
  # @api ppublic
232
136
  # @since 1.9.0
233
- def zombie_acquiers(
234
- zombie_ttl: config[:swarm][:flush_zombies][:zombie_ttl],
235
- lock_scan_size: config[:swarm][:flush_zombies][:zombie_lock_scan_size]
137
+ def zombie_acquirers(
138
+ zombie_ttl: config['swarm.flush_zombies.zombie_ttl'], # steep:ignore
139
+ lock_scan_size: config['swarm.flush_zombies.zombie_lock_scan_size'] # steep:ignore
236
140
  )
237
- swarm.zombie_acquiers(zombie_ttl:, lock_scan_size:)
141
+ swarm.zombie_acquirers(zombie_ttl:, lock_scan_size:)
238
142
  end
239
143
 
240
144
  # @option zombie_ttl [Integer]
@@ -242,22 +146,22 @@ class RedisQueuedLocks::Client
242
146
  #
243
147
  # @api public
244
148
  # @since 1.9.0
245
- def zombie_hosts(zombie_ttl: config[:swarm][:flush_zombies][:zombie_ttl])
149
+ def zombie_hosts(zombie_ttl: config['swarm.flush_zombies.zombie_ttl']) # steep:ignore
246
150
  swarm.zombie_hosts(zombie_ttl:)
247
151
  end
248
152
 
249
153
  # @return [Hash<Symbol,Set<String>>]
250
154
  # Format: {
251
155
  # zombie_hosts: <Set<String>>,
252
- # zombie_acquiers: <Set<String>>,
156
+ # zombie_acquirers: <Set<String>>,
253
157
  # zombie_locks: <Set<String>>
254
158
  # }
255
159
  #
256
160
  # @api public
257
161
  # @since 1.9.0
258
162
  def zombies_info(
259
- zombie_ttl: config[:swarm][:flush_zombies][:zombie_ttl],
260
- lock_scan_size: config[:swarm][:flush_zombies][:zombie_ttl]
163
+ zombie_ttl: config['swarm.flush_zombies.zombie_ttl'], # steep:ignore
164
+ lock_scan_size: config['swarm.flush_zombies.zombie_ttl'] # steep:ignore
261
165
  )
262
166
  swarm.zombies_info(zombie_ttl:, lock_scan_size:)
263
167
  end
@@ -294,13 +198,15 @@ class RedisQueuedLocks::Client
294
198
  # - The conflict strategy mode for cases when the process that obtained the lock
295
199
  # want to acquire this lock again;
296
200
  # - By default uses `:wait_for_lock` strategy;
297
- # - pre-confured in `config[:default_conflict_strategy]`;
201
+ # - pre-confured in `config['default_conflict_strategy']`;
298
202
  # - Supports:
299
203
  # - `:work_through` - continue working under the lock without lock's TTL extension;
300
204
  # - `:extendable_work_through` - continue working under the lock with lock's TTL extension;
301
205
  # - `:wait_for_lock` - (default) - work in classic way
302
206
  # (with timeouts, retry delays, retry limits, etc - in classic way :));
303
207
  # - `:dead_locking` - fail with deadlock exception;
208
+ # @option read_write_mode [Symbol]
209
+ # - ?
304
210
  # @option access_strategy [Symbol]
305
211
  # - The way in which the lock will be obtained;
306
212
  # - By default it uses `:queued` strategy;
@@ -310,7 +216,7 @@ class RedisQueuedLocks::Client
310
216
  # - `:random` (RANDOM): obtain a lock without checking the positions in the queue
311
217
  # (but with checking the limist, retries, timeouts and so on). if lock is
312
218
  # free to obtain - it will be obtained;
313
- # - pre-configured in `config[:default_access_strategy]`;
219
+ # - pre-configured in `config['default_access_strategy']`;
314
220
  # @option meta [NilClass,Hash<String|Symbol,Any>]
315
221
  # - A custom metadata wich will be passed to the lock data in addition to the existing data;
316
222
  # - Metadata can not contain reserved lock data keys;
@@ -334,20 +240,20 @@ class RedisQueuedLocks::Client
334
240
  # and moved from the lock queue after the error moment and before the error message build;
335
241
  # - You should consider the async nature of this error message and should use received data
336
242
  # from error message correspondingly;
337
- # - pre-configred in `config[:detailed_acq_timeout_error]`;
243
+ # - pre-configred in `config['detailed_acq_timeout_error']`;
338
244
  # @option logger [::Logger,#debug]
339
- # - Logger object used from the configuration layer (see config[:logger]);
245
+ # - Logger object used from the configuration layer (see config['logger']);
340
246
  # - See `RedisQueuedLocks::Logging::VoidLogger` for example;
341
247
  # - Supports `SemanticLogger::Logger` (see "semantic_logger" gem)
342
248
  # @option log_lock_try [Boolean]
343
249
  # - should be logged the each try of lock acquiring (a lot of logs can
344
250
  # be generated depending on your retry configurations);
345
- # - see `config[:log_lock_try]`;
251
+ # - see `config['log_lock_try']`;
346
252
  # @option instrumenter [#notify]
347
253
  # - Custom instrumenter that will be invoked via #notify method with `event` and `payload` data;
348
254
  # - See RedisQueuedLocks::Instrument::ActiveSupport for examples and implementation details;
349
255
  # - See [Instrumentation](#instrumentation) section of docs;
350
- # - pre-configured in `config[:isntrumenter]` with void notifier
256
+ # - pre-configured in `config['isntrumenter']` with void notifier
351
257
  # (`RedisQueuedLocks::Instrumenter::VoidNotifier`);
352
258
  # @option instrument [NilClass,Any]
353
259
  # - Custom instrumentation data wich will be passed to the instrumenter's payload
@@ -355,15 +261,15 @@ class RedisQueuedLocks::Client
355
261
  # @option log_sampling_enabled [Boolean]
356
262
  # - enables <log sampling>: only the configured percent of RQL cases will be logged;
357
263
  # - disabled by default;
358
- # - works in tandem with <config.log_sampling_percent and <log.sampler>;
264
+ # - works in tandem with <config['log_sampling_percent'] and <config['log_sampler']>;
359
265
  # @option log_sampling_percent [Integer]
360
266
  # - the percent of cases that should be logged;
361
- # - take an effect when <config.log_sampling_enalbed> is true;
362
- # - works in tandem with <config.log_sampling_enabled> and <config.log_sampler> configs;
267
+ # - take an effect when <config['log_sampling_enalbed']> is true;
268
+ # - works in tandem with <config['log_sampling_enabled']> and <config['log_sampler']> configs;
363
269
  # @option log_sampler [#sampling_happened?,Module<RedisQueuedLocks::Logging::Sampler>]
364
270
  # - percent-based log sampler that decides should be RQL case logged or not;
365
- # - works in tandem with <config.log_sampling_enabled> and
366
- # <config.log_sampling_percent> configs;
271
+ # - works in tandem with <config['log_sampling_enabled']> and
272
+ # <config['log_sampling_percent']> configs;
367
273
  # - based on the ultra simple percent-based (weight-based) algorithm that uses SecureRandom.rand
368
274
  # method so the algorithm error is ~(0%..13%);
369
275
  # - you can provide your own log sampler with bettter algorithm that should realize
@@ -376,15 +282,16 @@ class RedisQueuedLocks::Client
376
282
  # - enables <instrumentaion sampling>: only the configured percent
377
283
  # of RQL cases will be instrumented;
378
284
  # - disabled by default;
379
- # - works in tandem with <config.instr_sampling_percent and <log.instr_sampler>;
285
+ # - works in tandem with <config['instr_sampling_percent']> and <config['instr_sampler']>;
380
286
  # @option instr_sampling_percent [Integer]
381
287
  # - the percent of cases that should be instrumented;
382
- # - take an effect when <config.instr_sampling_enalbed> is true;
383
- # - works in tandem with <config.instr_sampling_enabled> and <config.instr_sampler> configs;
288
+ # - take an effect when <config['instr_sampling_enalbed']> is true;
289
+ # - works in tandem with <config['instr_sampling_enabled']>
290
+ # and <config['instr_sampler']> configs;
384
291
  # @option instr_sampler [#sampling_happened?,Module<RedisQueuedLocks::Instrument::Sampler>]
385
292
  # - percent-based log sampler that decides should be RQL case instrumented or not;
386
- # - works in tandem with <config.instr_sampling_enabled> and
387
- # <config.instr_sampling_percent> configs;
293
+ # - works in tandem with <config['instr_sampling_enabled']> and
294
+ # <config['instr_sampling_percent']> configs;
388
295
  # - based on the ultra simple percent-based (weight-based) algorithm that uses SecureRandom.rand
389
296
  # method so the algorithm error is ~(0%..13%);
390
297
  # - you can provide your own log sampler with bettter algorithm that should realize
@@ -396,45 +303,46 @@ class RedisQueuedLocks::Client
396
303
  # - makes sense when instrumentation sampling is enabled;
397
304
  # @param block [Block]
398
305
  # A block of code that should be executed after the successfully acquired lock.
399
- # @return [RedisQueuedLocks::Data,Hash<Symbol,Any>,yield]
306
+ # @return [Hash<Symbol,Any>,yield]
400
307
  # - Format: { ok: true/false, result: Symbol/Hash }.
401
308
  # - If block is given the result of block's yeld will be returned.
402
309
  #
403
310
  # @api public
404
311
  # @since 1.0.0
405
- # @version 1.8.0
312
+ # @version 1.13.0
406
313
  # rubocop:disable Metrics/MethodLength
407
314
  def lock(
408
315
  lock_name,
409
- ttl: config[:default_lock_ttl],
410
- queue_ttl: config[:default_queue_ttl],
411
- timeout: config[:try_to_lock_timeout],
412
- timed: config[:is_timed_by_default],
413
- retry_count: config[:retry_count],
414
- retry_delay: config[:retry_delay],
415
- retry_jitter: config[:retry_jitter],
316
+ ttl: config['default_lock_ttl'], # steep:ignore
317
+ queue_ttl: config['default_queue_ttl'], # steep:ignore
318
+ timeout: config['try_to_lock_timeout'], # steep:ignore
319
+ timed: config['is_timed_by_default'], # steep:ignore
320
+ retry_count: config['retry_count'], # steep:ignore
321
+ retry_delay: config['retry_delay'], # steep:ignore
322
+ retry_jitter: config['retry_jitter'], # steep:ignore
416
323
  raise_errors: false,
417
324
  fail_fast: false,
418
- conflict_strategy: config[:default_conflict_strategy],
419
- access_strategy: config[:default_access_strategy],
325
+ conflict_strategy: config['default_conflict_strategy'], # steep:ignore
326
+ read_write_mode: :write,
327
+ access_strategy: config['default_access_strategy'], # steep:ignore
420
328
  identity: uniq_identity,
421
329
  meta: nil,
422
- detailed_acq_timeout_error: config[:detailed_acq_timeout_error],
423
- logger: config[:logger],
424
- log_lock_try: config[:log_lock_try],
425
- instrumenter: config[:instrumenter],
330
+ detailed_acq_timeout_error: config['detailed_acq_timeout_error'], # steep:ignore
331
+ logger: config['logger'], # steep:ignore
332
+ log_lock_try: config['log_lock_try'], # steep:ignore
333
+ instrumenter: config['instrumenter'], # steep:ignore
426
334
  instrument: nil,
427
- log_sampling_enabled: config[:log_sampling_enabled],
428
- log_sampling_percent: config[:log_sampling_percent],
429
- log_sampler: config[:log_sampler],
335
+ log_sampling_enabled: config['log_sampling_enabled'], # steep:ignore
336
+ log_sampling_percent: config['log_sampling_percent'], # steep:ignore
337
+ log_sampler: config['log_sampler'], # steep:ignore
430
338
  log_sample_this: false,
431
- instr_sampling_enabled: config[:instr_sampling_enabled],
432
- instr_sampling_percent: config[:instr_sampling_percent],
433
- instr_sampler: config[:instr_sampler],
339
+ instr_sampling_enabled: config['instr_sampling_enabled'], # steep:ignore
340
+ instr_sampling_percent: config['instr_sampling_percent'], # steep:ignore
341
+ instr_sampler: config['instr_sampler'], # steep:ignore
434
342
  instr_sample_this: false,
435
343
  &block
436
344
  )
437
- RedisQueuedLocks::Acquier::AcquireLock.acquire_lock(
345
+ RedisQueuedLocks::Acquirer::AcquireLock.acquire_lock(
438
346
  redis_client,
439
347
  lock_name,
440
348
  process_id: RedisQueuedLocks::Resource.get_process_id,
@@ -453,6 +361,7 @@ class RedisQueuedLocks::Client
453
361
  identity:,
454
362
  fail_fast:,
455
363
  conflict_strategy:,
364
+ read_write_mode:,
456
365
  access_strategy:,
457
366
  meta:,
458
367
  detailed_acq_timeout_error:,
@@ -476,34 +385,35 @@ class RedisQueuedLocks::Client
476
385
  #
477
386
  # @api public
478
387
  # @since 1.0.0
479
- # @version 1.8.0
388
+ # @version 1.13.0
480
389
  # rubocop:disable Metrics/MethodLength
481
390
  def lock!(
482
391
  lock_name,
483
- ttl: config[:default_lock_ttl],
484
- queue_ttl: config[:default_queue_ttl],
485
- timeout: config[:try_to_lock_timeout],
486
- timed: config[:is_timed_by_default],
487
- retry_count: config[:retry_count],
488
- retry_delay: config[:retry_delay],
489
- retry_jitter: config[:retry_jitter],
392
+ ttl: config['default_lock_ttl'], # steep:ignore
393
+ queue_ttl: config['default_queue_ttl'], # steep:ignore
394
+ timeout: config['try_to_lock_timeout'], # steep:ignore
395
+ timed: config['is_timed_by_default'], # steep:ignore
396
+ retry_count: config['retry_count'], # steep:ignore
397
+ retry_delay: config['retry_delay'], # steep:ignore
398
+ retry_jitter: config['retry_jitter'], # steep:ignore
490
399
  fail_fast: false,
491
- conflict_strategy: config[:default_conflict_strategy],
492
- access_strategy: config[:default_access_strategy],
400
+ conflict_strategy: config['default_conflict_strategy'], # steep:ignore
401
+ read_write_mode: :write,
402
+ access_strategy: config['default_access_strategy'], # steep:ignore
493
403
  identity: uniq_identity,
494
- instrumenter: config[:instrumenter],
404
+ instrumenter: config['instrumenter'], # steep:ignore
495
405
  meta: nil,
496
- detailed_acq_timeout_error: config[:detailed_acq_timeout_error],
497
- logger: config[:logger],
498
- log_lock_try: config[:log_lock_try],
406
+ detailed_acq_timeout_error: config['detailed_acq_timeout_error'], # steep:ignore
407
+ logger: config['logger'], # steep:ignore
408
+ log_lock_try: config['log_lock_try'], # steep:ignore
499
409
  instrument: nil,
500
- log_sampling_enabled: config[:log_sampling_enabled],
501
- log_sampling_percent: config[:log_sampling_percent],
502
- log_sampler: config[:log_sampler],
410
+ log_sampling_enabled: config['log_sampling_enabled'], # steep:ignore
411
+ log_sampling_percent: config['log_sampling_percent'], # steep:ignore
412
+ log_sampler: config['log_sampler'], # steep:ignore
503
413
  log_sample_this: false,
504
- instr_sampling_enabled: config[:instr_sampling_enabled],
505
- instr_sampling_percent: config[:instr_sampling_percent],
506
- instr_sampler: config[:instr_sampler],
414
+ instr_sampling_enabled: config['instr_sampling_enabled'], # steep:ignore
415
+ instr_sampling_percent: config['instr_sampling_percent'], # steep:ignore
416
+ instr_sampler: config['instr_sampler'], # steep:ignore
507
417
  instr_sample_this: false,
508
418
  &block
509
419
  )
@@ -526,6 +436,7 @@ class RedisQueuedLocks::Client
526
436
  instrument:,
527
437
  instrumenter:,
528
438
  conflict_strategy:,
439
+ read_write_mode:,
529
440
  access_strategy:,
530
441
  log_sampling_enabled:,
531
442
  log_sampling_percent:,
@@ -552,7 +463,7 @@ class RedisQueuedLocks::Client
552
463
  # @option instr_sampling_percent [Integer]
553
464
  # @option instr_sampler [#sampling_happened?,Module<RedisQueuedLocks::Instrument::Sampler>]
554
465
  # @option instr_sample_this [Boolean]
555
- # @return [RedisQueuedLocks::Data, Hash<Symbol,Any>]
466
+ # @return [Hash<Symbol,Any>]
556
467
  # Format: {
557
468
  # ok: true/false,
558
469
  # result: {
@@ -569,19 +480,19 @@ class RedisQueuedLocks::Client
569
480
  # @version 1.6.0
570
481
  def unlock(
571
482
  lock_name,
572
- logger: config[:logger],
573
- instrumenter: config[:instrumenter],
483
+ logger: config['logger'], # steep:ignore
484
+ instrumenter: config['instrumenter'], # steep:ignore
574
485
  instrument: nil,
575
- log_sampling_enabled: config[:log_sampling_enabled],
576
- log_sampling_percent: config[:log_sampling_percent],
577
- log_sampler: config[:log_sampler],
486
+ log_sampling_enabled: config['log_sampling_enabled'], # steep:ignore
487
+ log_sampling_percent: config['log_sampling_percent'], # steep:ignore
488
+ log_sampler: config['log_sampler'], # steep:ignore
578
489
  log_sample_this: false,
579
- instr_sampling_enabled: config[:instr_sampling_enabled],
580
- instr_sampling_percent: config[:instr_sampling_percent],
581
- instr_sampler: config[:instr_sampler],
490
+ instr_sampling_enabled: config['instr_sampling_enabled'], # steep:ignore
491
+ instr_sampling_percent: config['instr_sampling_percent'], # steep:ignore
492
+ instr_sampler: config['instr_sampler'], # steep:ignore
582
493
  instr_sample_this: false
583
494
  )
584
- RedisQueuedLocks::Acquier::ReleaseLock.release_lock(
495
+ RedisQueuedLocks::Acquirer::ReleaseLock.release_lock(
585
496
  redis_client,
586
497
  lock_name,
587
498
  instrumenter,
@@ -604,7 +515,7 @@ class RedisQueuedLocks::Client
604
515
  # @api public
605
516
  # @since 1.0.0
606
517
  def locked?(lock_name)
607
- RedisQueuedLocks::Acquier::IsLocked.locked?(redis_client, lock_name)
518
+ RedisQueuedLocks::Acquirer::IsLocked.locked?(redis_client, lock_name)
608
519
  end
609
520
 
610
521
  # @param lock_name [String]
@@ -613,7 +524,7 @@ class RedisQueuedLocks::Client
613
524
  # @api public
614
525
  # @since 1.0.0
615
526
  def queued?(lock_name)
616
- RedisQueuedLocks::Acquier::IsQueued.queued?(redis_client, lock_name)
527
+ RedisQueuedLocks::Acquirer::IsQueued.queued?(redis_client, lock_name)
617
528
  end
618
529
 
619
530
  # @param lock_name [String]
@@ -622,7 +533,7 @@ class RedisQueuedLocks::Client
622
533
  # @api public
623
534
  # @since 1.0.0
624
535
  def lock_info(lock_name)
625
- RedisQueuedLocks::Acquier::LockInfo.lock_info(redis_client, lock_name)
536
+ RedisQueuedLocks::Acquirer::LockInfo.lock_info(redis_client, lock_name)
626
537
  end
627
538
 
628
539
  # @param lock_name [String]
@@ -631,7 +542,7 @@ class RedisQueuedLocks::Client
631
542
  # @api public
632
543
  # @since 1.0.0
633
544
  def queue_info(lock_name)
634
- RedisQueuedLocks::Acquier::QueueInfo.queue_info(redis_client, lock_name)
545
+ RedisQueuedLocks::Acquirer::QueueInfo.queue_info(redis_client, lock_name)
635
546
  end
636
547
 
637
548
  # Retrun the current acquirer identifier.
@@ -640,10 +551,10 @@ class RedisQueuedLocks::Client
640
551
  # @option thread_id [Integer,Any] Thread identifier.
641
552
  # @option fiber_id [Integer,Any] Fiber identifier.
642
553
  # @option ractor_id [Integer,Any] Ractor identifier.
643
- # @option identity [String] Unique per-process string. See `config[:uniq_identifier]`.
554
+ # @option identity [String] Unique per-process string. See `config['uniq_identifier']`.
644
555
  # @return [String]
645
556
  #
646
- # @see RedisQueuedLocks::Resource.acquier_identifier
557
+ # @see RedisQueuedLocks::Resource.acquirer_identifier
647
558
  # @see RedisQueuedLocks::Resource.get_process_id
648
559
  # @see RedisQueuedLocks::Resource.get_thread_id
649
560
  # @see RedisQueuedLocks::Resource.get_fiber_id
@@ -652,14 +563,14 @@ class RedisQueuedLocks::Client
652
563
  #
653
564
  # @api public
654
565
  # @since 1.8.0
655
- def current_acquier_id(
566
+ def current_acquirer_id(
656
567
  process_id: RedisQueuedLocks::Resource.get_process_id,
657
568
  thread_id: RedisQueuedLocks::Resource.get_thread_id,
658
569
  fiber_id: RedisQueuedLocks::Resource.get_fiber_id,
659
570
  ractor_id: RedisQueuedLocks::Resource.get_ractor_id,
660
571
  identity: uniq_identity
661
572
  )
662
- RedisQueuedLocks::Resource.acquier_identifier(
573
+ RedisQueuedLocks::Resource.acquirer_identifier(
663
574
  process_id,
664
575
  thread_id,
665
576
  fiber_id,
@@ -667,6 +578,8 @@ class RedisQueuedLocks::Client
667
578
  identity
668
579
  )
669
580
  end
581
+ alias_method :current_acq_id, :current_acquirer_id
582
+ alias_method :acq_id, :current_acquirer_id
670
583
 
671
584
  # Retrun the current host identifier.
672
585
  #
@@ -674,7 +587,7 @@ class RedisQueuedLocks::Client
674
587
  # @option thread_id [Integer,Any] Thread identifier.
675
588
  # @option fiber_id [Integer,Any] Fiber identifier.
676
589
  # @option ractor_id [Integer,Any] Ractor identifier.
677
- # @option identity [String] Unique per-process string. See `config[:uniq_identifier]`.
590
+ # @option identity [String] Unique per-process string. See `config['uniq_identifier']`.
678
591
  # @return [String]
679
592
  #
680
593
  # @see RedisQueuedLocks::Resource.host_identifier
@@ -698,6 +611,8 @@ class RedisQueuedLocks::Client
698
611
  identity
699
612
  )
700
613
  end
614
+ alias_method :current_hst_id, :current_host_id
615
+ alias_method :hst_id, :current_host_id
701
616
 
702
617
  # Return the list of possible host identifiers that can be reached from the current ractor.
703
618
  #
@@ -724,7 +639,7 @@ class RedisQueuedLocks::Client
724
639
  # @param lock_name [String]
725
640
  # @param milliseconds [Integer] How many milliseconds should be added.
726
641
  # @option logger [::Logger,#debug]
727
- # @option instrumenter [#notify] See `config[:instrumenter]` docs for details.
642
+ # @option instrumenter [#notify] See `config['instrumenter']` docs for details.
728
643
  # @option instrument [NilClass,Any]
729
644
  # @option log_sampling_enabled [Boolean]
730
645
  # @option log_sampling_percent [Integer]
@@ -744,19 +659,19 @@ class RedisQueuedLocks::Client
744
659
  def extend_lock_ttl(
745
660
  lock_name,
746
661
  milliseconds,
747
- logger: config[:logger],
748
- instrumenter: config[:instrumenter],
662
+ logger: config['logger'], # steep:ignore
663
+ instrumenter: config['instrumenter'], # steep:ignore
749
664
  instrument: nil,
750
- log_sampling_enabled: config[:log_sampling_enabled],
751
- log_sampling_percent: config[:log_sampling_percent],
752
- log_sampler: config[:log_sampler],
665
+ log_sampling_enabled: config['log_sampling_enabled'], # steep:ignore
666
+ log_sampling_percent: config['log_sampling_percent'], # steep:ignore
667
+ log_sampler: config['log_sampler'], # steep:ignore
753
668
  log_sample_this: false,
754
- instr_sampling_enabled: config[:instr_sampling_enabled],
755
- instr_sampling_percent: config[:instr_sampling_percent],
756
- instr_sampler: config[:instr_sampler],
669
+ instr_sampling_enabled: config['instr_sampling_enabled'], # steep:ignore
670
+ instr_sampling_percent: config['instr_sampling_percent'], # steep:ignore
671
+ instr_sampler: config['instr_sampler'], # steep:ignore
757
672
  instr_sample_this: false
758
673
  )
759
- RedisQueuedLocks::Acquier::ExtendLockTTL.extend_lock_ttl(
674
+ RedisQueuedLocks::Acquirer::ExtendLockTTL.extend_lock_ttl(
760
675
  redis_client,
761
676
  lock_name,
762
677
  milliseconds,
@@ -781,7 +696,7 @@ class RedisQueuedLocks::Client
781
696
  #
782
697
  # @option batch_size [Integer]
783
698
  # @option logger [::Logger,#debug]
784
- # @option instrumenter [#notify] See `config[:instrumenter]` docs for details.
699
+ # @option instrumenter [#notify] See `config['instrumenter']` docs for details.
785
700
  # @option instrument [NilClass,Any]
786
701
  # @option log_sampling_enabled [Boolean]
787
702
  # @option log_sampling_percent [Integer]
@@ -791,27 +706,27 @@ class RedisQueuedLocks::Client
791
706
  # @option instr_sampling_percent [Integer]
792
707
  # @option instr_sampler [#sampling_happened?,Module<RedisQueuedLocks::Instrument::Sampler>]
793
708
  # @option instr_sample_this [Boolean]
794
- # @return [RedisQueuedLocks::Data,Hash<Symbol,Boolean|Hash<Symbol,Numeric>>]
709
+ # @return [Hash<Symbol,Boolean|Hash<Symbol,Numeric>>]
795
710
  # Example: { ok: true, result { rel_key_cnt: 100, rel_time: 0.01 } }
796
711
  #
797
712
  # @api public
798
713
  # @since 1.0.0
799
714
  # @version 1.6.0
800
715
  def clear_locks(
801
- batch_size: config[:lock_release_batch_size],
802
- logger: config[:logger],
803
- instrumenter: config[:instrumenter],
716
+ batch_size: config['lock_release_batch_size'], # steep:ignore
717
+ logger: config['logger'], # steep:ignore
718
+ instrumenter: config['instrumenter'], # steep:ignore
804
719
  instrument: nil,
805
- log_sampling_enabled: config[:log_sampling_enabled],
806
- log_sampling_percent: config[:log_sampling_percent],
807
- log_sampler: config[:log_sampler],
720
+ log_sampling_enabled: config['log_sampling_enabled'], # steep:ignore
721
+ log_sampling_percent: config['log_sampling_percent'], # steep:ignore
722
+ log_sampler: config['log_sampler'], # steep:ignore
808
723
  log_sample_this: false,
809
- instr_sampling_enabled: config[:instr_sampling_enabled],
810
- instr_sampling_percent: config[:instr_sampling_percent],
811
- instr_sampler: config[:instr_sampler],
724
+ instr_sampling_enabled: config['instr_sampling_enabled'], # steep:ignore
725
+ instr_sampling_percent: config['instr_sampling_percent'], # steep:ignore
726
+ instr_sampler: config['instr_sampler'], # steep:ignore
812
727
  instr_sample_this: false
813
728
  )
814
- RedisQueuedLocks::Acquier::ReleaseAllLocks.release_all_locks(
729
+ RedisQueuedLocks::Acquirer::ReleaseAllLocks.release_all_locks(
815
730
  redis_client,
816
731
  batch_size,
817
732
  logger,
@@ -829,6 +744,154 @@ class RedisQueuedLocks::Client
829
744
  end
830
745
  alias_method :release_locks, :clear_locks
831
746
 
747
+ # Release all locks of the passed acquirer/host and remove this acquirer/host from all queues;
748
+ #
749
+ # This is a cleanup helper intended for operational and debugging scenarios (for example: your
750
+ # current puma request thread is killed by Rack::Timeout and you need to cleanup all zombie RQL
751
+ # locks and lock reuqests obtained during the request processing).
752
+ #
753
+ # Identifiers can be extracted via:
754
+ # - `#current_host_id`
755
+ # - `#current_acquirer_id`
756
+ # - `#possible_host_ids`
757
+ # - lock data (extracted from Redis via #lock_info, #locks_info, #queue_info, #queues_info)
758
+ #
759
+ # @option host_id [String] Host identifier whose locks/queues should be released.
760
+ # @option acquirer_id [String] Acquirer identifier, associated with the `host_id`.
761
+ # @option lock_scan_size [Integer]
762
+ # @option queue_scan_size [Integer]
763
+ # @option logger [::Logger,#debug]
764
+ # @option instrumenter [#notify] See `config['instrumenter']` docs for details.
765
+ # @option instrument [NilClass,Any]
766
+ # @option log_sampling_enabled [Boolean]
767
+ # @option log_sampling_percent [Integer]
768
+ # @option log_sampler [#sampling_happened?,Module<RedisQueuedLocks::Logging::Sampler>]
769
+ # @option log_sample_this [Boolean]
770
+ # @option instr_sampling_enabled [Boolean]
771
+ # @option instr_sampling_percent [Integer]
772
+ # @option instr_sampler [#sampling_happened?,Module<RedisQueuedLocks::Instrument::Sampler>]
773
+ # @option instr_sample_this [Boolean]
774
+ # @return [Hash<Symbol,Boolean|Hash<Symbol,Numeric>>]
775
+ # Example: { ok: true, result: { rel_key_cnt: 100, tch_queue_cnt: 2, rel_time: 0.01 } }
776
+ #
777
+ # @example Release locks of the current process:
778
+ # client.clear_locks_of(
779
+ # host_id: client.current_host_id,
780
+ # acquirer_id: client.current_acquirer_id
781
+ # )
782
+ #
783
+ # @example Release locks of a different host/acquirer:
784
+ # client.clear_locks_of(
785
+ # host_id: "rql:hst:62681/2016/2032/b30ec5e4bea10512",
786
+ # acquirer_id: "ral:acq:62681/2016/2024/2032/b30ec5e4bea10512"
787
+ # )
788
+ #
789
+ # @see #clear_current_locks
790
+ # @see #current_host_id
791
+ # @see #current_acquirer_id
792
+ # @see #possible_host_ids
793
+ # @see #lock_info
794
+ # @see #locks_info
795
+ # @see #queue_info
796
+ # @see #queues_info
797
+ #
798
+ # @api public
799
+ # @since 1.14.0
800
+ def clear_locks_of(
801
+ host_id:,
802
+ acquirer_id:,
803
+ lock_scan_size: config['clear_locks_of__lock_scan_size'], # steep:ignore
804
+ queue_scan_size: config['clear_locks_of__queue_scan_size'], # steep:ingore
805
+ logger: config['logger'], # steep:ignore
806
+ instrumenter: config['instrumenter'], # steep:ignore
807
+ instrument: nil,
808
+ log_sampling_enabled: config['log_sampling_enabled'], # steep:ignore
809
+ log_sampling_percent: config['log_sampling_percent'], # steep:ignore
810
+ log_sampler: config['log_sampler'], # steep:ignore
811
+ log_sample_this: false,
812
+ instr_sampling_enabled: config['instr_sampling_enabled'], # steep:ignore
813
+ instr_sampling_percent: config['instr_sampling_percent'], # steep:ignore
814
+ instr_sampler: config['instr_sampler'], # steep:ignore
815
+ instr_sample_this: false
816
+ )
817
+ RedisQueuedLocks::Acquirer::ReleaseLocksOf.release_locks_of(
818
+ host_id,
819
+ acquirer_id,
820
+ redis_client,
821
+ lock_scan_size,
822
+ queue_scan_size,
823
+ logger,
824
+ instrumenter,
825
+ instrument,
826
+ log_sampling_enabled,
827
+ log_sampling_percent,
828
+ log_sampler,
829
+ log_sample_this,
830
+ instr_sampling_enabled,
831
+ instr_sampling_percent,
832
+ instr_sampler,
833
+ instr_sample_this
834
+ )
835
+ end
836
+ alias_method :release_locks_of, :clear_locks_of
837
+
838
+ # Release all locks of the current acquirer/host and
839
+ # remove the current acquirer/host from all queues;
840
+ #
841
+ # @option batch_size [Integer]
842
+ # @option logger [::Logger,#debug]
843
+ # @option instrumenter [#notify] See `config['instrumenter']` docs for details.
844
+ # @option instrument [NilClass,Any]
845
+ # @option log_sampling_enabled [Boolean]
846
+ # @option log_sampling_percent [Integer]
847
+ # @option log_sampler [#sampling_happened?,Module<RedisQueuedLocks::Logging::Sampler>]
848
+ # @option log_sample_this [Boolean]
849
+ # @option instr_sampling_enabled [Boolean]
850
+ # @option instr_sampling_percent [Integer]
851
+ # @option instr_sampler [#sampling_happened?,Module<RedisQueuedLocks::Instrument::Sampler>]
852
+ # @option instr_sample_this [Boolean]
853
+ # @return [Hash<Symbol,Boolean|Hash<Symbol,Numeric>>]
854
+ # Example: { ok: true, result: { rel_key_cnt: 100, tch_queue_cnt: 2, rel_time: 0.01 } }
855
+ #
856
+ # @see #clear_locks_of
857
+ #
858
+ # @api public
859
+ # @since 1.14.0
860
+ def clear_current_locks(
861
+ lock_scan_size: config['clear_locks_of__lock_scan_size'], # steep:ignore
862
+ queue_scan_size: config['clear_locks_of__queue_scan_size'], # steep:ingore
863
+ logger: config['logger'], # steep:ignore
864
+ instrumenter: config['instrumenter'], # steep:ignore
865
+ instrument: nil,
866
+ log_sampling_enabled: config['log_sampling_enabled'], # steep:ignore
867
+ log_sampling_percent: config['log_sampling_percent'], # steep:ignore
868
+ log_sampler: config['log_sampler'], # steep:ignore
869
+ log_sample_this: false,
870
+ instr_sampling_enabled: config['instr_sampling_enabled'], # steep:ignore
871
+ instr_sampling_percent: config['instr_sampling_percent'], # steep:ignore
872
+ instr_sampler: config['instr_sampler'], # steep:ignore
873
+ instr_sample_this: false
874
+ )
875
+ clear_locks_of(
876
+ host_id: current_host_id,
877
+ acquirer_id: current_acquirer_id,
878
+ lock_scan_size:,
879
+ queue_scan_size:,
880
+ logger:,
881
+ instrumenter:,
882
+ instrument:,
883
+ log_sampling_enabled:,
884
+ log_sampling_percent:,
885
+ log_sampler:,
886
+ log_sample_this:,
887
+ instr_sampling_enabled:,
888
+ instr_sampling_percent:,
889
+ instr_sampler:,
890
+ instr_sample_this:
891
+ )
892
+ end
893
+ alias_method :release_current_locks, :clear_current_locks
894
+
832
895
  # @option scan_size [Integer]
833
896
  # The batch of scanned keys for Redis'es SCAN command.
834
897
  # @option with_info [Boolean]
@@ -848,8 +911,8 @@ class RedisQueuedLocks::Client
848
911
  #
849
912
  # @api public
850
913
  # @since 1.0.0
851
- def locks(scan_size: config[:key_extraction_batch_size], with_info: false)
852
- RedisQueuedLocks::Acquier::Locks.locks(redis_client, scan_size:, with_info:)
914
+ def locks(scan_size: config['key_extraction_batch_size'], with_info: false) # steep:ignore
915
+ RedisQueuedLocks::Acquirer::Locks.locks(redis_client, scan_size:, with_info:)
853
916
  end
854
917
 
855
918
  # Extracts lock keys with their info. See #locks(with_info: true) for details.
@@ -859,7 +922,7 @@ class RedisQueuedLocks::Client
859
922
  #
860
923
  # @api public
861
924
  # @since 1.0.0
862
- def locks_info(scan_size: config[:key_extraction_batch_size])
925
+ def locks_info(scan_size: config['key_extraction_batch_size']) # steep:ignore
863
926
  locks(scan_size:, with_info: true)
864
927
  end
865
928
 
@@ -879,8 +942,8 @@ class RedisQueuedLocks::Client
879
942
  #
880
943
  # @api public
881
944
  # @since 1.0.0
882
- def queues(scan_size: config[:key_extraction_batch_size], with_info: false)
883
- RedisQueuedLocks::Acquier::Queues.queues(redis_client, scan_size:, with_info:)
945
+ def queues(scan_size: config['key_extraction_batch_size'], with_info: false) # steep:ignore
946
+ RedisQueuedLocks::Acquirer::Queues.queues(redis_client, scan_size:, with_info:)
884
947
  end
885
948
 
886
949
  # Extracts lock queues with their info. See #queues(with_info: true) for details.
@@ -890,7 +953,7 @@ class RedisQueuedLocks::Client
890
953
  #
891
954
  # @api public
892
955
  # @since 1.0.0
893
- def queues_info(scan_size: config[:key_extraction_batch_size])
956
+ def queues_info(scan_size: config['key_extraction_batch_size']) # steep:ignore
894
957
  queues(scan_size:, with_info: true)
895
958
  end
896
959
 
@@ -899,17 +962,17 @@ class RedisQueuedLocks::Client
899
962
  #
900
963
  # @api public
901
964
  # @since 1.0.0
902
- def keys(scan_size: config[:key_extraction_batch_size])
903
- RedisQueuedLocks::Acquier::Keys.keys(redis_client, scan_size:)
965
+ def keys(scan_size: config['key_extraction_batch_size']) # steep:ignore
966
+ RedisQueuedLocks::Acquirer::Keys.keys(redis_client, scan_size:)
904
967
  end
905
968
 
906
969
  # @option dead_ttl [Integer]
907
970
  # - the time period (in millsiecnds) after whcih the lock request is
908
971
  # considered as dead;
909
- # - `config[:dead_request_ttl]` is used by default;
972
+ # - `config['dead_request_ttl']` is used by default;
910
973
  # @option scan_size [Integer]
911
974
  # - the batch of scanned keys for Redis'es SCAN command;
912
- # - `config[:lock_release_batch_size]` is used by default;
975
+ # - `config['lock_release_batch_size']` is used by default;
913
976
  # @option logger [::Logger,#debug]
914
977
  # @option instrumenter [#notify]
915
978
  # @option instrument [NilClass,Any]
@@ -928,21 +991,21 @@ class RedisQueuedLocks::Client
928
991
  # @since 1.0.0
929
992
  # @version 1.6.0
930
993
  def clear_dead_requests(
931
- dead_ttl: config[:dead_request_ttl],
932
- scan_size: config[:lock_release_batch_size],
933
- logger: config[:logger],
934
- instrumenter: config[:instrumenter],
994
+ dead_ttl: config['dead_request_ttl'], # steep:ignore
995
+ scan_size: config['lock_release_batch_size'], # steep:ignore
996
+ logger: config['logger'], # steep:ignore
997
+ instrumenter: config['instrumenter'], # steep:ignore
935
998
  instrument: nil,
936
- log_sampling_enabled: config[:log_sampling_enabled],
937
- log_sampling_percent: config[:log_sampling_percent],
938
- log_sampler: config[:log_sampler],
999
+ log_sampling_enabled: config['log_sampling_enabled'], # steep:ignore
1000
+ log_sampling_percent: config['log_sampling_percent'], # steep:ignore
1001
+ log_sampler: config['log_sampler'], # steep:ignore
939
1002
  log_sample_this: false,
940
- instr_sampling_enabled: config[:instr_sampling_enabled],
941
- instr_sampling_percent: config[:instr_sampling_percent],
942
- instr_sampler: config[:instr_sampler],
1003
+ instr_sampling_enabled: config['instr_sampling_enabled'], # steep:ignore
1004
+ instr_sampling_percent: config['instr_sampling_percent'], # steep:ignore
1005
+ instr_sampler: config['instr_sampler'], # steep:ignore
943
1006
  instr_sample_this: false
944
1007
  )
945
- RedisQueuedLocks::Acquier::ClearDeadRequests.clear_dead_requests(
1008
+ RedisQueuedLocks::Acquirer::ClearDeadRequests.clear_dead_requests(
946
1009
  redis_client,
947
1010
  scan_size,
948
1011
  dead_ttl,