redis_queued_locks 1.20.0 → 1.22.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 (86) hide show
  1. checksums.yaml +4 -4
  2. data/.claude/project-overview.md +249 -36
  3. data/.claude/rules/acquirer.md +16 -14
  4. data/.claude/rules/arguments.md +2 -2
  5. data/.claude/rules/changelog.md +27 -0
  6. data/.claude/rules/git.md +1 -1
  7. data/.claude/rules/logic.md +34 -13
  8. data/.claude/rules/swarm.md +4 -5
  9. data/.claude/rules/tests.md +9 -6
  10. data/.claude/rules/type-checking.md +13 -14
  11. data/.claude/rules/visitors.md +13 -14
  12. data/.claude/skills/rql-code-review/SKILL.md +134 -43
  13. data/CHANGELOG.md +105 -125
  14. data/CLAUDE.md +11 -9
  15. data/README.md +501 -136
  16. data/Rakefile +11 -0
  17. data/lib/redis_queued_locks/acquirer/acquire_lock/dequeue_from_lock_queue/log_visitor.rb +1 -0
  18. data/lib/redis_queued_locks/acquirer/acquire_lock/instr_visitor.rb +68 -10
  19. data/lib/redis_queued_locks/acquirer/acquire_lock/log_visitor.rb +82 -15
  20. data/lib/redis_queued_locks/acquirer/acquire_lock/try_to_lock/log_visitor.rb +92 -14
  21. data/lib/redis_queued_locks/acquirer/acquire_lock/try_to_lock.rb +441 -63
  22. data/lib/redis_queued_locks/acquirer/acquire_lock/with_acq_timeout.rb +2 -2
  23. data/lib/redis_queued_locks/acquirer/acquire_lock/yield_expire/log_visitor.rb +1 -0
  24. data/lib/redis_queued_locks/acquirer/acquire_lock/yield_expire.rb +5 -5
  25. data/lib/redis_queued_locks/acquirer/acquire_lock.rb +176 -39
  26. data/lib/redis_queued_locks/acquirer/clear_dead_requests.rb +322 -49
  27. data/lib/redis_queued_locks/acquirer/extend_lock_ttl.rb +125 -13
  28. data/lib/redis_queued_locks/acquirer/is_locked.rb +0 -1
  29. data/lib/redis_queued_locks/acquirer/is_queued.rb +0 -1
  30. data/lib/redis_queued_locks/acquirer/keys.rb +16 -3
  31. data/lib/redis_queued_locks/acquirer/lock_info.rb +31 -39
  32. data/lib/redis_queued_locks/acquirer/lock_series_poc/instr_visitor.rb +11 -5
  33. data/lib/redis_queued_locks/acquirer/lock_series_poc/log_visitor.rb +20 -10
  34. data/lib/redis_queued_locks/acquirer/lock_series_poc.rb +105 -36
  35. data/lib/redis_queued_locks/acquirer/locks.rb +32 -11
  36. data/lib/redis_queued_locks/acquirer/queue_info.rb +30 -8
  37. data/lib/redis_queued_locks/acquirer/queues.rb +26 -6
  38. data/lib/redis_queued_locks/acquirer/reindex_locks.rb +117 -4
  39. data/lib/redis_queued_locks/acquirer/release_all_locks.rb +37 -6
  40. data/lib/redis_queued_locks/acquirer/release_lock.rb +33 -7
  41. data/lib/redis_queued_locks/acquirer/release_locks_of.rb +45 -6
  42. data/lib/redis_queued_locks/acquirer/release_read_lock.rb +22 -3
  43. data/lib/redis_queued_locks/client.rb +140 -56
  44. data/lib/redis_queued_locks/config.rb +105 -14
  45. data/lib/redis_queued_locks/errors.rb +34 -4
  46. data/lib/redis_queued_locks/instrument/sampler.rb +4 -7
  47. data/lib/redis_queued_locks/logging/sampler.rb +4 -8
  48. data/lib/redis_queued_locks/resource.rb +137 -12
  49. data/lib/redis_queued_locks/swarm/flush_zombies.rb +1 -0
  50. data/lib/redis_queued_locks/swarm/redis_client_builder.rb +8 -4
  51. data/lib/redis_queued_locks/swarm/swarm_element/threaded.rb +8 -6
  52. data/lib/redis_queued_locks/swarm/zombie_info.rb +6 -2
  53. data/lib/redis_queued_locks/swarm.rb +86 -5
  54. data/lib/redis_queued_locks/utilities.rb +1 -1
  55. data/lib/redis_queued_locks/version.rb +2 -2
  56. data/rbs_collection.lock.yaml +4 -0
  57. data/rbs_collection.yaml +2 -1
  58. data/sig/manifest.yml +1 -0
  59. data/sig/redis_queued_locks/acquirer/acquire_lock/dequeue_from_lock_queue/log_visitor.rbs +2 -2
  60. data/sig/redis_queued_locks/acquirer/acquire_lock/dequeue_from_lock_queue.rbs +2 -2
  61. data/sig/redis_queued_locks/acquirer/acquire_lock/instr_visitor.rbs +25 -5
  62. data/sig/redis_queued_locks/acquirer/acquire_lock/log_visitor.rbs +32 -12
  63. data/sig/redis_queued_locks/acquirer/acquire_lock/try_to_lock/log_visitor.rbs +61 -40
  64. data/sig/redis_queued_locks/acquirer/acquire_lock/try_to_lock.rbs +59 -11
  65. data/sig/redis_queued_locks/acquirer/acquire_lock/{yield_with_expire → yield_expire}/log_visitor.rbs +4 -4
  66. data/sig/redis_queued_locks/acquirer/acquire_lock/yield_expire.rbs +4 -4
  67. data/sig/redis_queued_locks/acquirer/acquire_lock.rbs +6 -4
  68. data/sig/redis_queued_locks/acquirer/clear_dead_requests.rbs +23 -1
  69. data/sig/redis_queued_locks/acquirer/extend_lock_ttl.rbs +16 -3
  70. data/sig/redis_queued_locks/acquirer/queues.rbs +1 -1
  71. data/sig/redis_queued_locks/acquirer/reindex_locks.rbs +22 -1
  72. data/sig/redis_queued_locks/acquirer/release_lock.rbs +3 -2
  73. data/sig/redis_queued_locks/acquirer/release_read_lock.rbs +1 -1
  74. data/sig/redis_queued_locks/client.rbs +24 -10
  75. data/sig/redis_queued_locks/config.rbs +54 -1
  76. data/sig/redis_queued_locks/errors.rbs +5 -2
  77. data/sig/redis_queued_locks/instrument/sampler.rbs +3 -3
  78. data/sig/redis_queued_locks/instrument/void_notifier.rbs +3 -1
  79. data/sig/redis_queued_locks/logging/sampler.rbs +3 -3
  80. data/sig/redis_queued_locks/resource.rbs +23 -13
  81. data/sig/redis_queued_locks/swarm/swarm_element/threaded.rbs +1 -1
  82. data/sig/redis_queued_locks/utilities.rbs +2 -1
  83. data/sig/redis_queued_locks.rbs +7 -0
  84. data/sig/vendor/redis_client.rbs +1 -0
  85. metadata +4 -3
  86. /data/sig/redis_queued_locks/{acquier.rbs → acquirer.rbs} +0 -0
data/Rakefile CHANGED
@@ -55,4 +55,15 @@ end
55
55
  RSpec::Core::RakeTask.new(:rspec)
56
56
  Steep::RakeTask.new(:steep)
57
57
 
58
+ # NOTE: (parallel specs) the runner: `spec/support/parallel_runner.rb`
59
+ namespace :rspec do
60
+ desc 'Run the specs in parallel processes (WORKERS=<n>, each worker with its own Redis databases)'
61
+ task :parallel, [:paths] do |_task, args|
62
+ require_relative 'spec/support/parallel_runner'
63
+
64
+ workers = ENV.key?('WORKERS') ? Integer(ENV.fetch('WORKERS')) : nil
65
+ RQLParallelSpecs.run(workers, args[:paths].to_s.split)
66
+ end
67
+ end
68
+
58
69
  task default: :rspec
@@ -2,6 +2,7 @@
2
2
 
3
3
  # @api private
4
4
  # @since 1.7.0
5
+ # @version 1.18.0
5
6
  module RedisQueuedLocks::Acquirer::AcquireLock::DequeueFromLockQueue::LogVisitor
6
7
  class << self
7
8
  # @param logger [::Logger,#debug]
@@ -2,12 +2,16 @@
2
2
 
3
3
  # @api private
4
4
  # @since 1.7.0
5
+ # @version 1.22.0
6
+ # rubocop:disable Metrics/ModuleLength
5
7
  module RedisQueuedLocks::Acquirer::AcquireLock::InstrVisitor
8
+ # rubocop:disable Metrics/ClassLength
6
9
  class << self
7
10
  # @param instrumenter [#notify]
8
11
  # @param instr_sampled [Boolean]
9
12
  # @param lock_key [String]
10
13
  # @param rw_mode [Symbol]
14
+ # @param priority [Integer] The lock request priority.
11
15
  # @param ttl [Integer, NilClass]
12
16
  # @param acq_id [String]
13
17
  # @param hst_id [String]
@@ -18,12 +22,13 @@ module RedisQueuedLocks::Acquirer::AcquireLock::InstrVisitor
18
22
  #
19
23
  # @api private
20
24
  # @since 1.7.0
21
- # @version 1.18.0
25
+ # @version 1.22.0
22
26
  def extendable_reentrant_lock_obtained(
23
27
  instrumenter,
24
28
  instr_sampled,
25
29
  lock_key,
26
30
  rw_mode,
31
+ priority,
27
32
  ttl,
28
33
  acq_id,
29
34
  hst_id,
@@ -33,7 +38,7 @@ module RedisQueuedLocks::Acquirer::AcquireLock::InstrVisitor
33
38
  )
34
39
  return unless instr_sampled
35
40
  instrumenter.notify('redis_queued_locks.extendable_reentrant_lock_obtained', {
36
- lock_key:, rw_mode:, ttl:, acq_id:, hst_id:, ts:, acq_time:, instrument:
41
+ lock_key:, rw_mode:, priority:, ttl:, acq_id:, hst_id:, ts:, acq_time:, instrument:
37
42
  }) rescue nil
38
43
  end
39
44
 
@@ -41,6 +46,7 @@ module RedisQueuedLocks::Acquirer::AcquireLock::InstrVisitor
41
46
  # @param instr_sampled [Boolean]
42
47
  # @param lock_key [String]
43
48
  # @param rw_mode [Symbol]
49
+ # @param priority [Integer] The lock request priority.
44
50
  # @param ttl [Integer, NilClass]
45
51
  # @param acq_id [String]
46
52
  # @param hst_id [String]
@@ -51,12 +57,13 @@ module RedisQueuedLocks::Acquirer::AcquireLock::InstrVisitor
51
57
  #
52
58
  # @api private
53
59
  # @since 1.7.0
54
- # @version 1.18.0
60
+ # @version 1.22.0
55
61
  def reentrant_lock_obtained(
56
62
  instrumenter,
57
63
  instr_sampled,
58
64
  lock_key,
59
65
  rw_mode,
66
+ priority,
60
67
  ttl,
61
68
  acq_id,
62
69
  hst_id,
@@ -66,7 +73,7 @@ module RedisQueuedLocks::Acquirer::AcquireLock::InstrVisitor
66
73
  )
67
74
  return unless instr_sampled
68
75
  instrumenter.notify('redis_queued_locks.reentrant_lock_obtained', {
69
- lock_key:, rw_mode:, ttl:, acq_id:, hst_id:, ts:, acq_time:, instrument:
76
+ lock_key:, rw_mode:, priority:, ttl:, acq_id:, hst_id:, ts:, acq_time:, instrument:
70
77
  }) rescue nil
71
78
  end
72
79
 
@@ -74,6 +81,7 @@ module RedisQueuedLocks::Acquirer::AcquireLock::InstrVisitor
74
81
  # @param instr_sampled [Boolean]
75
82
  # @param lock_key [String]
76
83
  # @param rw_mode [Symbol]
84
+ # @param priority [Integer] The lock request priority.
77
85
  # @param ttl [Integer, NilClass]
78
86
  # @param acq_id [String]
79
87
  # @param hst_id [String]
@@ -84,12 +92,13 @@ module RedisQueuedLocks::Acquirer::AcquireLock::InstrVisitor
84
92
  #
85
93
  # @api private
86
94
  # @since 1.7.0
87
- # @version 1.18.0
95
+ # @version 1.22.0
88
96
  def lock_obtained(
89
97
  instrumenter,
90
98
  instr_sampled,
91
99
  lock_key,
92
100
  rw_mode,
101
+ priority,
93
102
  ttl,
94
103
  acq_id,
95
104
  hst_id,
@@ -99,7 +108,7 @@ module RedisQueuedLocks::Acquirer::AcquireLock::InstrVisitor
99
108
  )
100
109
  return unless instr_sampled
101
110
  instrumenter.notify('redis_queued_locks.lock_obtained', {
102
- lock_key:, rw_mode:, ttl:, acq_id:, hst_id:, ts:, acq_time:, instrument:
111
+ lock_key:, rw_mode:, priority:, ttl:, acq_id:, hst_id:, ts:, acq_time:, instrument:
103
112
  }) rescue nil
104
113
  end
105
114
 
@@ -107,6 +116,7 @@ module RedisQueuedLocks::Acquirer::AcquireLock::InstrVisitor
107
116
  # @param instr_sampled [Boolean]
108
117
  # @param lock_key [String]
109
118
  # @param rw_mode [Symbol]
119
+ # @param priority [Integer] The lock request priority.
110
120
  # @param ttl [Integer, NilClass]
111
121
  # @param acq_id [String]
112
122
  # @param hst_id [String]
@@ -118,12 +128,13 @@ module RedisQueuedLocks::Acquirer::AcquireLock::InstrVisitor
118
128
  #
119
129
  # @api private
120
130
  # @since 1.7.0
121
- # @version 1.18.0
131
+ # @version 1.22.0
122
132
  def reentrant_lock_hold_completes(
123
133
  instrumenter,
124
134
  instr_sampled,
125
135
  lock_key,
126
136
  rw_mode,
137
+ priority,
127
138
  ttl,
128
139
  acq_id,
129
140
  hst_id,
@@ -134,7 +145,8 @@ module RedisQueuedLocks::Acquirer::AcquireLock::InstrVisitor
134
145
  )
135
146
  return unless instr_sampled
136
147
  instrumenter.notify('redis_queued_locks.reentrant_lock_hold_completes', {
137
- hold_time:, ttl:, acq_id:, hst_id:, ts:, lock_key:, rw_mode:, acq_time:, instrument:
148
+ hold_time:, ttl:, acq_id:, hst_id:, ts:, lock_key:, rw_mode:, priority:, acq_time:,
149
+ instrument:
138
150
  }) rescue nil
139
151
  end
140
152
 
@@ -142,6 +154,7 @@ module RedisQueuedLocks::Acquirer::AcquireLock::InstrVisitor
142
154
  # @param instr_sampled [Boolean]
143
155
  # @param lock_key [String]
144
156
  # @param rw_mode [Symbol]
157
+ # @param priority [Integer] The lock request priority.
145
158
  # @param ttl [Integer, NilClass]
146
159
  # @param acq_id [String]
147
160
  # @param hst_id [String]
@@ -153,12 +166,13 @@ module RedisQueuedLocks::Acquirer::AcquireLock::InstrVisitor
153
166
  #
154
167
  # @api private
155
168
  # @since 1.7.0
156
- # @version 1.18.0
169
+ # @version 1.22.0
157
170
  def lock_hold_and_release(
158
171
  instrumenter,
159
172
  instr_sampled,
160
173
  lock_key,
161
174
  rw_mode,
175
+ priority,
162
176
  ttl,
163
177
  acq_id,
164
178
  hst_id,
@@ -169,8 +183,52 @@ module RedisQueuedLocks::Acquirer::AcquireLock::InstrVisitor
169
183
  )
170
184
  return unless instr_sampled
171
185
  instrumenter.notify('redis_queued_locks.lock_hold_and_release', {
172
- hold_time:, ttl:, acq_id:, hst_id:, ts:, lock_key:, rw_mode:, acq_time:, instrument:
186
+ hold_time:, ttl:, acq_id:, hst_id:, ts:, lock_key:, rw_mode:, priority:, acq_time:,
187
+ instrument:
188
+ }) rescue nil
189
+ end
190
+
191
+ # The lock is not obtained (the failure result of `#lock`/`#lock!`: the timeout, the retry
192
+ # limit, `fail_fast`, the dead lock or the lock upgrade conflict).
193
+ #
194
+ # @param instrumenter [#notify]
195
+ # @param instr_sampled [Boolean]
196
+ # @param lock_key [String]
197
+ # @param rw_mode [Symbol]
198
+ # @param priority [Integer] The lock request priority.
199
+ # @param ttl [Integer]
200
+ # @param acq_id [String]
201
+ # @param hst_id [String]
202
+ # @param ts [Numeric]
203
+ # @param acq_time [Numeric]
204
+ # @param result [Symbol] The failure result (`:timeout_reached`, `:retry_limit_reached`, ...).
205
+ # @param instrument [NilClass,Any]
206
+ # @return [void]
207
+ #
208
+ # @api private
209
+ # @since 1.21.0
210
+ # @version 1.22.0
211
+ def lock_obtaining_failed(
212
+ instrumenter,
213
+ instr_sampled,
214
+ lock_key,
215
+ rw_mode,
216
+ priority,
217
+ ttl,
218
+ acq_id,
219
+ hst_id,
220
+ ts,
221
+ acq_time,
222
+ result,
223
+ instrument
224
+ )
225
+ return unless instr_sampled
226
+ instrumenter.notify('redis_queued_locks.lock_obtaining_failed', {
227
+ lock_key:, rw_mode:, priority:, ttl:, acq_id:, hst_id:, ts:, acq_time:, result:,
228
+ instrument:
173
229
  }) rescue nil
174
230
  end
175
231
  end
232
+ # rubocop:enable Metrics/ClassLength
176
233
  end
234
+ # rubocop:enable Metrics/ModuleLength
@@ -2,6 +2,7 @@
2
2
 
3
3
  # @api private
4
4
  # @since 1.7.0
5
+ # @version 1.22.0
5
6
  # rubocop:disable Metrics/ModuleLength
6
7
  module RedisQueuedLocks::Acquirer::AcquireLock::LogVisitor
7
8
  # rubocop:disable Metrics/ClassLength
@@ -14,11 +15,12 @@ module RedisQueuedLocks::Acquirer::AcquireLock::LogVisitor
14
15
  # @param host_id [String]
15
16
  # @param access_strategy [Symbol]
16
17
  # @param rw_mode [Symbol]
18
+ # @param priority [Integer] The lock request priority.
17
19
  # @return [void]
18
20
  #
19
21
  # @api private
20
22
  # @since 1.7.0
21
- # @version 1.18.0
23
+ # @version 1.22.0
22
24
  def start_lock_obtaining(
23
25
  logger,
24
26
  log_sampled,
@@ -27,7 +29,8 @@ module RedisQueuedLocks::Acquirer::AcquireLock::LogVisitor
27
29
  acquirer_id,
28
30
  host_id,
29
31
  access_strategy,
30
- rw_mode
32
+ rw_mode,
33
+ priority
31
34
  )
32
35
  return unless log_sampled
33
36
 
@@ -38,7 +41,8 @@ module RedisQueuedLocks::Acquirer::AcquireLock::LogVisitor
38
41
  "acq_id => '#{acquirer_id}' " \
39
42
  "hst_id => '#{host_id}' " \
40
43
  "acs_strat => '#{access_strategy}' " \
41
- "rw_mode => '#{rw_mode}'"
44
+ "rw_mode => '#{rw_mode}' " \
45
+ "priority => #{priority}"
42
46
  end rescue nil
43
47
  end
44
48
 
@@ -50,11 +54,12 @@ module RedisQueuedLocks::Acquirer::AcquireLock::LogVisitor
50
54
  # @param host_id [String]
51
55
  # @param access_strategy [Symbol]
52
56
  # @param rw_mode [Symbol]
57
+ # @param priority [Integer] The lock request priority.
53
58
  # @return [void]
54
59
  #
55
60
  # @api private
56
61
  # @since 1.7.0
57
- # @version 1.18.0
62
+ # @version 1.22.0
58
63
  def start_try_to_lock_cycle(
59
64
  logger,
60
65
  log_sampled,
@@ -63,7 +68,8 @@ module RedisQueuedLocks::Acquirer::AcquireLock::LogVisitor
63
68
  acquirer_id,
64
69
  host_id,
65
70
  access_strategy,
66
- rw_mode
71
+ rw_mode,
72
+ priority
67
73
  )
68
74
  return unless log_sampled
69
75
 
@@ -74,7 +80,8 @@ module RedisQueuedLocks::Acquirer::AcquireLock::LogVisitor
74
80
  "acq_id => '#{acquirer_id}' " \
75
81
  "hst_id => '#{host_id}' " \
76
82
  "acs_strat => '#{access_strategy}' " \
77
- "rw_mode => '#{rw_mode}'"
83
+ "rw_mode => '#{rw_mode}' " \
84
+ "priority => #{priority}"
78
85
  end rescue nil
79
86
  end
80
87
 
@@ -86,11 +93,12 @@ module RedisQueuedLocks::Acquirer::AcquireLock::LogVisitor
86
93
  # @param host_id [String]
87
94
  # @param access_strategy [Symbol]
88
95
  # @param rw_mode [Symbol]
96
+ # @param priority [Integer] The lock request priority.
89
97
  # @return [void]
90
98
  #
91
99
  # @api private
92
100
  # @since 1.7.0
93
- # @version 1.18.0
101
+ # @version 1.22.0
94
102
  def dead_score_reached__reset_acquirer_position(
95
103
  logger,
96
104
  log_sampled,
@@ -99,7 +107,8 @@ module RedisQueuedLocks::Acquirer::AcquireLock::LogVisitor
99
107
  acquirer_id,
100
108
  host_id,
101
109
  access_strategy,
102
- rw_mode
110
+ rw_mode,
111
+ priority
103
112
  )
104
113
  return unless log_sampled
105
114
 
@@ -110,7 +119,8 @@ module RedisQueuedLocks::Acquirer::AcquireLock::LogVisitor
110
119
  "acq_id => '#{acquirer_id}' " \
111
120
  "hst_id => '#{host_id}' " \
112
121
  "acs_strat => '#{access_strategy}' " \
113
- "rw_mode => '#{rw_mode}'"
122
+ "rw_mode => '#{rw_mode}' " \
123
+ "priority => #{priority}"
114
124
  end rescue nil
115
125
  end
116
126
 
@@ -123,11 +133,12 @@ module RedisQueuedLocks::Acquirer::AcquireLock::LogVisitor
123
133
  # @param acq_time [Numeric]
124
134
  # @param access_strategy [Symbol]
125
135
  # @param rw_mode [Symbol]
136
+ # @param priority [Integer] The lock request priority.
126
137
  # @return [void]
127
138
  #
128
139
  # @api private
129
140
  # @since 1.7.0
130
- # @version 1.18.0
141
+ # @version 1.22.0
131
142
  def extendable_reentrant_lock_obtained(
132
143
  logger,
133
144
  log_sampled,
@@ -137,7 +148,8 @@ module RedisQueuedLocks::Acquirer::AcquireLock::LogVisitor
137
148
  host_id,
138
149
  acq_time,
139
150
  access_strategy,
140
- rw_mode
151
+ rw_mode,
152
+ priority
141
153
  )
142
154
  return unless log_sampled
143
155
 
@@ -149,6 +161,7 @@ module RedisQueuedLocks::Acquirer::AcquireLock::LogVisitor
149
161
  "hst_id => '#{host_id}' " \
150
162
  "acs_strat => '#{access_strategy}' " \
151
163
  "rw_mode => '#{rw_mode}' " \
164
+ "priority => #{priority} " \
152
165
  "acq_time => #{acq_time} (ms)"
153
166
  end rescue nil
154
167
  end
@@ -162,11 +175,12 @@ module RedisQueuedLocks::Acquirer::AcquireLock::LogVisitor
162
175
  # @param acq_time [Numeric]
163
176
  # @param access_strategy [Symbol]
164
177
  # @param rw_mode [Symbol]
178
+ # @param priority [Integer] The lock request priority.
165
179
  # @return [void]
166
180
  #
167
181
  # @api private
168
182
  # @since 1.7.0
169
- # @version 1.18.0
183
+ # @version 1.22.0
170
184
  def reentrant_lock_obtained(
171
185
  logger,
172
186
  log_sampled,
@@ -176,7 +190,8 @@ module RedisQueuedLocks::Acquirer::AcquireLock::LogVisitor
176
190
  host_id,
177
191
  acq_time,
178
192
  access_strategy,
179
- rw_mode
193
+ rw_mode,
194
+ priority
180
195
  )
181
196
  return unless log_sampled
182
197
 
@@ -188,6 +203,7 @@ module RedisQueuedLocks::Acquirer::AcquireLock::LogVisitor
188
203
  "hst_id => '#{host_id}' " \
189
204
  "acs_strat => '#{access_strategy}' " \
190
205
  "rw_mode => '#{rw_mode}' " \
206
+ "priority => #{priority} " \
191
207
  "acq_time => #{acq_time} (ms)"
192
208
  end rescue nil
193
209
  end
@@ -201,11 +217,12 @@ module RedisQueuedLocks::Acquirer::AcquireLock::LogVisitor
201
217
  # @param acq_time [Numeric]
202
218
  # @param access_strategy [Symbol]
203
219
  # @param rw_mode [Symbol]
220
+ # @param priority [Integer] The lock request priority.
204
221
  # @return [void]
205
222
  #
206
223
  # @api private
207
224
  # @since 1.7.0
208
- # @version 1.18.0
225
+ # @version 1.22.0
209
226
  def lock_obtained(
210
227
  logger,
211
228
  log_sampled,
@@ -215,7 +232,8 @@ module RedisQueuedLocks::Acquirer::AcquireLock::LogVisitor
215
232
  host_id,
216
233
  acq_time,
217
234
  access_strategy,
218
- rw_mode
235
+ rw_mode,
236
+ priority
219
237
  )
220
238
  return unless log_sampled
221
239
 
@@ -227,9 +245,58 @@ module RedisQueuedLocks::Acquirer::AcquireLock::LogVisitor
227
245
  "hst_id => '#{host_id}' " \
228
246
  "acs_strat => '#{access_strategy}' " \
229
247
  "rw_mode => '#{rw_mode}' " \
248
+ "priority => #{priority} " \
230
249
  "acq_time => #{acq_time} (ms)"
231
250
  end rescue nil
232
251
  end
252
+
253
+ # The lock is not obtained (the failure result of `#lock`/`#lock!`: the timeout, the retry
254
+ # limit, `fail_fast`, the dead lock or the lock upgrade conflict).
255
+ #
256
+ # @param logger [::Logger,#debug]
257
+ # @param log_sampled [Boolean]
258
+ # @param lock_key [String]
259
+ # @param queue_ttl [Integer]
260
+ # @param acquirer_id [String]
261
+ # @param host_id [String]
262
+ # @param acq_time [Numeric]
263
+ # @param access_strategy [Symbol]
264
+ # @param rw_mode [Symbol]
265
+ # @param priority [Integer] The lock request priority.
266
+ # @param result [Symbol] The failure result (`:timeout_reached`, `:retry_limit_reached`, ...).
267
+ # @return [void]
268
+ #
269
+ # @api private
270
+ # @since 1.21.0
271
+ # @version 1.22.0
272
+ def lock_obtaining_failed(
273
+ logger,
274
+ log_sampled,
275
+ lock_key,
276
+ queue_ttl,
277
+ acquirer_id,
278
+ host_id,
279
+ acq_time,
280
+ access_strategy,
281
+ rw_mode,
282
+ priority,
283
+ result
284
+ )
285
+ return unless log_sampled
286
+
287
+ logger.debug do
288
+ "[redis_queued_locks.lock_obtaining_failed] " \
289
+ "lock_key => '#{lock_key}' " \
290
+ "queue_ttl => #{queue_ttl} " \
291
+ "acq_id => '#{acquirer_id}' " \
292
+ "hst_id => '#{host_id}' " \
293
+ "acs_strat => '#{access_strategy}' " \
294
+ "rw_mode => '#{rw_mode}' " \
295
+ "priority => #{priority} " \
296
+ "acq_time => #{acq_time} (ms) " \
297
+ "result => '#{result}'"
298
+ end rescue nil
299
+ end
233
300
  end
234
301
  # rubocop:enable Metrics/ClassLength
235
302
  end