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
@@ -1,166 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # @api private
4
- # @since 1.7.0
5
- module RedisQueuedLocks::Acquier::AcquireLock::InstrVisitor
6
- extend self
7
-
8
- # @param instrumenter [#notify]
9
- # @param instr_sampled [Boolean]
10
- # @param lock_key [String]
11
- # @param ttl [Integer, NilClass]
12
- # @param acq_id [String]
13
- # @param hst_id [String]
14
- # @param ts [Numeric]
15
- # @param acq_time [Numeric]
16
- # @param instrument [NilClass,Any]
17
- # @return [void]
18
- #
19
- # @api private
20
- # @since 1.7.0
21
- # @version 1.9.0
22
- def extendable_reentrant_lock_obtained(
23
- instrumenter,
24
- instr_sampled,
25
- lock_key,
26
- ttl,
27
- acq_id,
28
- hst_id,
29
- ts,
30
- acq_time,
31
- instrument
32
- )
33
- return unless instr_sampled
34
- instrumenter.notify('redis_queued_locks.extendable_reentrant_lock_obtained', {
35
- lock_key:, ttl:, acq_id:, hst_id:, ts:, acq_time:, instrument:
36
- }) rescue nil
37
- end
38
-
39
- # @param instrumenter [#notify]
40
- # @param instr_sampled [Boolean]
41
- # @param lock_key [String]
42
- # @param ttl [Integer, NilClass]
43
- # @param acq_id [String]
44
- # @param hst_id [String]
45
- # @param ts [Numeric]
46
- # @param acq_time [Numeric]
47
- # @param instrument [NilClass,Any]
48
- # @return [void]
49
- #
50
- # @api private
51
- # @since 1.7.0
52
- # @version 1.9.0
53
- def reentrant_lock_obtained(
54
- instrumenter,
55
- instr_sampled,
56
- lock_key,
57
- ttl,
58
- acq_id,
59
- hst_id,
60
- ts,
61
- acq_time,
62
- instrument
63
- )
64
- return unless instr_sampled
65
- instrumenter.notify('redis_queued_locks.reentrant_lock_obtained', {
66
- lock_key:, ttl:, acq_id:, hst_id:, ts:, acq_time:, instrument:
67
- }) rescue nil
68
- end
69
-
70
- # @param instrumenter [#notify]
71
- # @param instr_sampled [Boolean]
72
- # @param lock_key [String]
73
- # @param ttl [Integer, NilClass]
74
- # @param acq_id [String]
75
- # @param hst_id [String]
76
- # @param ts [Numeric]
77
- # @param acq_time [Numeric]
78
- # @param instrument [NilClass,Any]
79
- # @return [void]
80
- #
81
- # @api private
82
- # @since 1.7.0
83
- # @version 1.9.0
84
- def lock_obtained(
85
- instrumenter,
86
- instr_sampled,
87
- lock_key,
88
- ttl,
89
- acq_id,
90
- hst_id,
91
- ts,
92
- acq_time,
93
- instrument
94
- )
95
- return unless instr_sampled
96
- instrumenter.notify('redis_queued_locks.lock_obtained', {
97
- lock_key:, ttl:, acq_id:, hst_id:, ts:, acq_time:, instrument:
98
- }) rescue nil
99
- end
100
-
101
- # @param instrumenter [#notify]
102
- # @param instr_sampled [Boolean]
103
- # @param lock_key [String]
104
- # @param ttl [Integer, NilClass]
105
- # @param acq_id [String]
106
- # @param hst_id [String]
107
- # @param ts [Numeric]
108
- # @param acq_time [Numeric]
109
- # @param hold_time [Numeric]
110
- # @param instrument [NilClass,Any]
111
- # @return [void]
112
- #
113
- # @api private
114
- # @since 1.7.0
115
- # @version 1.9.0
116
- def reentrant_lock_hold_completes(
117
- instrumenter,
118
- instr_sampled,
119
- lock_key,
120
- ttl,
121
- acq_id,
122
- hst_id,
123
- ts,
124
- acq_time,
125
- hold_time,
126
- instrument
127
- )
128
- return unless instr_sampled
129
- instrumenter.notify('redis_queued_locks.reentrant_lock_hold_completes', {
130
- hold_time:, ttl:, acq_id:, hst_id:, ts:, lock_key:, acq_time:, instrument:
131
- }) rescue nil
132
- end
133
-
134
- # @param instrumenter [#notify]
135
- # @param instr_sampled [Boolean]
136
- # @param lock_key [String]
137
- # @param ttl [Integer, NilClass]
138
- # @param acq_id [String]
139
- # @param hst_id [String]
140
- # @param ts [Numeric]
141
- # @param acq_time [Numeric]
142
- # @param hold_time [Numeric]
143
- # @param instrument [NilClass,Any]
144
- # @return [void]
145
- #
146
- # @api private
147
- # @since 1.7.0
148
- # @version 1.9.0
149
- def lock_hold_and_release(
150
- instrumenter,
151
- instr_sampled,
152
- lock_key,
153
- ttl,
154
- acq_id,
155
- hst_id,
156
- ts,
157
- acq_time,
158
- hold_time,
159
- instrument
160
- )
161
- return unless instr_sampled
162
- instrumenter.notify('redis_queued_locks.lock_hold_and_release', {
163
- hold_time:, ttl:, acq_id:, hst_id:, ts:, lock_key:, acq_time:, instrument:
164
- }) rescue nil
165
- end
166
- end
@@ -1,216 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # @api private
4
- # @since 1.7.0
5
- # rubocop:disable Metrics/ModuleLength
6
- module RedisQueuedLocks::Acquier::AcquireLock::LogVisitor
7
- extend self
8
-
9
- # @param logger [::Logger,#debug]
10
- # @param log_sampled [Boolean]
11
- # @param lock_key [String]
12
- # @param queue_ttl [Integer]
13
- # @param acquier_id [String]
14
- # @param host_id [String]
15
- # @param access_strategy [Symbol]
16
- # @return [void]
17
- #
18
- # @api private
19
- # @since 1.7.0
20
- # @version 1.9.0
21
- def start_lock_obtaining(
22
- logger,
23
- log_sampled,
24
- lock_key,
25
- queue_ttl,
26
- acquier_id,
27
- host_id,
28
- access_strategy
29
- )
30
- return unless log_sampled
31
-
32
- logger.debug do
33
- "[redis_queued_locks.start_lock_obtaining] " \
34
- "lock_key => '#{lock_key}' " \
35
- "queue_ttl => #{queue_ttl} " \
36
- "acq_id => '#{acquier_id}' " \
37
- "hst_id => '#{host_id}' " \
38
- "acs_strat => '#{access_strategy}'"
39
- end rescue nil
40
- end
41
-
42
- # @param logger [::Logger,#debug]
43
- # @param log_sampled [Boolean]
44
- # @param lock_key [String]
45
- # @param queue_ttl [Integer]
46
- # @param acquier_id [String]
47
- # @param host_id [String]
48
- # @param access_strategy [Symbol]
49
- # @return [void]
50
- #
51
- # @api private
52
- # @since 1.7.0
53
- # @version 1.9.0
54
- def start_try_to_lock_cycle(
55
- logger,
56
- log_sampled,
57
- lock_key,
58
- queue_ttl,
59
- acquier_id,
60
- host_id,
61
- access_strategy
62
- )
63
- return unless log_sampled
64
-
65
- logger.debug do
66
- "[redis_queued_locks.start_try_to_lock_cycle] " \
67
- "lock_key => '#{lock_key}' " \
68
- "queue_ttl => #{queue_ttl} " \
69
- "acq_id => '#{acquier_id}' " \
70
- "hst_id => '#{host_id}' " \
71
- "acs_strat => '#{access_strategy}'"
72
- end rescue nil
73
- end
74
-
75
- # @param logger [::Logger,#debug]
76
- # @param log_sampled [Boolean]
77
- # @param lock_key [String]
78
- # @param queue_ttl [Integer]
79
- # @param acquier_id [String]
80
- # @param host_id [String]
81
- # @param access_strategy [Symbol]
82
- # @return [void]
83
- #
84
- # @api private
85
- # @since 1.7.0
86
- # @version 1.9.0
87
- def dead_score_reached__reset_acquier_position(
88
- logger,
89
- log_sampled,
90
- lock_key,
91
- queue_ttl,
92
- acquier_id,
93
- host_id,
94
- access_strategy
95
- )
96
- return unless log_sampled
97
-
98
- logger.debug do
99
- "[redis_queued_locks.dead_score_reached__reset_acquier_position] " \
100
- "lock_key => '#{lock_key}' " \
101
- "queue_ttl => #{queue_ttl} " \
102
- "acq_id => '#{acquier_id}' " \
103
- "hst_id => '#{host_id}' " \
104
- "acs_strat => '#{access_strategy}'"
105
- end rescue nil
106
- end
107
-
108
- # @param logger [::Logger,#debug]
109
- # @param log_sampled [Boolean]
110
- # @param lock_key [String]
111
- # @param queue_ttl [Integer]
112
- # @param acquier_id [String]
113
- # @param host_id [String]
114
- # @param acq_time [Numeric]
115
- # @param access_strategy [Symbol]
116
- # @return [void]
117
- #
118
- # @api private
119
- # @since 1.7.0
120
- # @version 1.9.0
121
- def extendable_reentrant_lock_obtained(
122
- logger,
123
- log_sampled,
124
- lock_key,
125
- queue_ttl,
126
- acquier_id,
127
- host_id,
128
- acq_time,
129
- access_strategy
130
- )
131
- return unless log_sampled
132
-
133
- logger.debug do
134
- "[redis_queued_locks.extendable_reentrant_lock_obtained] " \
135
- "lock_key => '#{lock_key}' " \
136
- "queue_ttl => #{queue_ttl} " \
137
- "acq_id => '#{acquier_id}' " \
138
- "host_id => '#{host_id}' " \
139
- "acs_strat => '#{access_strategy}' " \
140
- "acq_time => #{acq_time} (ms)"
141
- end rescue nil
142
- end
143
-
144
- # @param logger [::Logger,#debug]
145
- # @param log_sampled [Boolean]
146
- # @param lock_key [String]
147
- # @param queue_ttl [Integer]
148
- # @param acquier_id [String]
149
- # @param host_id [String]
150
- # @param acq_time [Numeric]
151
- # @param access_strategy [Symbol]
152
- # @return [void]
153
- #
154
- # @api private
155
- # @since 1.7.0
156
- # @version 1.9.0
157
- def reentrant_lock_obtained(
158
- logger,
159
- log_sampled,
160
- lock_key,
161
- queue_ttl,
162
- acquier_id,
163
- host_id,
164
- acq_time,
165
- access_strategy
166
- )
167
- return unless log_sampled
168
-
169
- logger.debug do
170
- "[redis_queued_locks.reentrant_lock_obtained] " \
171
- "lock_key => '#{lock_key}' " \
172
- "queue_ttl => #{queue_ttl} " \
173
- "acq_id => '#{acquier_id}' " \
174
- "hst_id => '#{host_id}' " \
175
- "acs_strat => '#{access_strategy}' " \
176
- "acq_time => #{acq_time} (ms)"
177
- end rescue nil
178
- end
179
-
180
- # @param logger [::Logger,#debug]
181
- # @param log_sampled [Boolean]
182
- # @param lock_key [String]
183
- # @param queue_ttl [Integer]
184
- # @param acquier_id [String]
185
- # @param host_id [String]
186
- # @param acq_time [Numeric]
187
- # @param access_strategy [Symbol]
188
- # @return [void]
189
- #
190
- # @api private
191
- # @since 1.7.0
192
- # @version 1.9.0
193
- def lock_obtained(
194
- logger,
195
- log_sampled,
196
- lock_key,
197
- queue_ttl,
198
- acquier_id,
199
- host_id,
200
- acq_time,
201
- access_strategy
202
- )
203
- return unless log_sampled
204
-
205
- logger.debug do
206
- "[redis_queued_locks.lock_obtained] " \
207
- "lock_key => '#{lock_key}' " \
208
- "queue_ttl => #{queue_ttl} " \
209
- "acq_id => '#{acquier_id}' " \
210
- "hst_id => '#{host_id}' " \
211
- "acs_strat => '#{access_strategy}' " \
212
- "acq_time => #{acq_time} (ms)"
213
- end rescue nil
214
- end
215
- end
216
- # rubocop:enable Metrics/ModuleLength