redis_queued_locks 1.12.0 → 1.13.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 (121) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -1
  3. data/.ruby-version +1 -1
  4. data/CHANGELOG.md +42 -5
  5. data/LICENSE.txt +1 -1
  6. data/README.md +231 -203
  7. data/Rakefile +12 -4
  8. data/Steepfile +16 -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 -13
  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 +43 -20
  21. data/lib/redis_queued_locks/{acquier → acquirer}/acquire_lock.rb +69 -42
  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 +23 -18
  32. data/lib/redis_queued_locks/{acquier → acquirer}/release_lock.rb +25 -19
  33. data/lib/redis_queued_locks/acquirer.rb +18 -0
  34. data/lib/redis_queued_locks/client.rb +164 -254
  35. data/lib/redis_queued_locks/config/dsl.rb +94 -0
  36. data/lib/redis_queued_locks/config.rb +231 -0
  37. data/lib/redis_queued_locks/data.rb +2 -0
  38. data/lib/redis_queued_locks/errors.rb +27 -11
  39. data/lib/redis_queued_locks/instrument.rb +11 -4
  40. data/lib/redis_queued_locks/logging/void_logger.rb +38 -1
  41. data/lib/redis_queued_locks/logging.rb +20 -5
  42. data/lib/redis_queued_locks/resource.rb +49 -11
  43. data/lib/redis_queued_locks/swarm/acquirers.rb +17 -16
  44. data/lib/redis_queued_locks/swarm/flush_zombies.rb +26 -25
  45. data/lib/redis_queued_locks/swarm/probe_hosts.rb +20 -19
  46. data/lib/redis_queued_locks/swarm/redis_client_builder.rb +3 -3
  47. data/lib/redis_queued_locks/swarm/supervisor.rb +19 -6
  48. data/lib/redis_queued_locks/swarm/swarm_element/isolated.rb +20 -18
  49. data/lib/redis_queued_locks/swarm/swarm_element/threaded.rb +35 -27
  50. data/lib/redis_queued_locks/swarm/zombie_info.rb +9 -9
  51. data/lib/redis_queued_locks/swarm.rb +20 -41
  52. data/lib/redis_queued_locks/utilities/lock.rb +4 -2
  53. data/lib/redis_queued_locks/utilities.rb +2 -2
  54. data/lib/redis_queued_locks/version.rb +2 -2
  55. data/lib/redis_queued_locks.rb +2 -2
  56. data/rbs_collection.lock.yaml +40 -0
  57. data/rbs_collection.yaml +16 -0
  58. data/redis_queued_locks.gemspec +22 -23
  59. data/sig/manifest.yml +7 -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 +51 -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/client.rbs +195 -0
  84. data/sig/redis_queued_locks/config/dsl.rbs +26 -0
  85. data/sig/redis_queued_locks/config.rbs +23 -0
  86. data/sig/redis_queued_locks/data.rbs +4 -0
  87. data/sig/redis_queued_locks/debugger/interface.rbs +9 -0
  88. data/sig/redis_queued_locks/debugger.rbs +13 -0
  89. data/sig/redis_queued_locks/errors.rbs +43 -0
  90. data/sig/redis_queued_locks/instrument/active_support.rbs +7 -0
  91. data/sig/redis_queued_locks/instrument/sampler.rbs +9 -0
  92. data/sig/redis_queued_locks/instrument/void_notifier.rbs +7 -0
  93. data/sig/redis_queued_locks/instrument.rbs +15 -0
  94. data/sig/redis_queued_locks/logging/sampler.rbs +9 -0
  95. data/sig/redis_queued_locks/logging/void_logger.rbs +15 -0
  96. data/sig/redis_queued_locks/logging.rbs +15 -0
  97. data/sig/redis_queued_locks/resource.rbs +42 -0
  98. data/sig/redis_queued_locks/swarm/acquirers.rbs +10 -0
  99. data/sig/redis_queued_locks/swarm/flush_zombies.rbs +13 -0
  100. data/sig/redis_queued_locks/swarm/probe_hosts.rbs +13 -0
  101. data/sig/redis_queued_locks/swarm/redis_client_builder.rbs +19 -0
  102. data/sig/redis_queued_locks/swarm/supervisor.rbs +26 -0
  103. data/sig/redis_queued_locks/swarm/swarm_element/isolated.rbs +52 -0
  104. data/sig/redis_queued_locks/swarm/swarm_element/threaded.rbs +61 -0
  105. data/sig/redis_queued_locks/swarm/swarm_element.rbs +8 -0
  106. data/sig/redis_queued_locks/swarm/zombie_info.rbs +24 -0
  107. data/sig/redis_queued_locks/swarm.rbs +41 -0
  108. data/sig/redis_queued_locks/utilities/lock.rbs +10 -0
  109. data/sig/redis_queued_locks/utilities.rbs +11 -0
  110. data/sig/redis_queued_locks/version.rbs +3 -0
  111. data/sig/redis_queued_locks.rbs +14 -0
  112. data/sig/vendor/active_support.rbs +9 -0
  113. data/sig/vendor/redis_client.rbs +39 -0
  114. data/sig/vendor/semantic_logger.rbs +4 -0
  115. metadata +96 -54
  116. data/lib/redis_queued_locks/acquier/acquire_lock/dequeue_from_lock_queue/log_visitor.rb +0 -40
  117. data/lib/redis_queued_locks/acquier/acquire_lock/instr_visitor.rb +0 -166
  118. data/lib/redis_queued_locks/acquier/acquire_lock/log_visitor.rb +0 -216
  119. data/lib/redis_queued_locks/acquier/acquire_lock/try_to_lock/log_visitor.rb +0 -541
  120. data/lib/redis_queued_locks/acquier/acquire_lock/yield_expire/log_visitor.rb +0 -76
  121. data/lib/redis_queued_locks/acquier.rb +0 -18
data/Rakefile CHANGED
@@ -2,20 +2,28 @@
2
2
 
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rspec/core/rake_task'
5
+ require "steep/rake_task"
5
6
  require 'rubocop'
6
7
  require 'rubocop/rake_task'
7
8
  require 'rubocop-performance'
8
9
  require 'rubocop-rspec'
9
10
  require 'rubocop-rake'
11
+ require 'rubocop-on-rbs'
12
+ require 'rubocop-thread_safety'
10
13
 
11
14
  RuboCop::RakeTask.new(:rubocop) do |t|
12
15
  config_path = File.expand_path(File.join('.rubocop.yml'), __dir__)
13
- t.options = ['--config', config_path]
14
- t.requires << 'rubocop-rspec'
15
- t.requires << 'rubocop-performance'
16
- t.requires << 'rubocop-rake'
16
+ t.options = [
17
+ '--config', config_path,
18
+ '--plugin', 'rubocop-rspec',
19
+ '--plugin', 'rubocop-performance',
20
+ '--plugin', 'rubocop-rake',
21
+ '--plugin', 'rubocop-on-rbs',
22
+ '--plugin', 'rubocop-thread_safety'
23
+ ]
17
24
  end
18
25
 
19
26
  RSpec::Core::RakeTask.new(:rspec)
27
+ Steep::RakeTask.new(:steep)
20
28
 
21
29
  task default: :rspec
data/Steepfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ target :lib do
4
+ signature 'sig'
5
+
6
+ check 'lib'
7
+ ignore 'spec'
8
+
9
+ library 'timeout'
10
+ library 'securerandom'
11
+ library 'logger'
12
+ library 'objspace'
13
+ library 'monitor'
14
+
15
+ configure_code_diagnostics(Steep::Diagnostic::Ruby.strict)
16
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec path: '..'
6
+
7
+ gem 'activesupport'
8
+ gem 'armitage-rubocop'
9
+ gem 'bundler'
10
+ gem 'pry'
11
+ gem 'rake'
12
+ gem 'rbs'
13
+ gem 'rspec'
14
+ gem 'rspec-retry' # NOTE: temporary decision for non-refactored tests
15
+ gem 'simplecov'
16
+ gem 'simplecov-lcov'
17
+ gem 'steep'
@@ -0,0 +1,217 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ redis_queued_locks (1.13.0)
5
+ redis-client (~> 0.20)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (8.0.2)
11
+ base64
12
+ benchmark (>= 0.3)
13
+ bigdecimal
14
+ concurrent-ruby (~> 1.0, >= 1.3.1)
15
+ connection_pool (>= 2.2.5)
16
+ drb
17
+ i18n (>= 1.6, < 2)
18
+ logger (>= 1.4.2)
19
+ minitest (>= 5.1)
20
+ securerandom (>= 0.3)
21
+ tzinfo (~> 2.0, >= 2.0.5)
22
+ uri (>= 0.13.1)
23
+ armitage-rubocop (1.75.7.7)
24
+ rubocop (= 1.75.7)
25
+ rubocop-capybara (= 2.22.1)
26
+ rubocop-factory_bot (= 2.27.1)
27
+ rubocop-on-rbs (= 1.7.0)
28
+ rubocop-performance (= 1.25.0)
29
+ rubocop-rails (= 2.32.0)
30
+ rubocop-rake (= 0.7.1)
31
+ rubocop-rspec (= 3.6.0)
32
+ rubocop-rspec_rails (= 2.31.0)
33
+ rubocop-thread_safety (= 0.7.2)
34
+ ast (2.4.3)
35
+ base64 (0.3.0)
36
+ benchmark (0.4.1)
37
+ bigdecimal (3.2.1)
38
+ coderay (1.1.3)
39
+ concurrent-ruby (1.3.5)
40
+ connection_pool (2.5.3)
41
+ csv (3.3.5)
42
+ diff-lcs (1.6.2)
43
+ docile (1.4.1)
44
+ drb (2.2.3)
45
+ ffi (1.17.2)
46
+ ffi (1.17.2-aarch64-linux-gnu)
47
+ ffi (1.17.2-aarch64-linux-musl)
48
+ ffi (1.17.2-arm-linux-gnu)
49
+ ffi (1.17.2-arm-linux-musl)
50
+ ffi (1.17.2-arm64-darwin)
51
+ ffi (1.17.2-x86-linux-gnu)
52
+ ffi (1.17.2-x86-linux-musl)
53
+ ffi (1.17.2-x86_64-darwin)
54
+ ffi (1.17.2-x86_64-linux-gnu)
55
+ ffi (1.17.2-x86_64-linux-musl)
56
+ fileutils (1.7.3)
57
+ i18n (1.14.7)
58
+ concurrent-ruby (~> 1.0)
59
+ json (2.12.2)
60
+ language_server-protocol (3.17.0.5)
61
+ lint_roller (1.1.0)
62
+ listen (3.9.0)
63
+ rb-fsevent (~> 0.10, >= 0.10.3)
64
+ rb-inotify (~> 0.9, >= 0.9.10)
65
+ logger (1.7.0)
66
+ method_source (1.1.0)
67
+ minitest (5.25.5)
68
+ mutex_m (0.3.0)
69
+ parallel (1.27.0)
70
+ parser (3.3.8.0)
71
+ ast (~> 2.4.1)
72
+ racc
73
+ prism (1.4.0)
74
+ pry (0.15.2)
75
+ coderay (~> 1.1)
76
+ method_source (~> 1.0)
77
+ racc (1.8.1)
78
+ rack (3.1.15)
79
+ rainbow (3.1.1)
80
+ rake (13.3.0)
81
+ rb-fsevent (0.11.2)
82
+ rb-inotify (0.11.1)
83
+ ffi (~> 1.0)
84
+ rbs (3.9.4)
85
+ logger
86
+ redis-client (0.24.0)
87
+ connection_pool
88
+ regexp_parser (2.10.0)
89
+ rspec (3.13.1)
90
+ rspec-core (~> 3.13.0)
91
+ rspec-expectations (~> 3.13.0)
92
+ rspec-mocks (~> 3.13.0)
93
+ rspec-core (3.13.4)
94
+ rspec-support (~> 3.13.0)
95
+ rspec-expectations (3.13.5)
96
+ diff-lcs (>= 1.2.0, < 2.0)
97
+ rspec-support (~> 3.13.0)
98
+ rspec-mocks (3.13.5)
99
+ diff-lcs (>= 1.2.0, < 2.0)
100
+ rspec-support (~> 3.13.0)
101
+ rspec-retry (0.6.2)
102
+ rspec-core (> 3.3)
103
+ rspec-support (3.13.4)
104
+ rubocop (1.75.7)
105
+ json (~> 2.3)
106
+ language_server-protocol (~> 3.17.0.2)
107
+ lint_roller (~> 1.1.0)
108
+ parallel (~> 1.10)
109
+ parser (>= 3.3.0.2)
110
+ rainbow (>= 2.2.2, < 4.0)
111
+ regexp_parser (>= 2.9.3, < 3.0)
112
+ rubocop-ast (>= 1.44.0, < 2.0)
113
+ ruby-progressbar (~> 1.7)
114
+ unicode-display_width (>= 2.4.0, < 4.0)
115
+ rubocop-ast (1.44.1)
116
+ parser (>= 3.3.7.2)
117
+ prism (~> 1.4)
118
+ rubocop-capybara (2.22.1)
119
+ lint_roller (~> 1.1)
120
+ rubocop (~> 1.72, >= 1.72.1)
121
+ rubocop-factory_bot (2.27.1)
122
+ lint_roller (~> 1.1)
123
+ rubocop (~> 1.72, >= 1.72.1)
124
+ rubocop-on-rbs (1.7.0)
125
+ lint_roller (~> 1.1)
126
+ rbs (~> 3.5)
127
+ rubocop (>= 1.72.1, < 2.0)
128
+ zlib
129
+ rubocop-performance (1.25.0)
130
+ lint_roller (~> 1.1)
131
+ rubocop (>= 1.75.0, < 2.0)
132
+ rubocop-ast (>= 1.38.0, < 2.0)
133
+ rubocop-rails (2.32.0)
134
+ activesupport (>= 4.2.0)
135
+ lint_roller (~> 1.1)
136
+ rack (>= 1.1)
137
+ rubocop (>= 1.75.0, < 2.0)
138
+ rubocop-ast (>= 1.44.0, < 2.0)
139
+ rubocop-rake (0.7.1)
140
+ lint_roller (~> 1.1)
141
+ rubocop (>= 1.72.1)
142
+ rubocop-rspec (3.6.0)
143
+ lint_roller (~> 1.1)
144
+ rubocop (~> 1.72, >= 1.72.1)
145
+ rubocop-rspec_rails (2.31.0)
146
+ lint_roller (~> 1.1)
147
+ rubocop (~> 1.72, >= 1.72.1)
148
+ rubocop-rspec (~> 3.5)
149
+ rubocop-thread_safety (0.7.2)
150
+ lint_roller (~> 1.1)
151
+ rubocop (~> 1.72, >= 1.72.1)
152
+ ruby-progressbar (1.13.0)
153
+ securerandom (0.4.1)
154
+ simplecov (0.22.0)
155
+ docile (~> 1.1)
156
+ simplecov-html (~> 0.11)
157
+ simplecov_json_formatter (~> 0.1)
158
+ simplecov-html (0.13.1)
159
+ simplecov-lcov (0.8.0)
160
+ simplecov_json_formatter (0.1.4)
161
+ steep (1.10.0)
162
+ activesupport (>= 5.1)
163
+ concurrent-ruby (>= 1.1.10)
164
+ csv (>= 3.0.9)
165
+ fileutils (>= 1.1.0)
166
+ json (>= 2.1.0)
167
+ language_server-protocol (>= 3.17.0.4, < 4.0)
168
+ listen (~> 3.0)
169
+ logger (>= 1.3.0)
170
+ mutex_m (>= 0.3.0)
171
+ parser (>= 3.1)
172
+ rainbow (>= 2.2.2, < 4.0)
173
+ rbs (~> 3.9)
174
+ securerandom (>= 0.1)
175
+ strscan (>= 1.0.0)
176
+ terminal-table (>= 2, < 5)
177
+ uri (>= 0.12.0)
178
+ strscan (3.1.5)
179
+ terminal-table (4.0.0)
180
+ unicode-display_width (>= 1.1.1, < 4)
181
+ tzinfo (2.0.6)
182
+ concurrent-ruby (~> 1.0)
183
+ unicode-display_width (3.1.4)
184
+ unicode-emoji (~> 4.0, >= 4.0.4)
185
+ unicode-emoji (4.0.4)
186
+ uri (1.0.3)
187
+ zlib (3.2.1)
188
+
189
+ PLATFORMS
190
+ aarch64-linux-gnu
191
+ aarch64-linux-musl
192
+ arm-linux-gnu
193
+ arm-linux-musl
194
+ arm64-darwin
195
+ ruby
196
+ x86-linux-gnu
197
+ x86-linux-musl
198
+ x86_64-darwin
199
+ x86_64-linux-gnu
200
+ x86_64-linux-musl
201
+
202
+ DEPENDENCIES
203
+ activesupport
204
+ armitage-rubocop
205
+ bundler
206
+ pry
207
+ rake
208
+ rbs
209
+ redis_queued_locks!
210
+ rspec
211
+ rspec-retry
212
+ simplecov
213
+ simplecov-lcov
214
+ steep
215
+
216
+ BUNDLED WITH
217
+ 2.6.9
@@ -2,17 +2,17 @@
2
2
 
3
3
  # @api private
4
4
  # @since 1.0.0
5
- module RedisQueuedLocks::Acquier::AcquireLock::DelayExecution
5
+ module RedisQueuedLocks::Acquirer::AcquireLock::DelayExecution
6
6
  # Sleep with random time-shifting (it is necessary for empty lock-acquirement time slots).
7
7
  #
8
8
  # @param retry_delay [Integer] In milliseconds
9
9
  # @param retry_jitter [Integer] In milliseconds
10
- # @return [void]
10
+ # @return [Integer] Slept seconds
11
11
  #
12
12
  # @api private
13
13
  # @since 1.0.0
14
14
  def delay_execution(retry_delay, retry_jitter)
15
- delay = (retry_delay + rand(retry_jitter)).to_f / 1_000
16
- sleep(delay)
15
+ delay = (retry_delay + ::Kernel.rand(retry_jitter)).to_f / 1_000
16
+ ::Kernel.sleep(delay)
17
17
  end
18
18
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 1.7.0
5
+ module RedisQueuedLocks::Acquirer::AcquireLock::DequeueFromLockQueue::LogVisitor
6
+ class << self
7
+ # @param logger [::Logger,#debug]
8
+ # @param log_sampled [Boolean]
9
+ # @param lock_key [String]
10
+ # @param queue_ttl [Integer]
11
+ # @param acquirer_id [String]
12
+ # @param host_id [String]
13
+ # @param access_strategy [Symbol]
14
+ # @return [void]
15
+ #
16
+ # @api private
17
+ # @since 1.7.0
18
+ # @version 1.9.0
19
+ def dequeue_from_lock_queue(
20
+ logger,
21
+ log_sampled,
22
+ lock_key,
23
+ queue_ttl,
24
+ acquirer_id,
25
+ host_id,
26
+ access_strategy
27
+ )
28
+ return unless log_sampled
29
+
30
+ logger.debug do
31
+ "[redis_queued_locks.fail_fast_or_limits_reached_or_deadlock__dequeue] " \
32
+ "lock_key => '#{lock_key}' " \
33
+ "queue_ttl => #{queue_ttl} " \
34
+ "acq_id => '#{acquirer_id}' " \
35
+ "hst_id => '#{host_id}' " \
36
+ "acs_strat => '#{access_strategy}"
37
+ end rescue nil
38
+ end
39
+ end
40
+ end
@@ -2,41 +2,50 @@
2
2
 
3
3
  # @api private
4
4
  # @since 1.7.0
5
- module RedisQueuedLocks::Acquier::AcquireLock::DequeueFromLockQueue
5
+ module RedisQueuedLocks::Acquirer::AcquireLock::DequeueFromLockQueue
6
6
  require_relative 'dequeue_from_lock_queue/log_visitor'
7
7
 
8
8
  # @param redis [RedisClient]
9
9
  # @param logger [::Logger,#debug]
10
10
  # @param lock_key [String]
11
+ # @param read_write_mode [Symbol]
11
12
  # @param lock_key_queue [String]
13
+ # @param read_lock_key_queue [String]
14
+ # @param write_lock_key_queue [String]
12
15
  # @param queue_ttl [Integer]
13
- # @param acquier_id [String]
16
+ # @param acquirer_id [String]
14
17
  # @param host_id [String]
15
18
  # @param access_strategy [Symbol]
16
19
  # @param log_sampled [Boolean]
17
20
  # @param instr_sampled [Boolean]
18
- # @return [Hash<Symbol,Any>] Format: { ok: true/false, result: Any }
21
+ # @return [Hash<Symbol,Any>] Format: { ok: true/false, result: Integer }
19
22
  #
20
23
  # @api private
21
24
  # @since 1.7.0
22
- # @version 1.9.0
25
+ # @version 1.13.0
23
26
  def dequeue_from_lock_queue(
24
27
  redis,
25
28
  logger,
26
29
  lock_key,
30
+ read_write_mode,
27
31
  lock_key_queue,
32
+ read_lock_key_queue,
33
+ write_lock_key_queue,
28
34
  queue_ttl,
29
- acquier_id,
35
+ acquirer_id,
30
36
  host_id,
31
37
  access_strategy,
32
38
  log_sampled,
33
39
  instr_sampled
34
40
  )
35
- result = redis.call('ZREM', lock_key_queue, acquier_id)
41
+ # @type var result: Integer
42
+ result = redis.call('ZREM', lock_key_queue, acquirer_id)
43
+
36
44
  LogVisitor.dequeue_from_lock_queue(
37
45
  logger, log_sampled,
38
- lock_key, queue_ttl, acquier_id, host_id, access_strategy
46
+ lock_key, queue_ttl, acquirer_id, host_id, access_strategy
39
47
  )
40
- RedisQueuedLocks::Data[ok: true, result: result]
48
+
49
+ { ok: true, result: result }
41
50
  end
42
51
  end
@@ -0,0 +1,166 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 1.7.0
5
+ module RedisQueuedLocks::Acquirer::AcquireLock::InstrVisitor
6
+ class << self
7
+ # @param instrumenter [#notify]
8
+ # @param instr_sampled [Boolean]
9
+ # @param lock_key [String]
10
+ # @param ttl [Integer, NilClass]
11
+ # @param acq_id [String]
12
+ # @param hst_id [String]
13
+ # @param ts [Numeric]
14
+ # @param acq_time [Numeric]
15
+ # @param instrument [NilClass,Any]
16
+ # @return [void]
17
+ #
18
+ # @api private
19
+ # @since 1.7.0
20
+ # @version 1.9.0
21
+ def extendable_reentrant_lock_obtained(
22
+ instrumenter,
23
+ instr_sampled,
24
+ lock_key,
25
+ ttl,
26
+ acq_id,
27
+ hst_id,
28
+ ts,
29
+ acq_time,
30
+ instrument
31
+ )
32
+ return unless instr_sampled
33
+ instrumenter.notify('redis_queued_locks.extendable_reentrant_lock_obtained', {
34
+ lock_key:, ttl:, acq_id:, hst_id:, ts:, acq_time:, instrument:
35
+ }) rescue nil
36
+ end
37
+
38
+ # @param instrumenter [#notify]
39
+ # @param instr_sampled [Boolean]
40
+ # @param lock_key [String]
41
+ # @param ttl [Integer, NilClass]
42
+ # @param acq_id [String]
43
+ # @param hst_id [String]
44
+ # @param ts [Numeric]
45
+ # @param acq_time [Numeric]
46
+ # @param instrument [NilClass,Any]
47
+ # @return [void]
48
+ #
49
+ # @api private
50
+ # @since 1.7.0
51
+ # @version 1.9.0
52
+ def reentrant_lock_obtained(
53
+ instrumenter,
54
+ instr_sampled,
55
+ lock_key,
56
+ ttl,
57
+ acq_id,
58
+ hst_id,
59
+ ts,
60
+ acq_time,
61
+ instrument
62
+ )
63
+ return unless instr_sampled
64
+ instrumenter.notify('redis_queued_locks.reentrant_lock_obtained', {
65
+ lock_key:, ttl:, acq_id:, hst_id:, ts:, acq_time:, instrument:
66
+ }) rescue nil
67
+ end
68
+
69
+ # @param instrumenter [#notify]
70
+ # @param instr_sampled [Boolean]
71
+ # @param lock_key [String]
72
+ # @param ttl [Integer, NilClass]
73
+ # @param acq_id [String]
74
+ # @param hst_id [String]
75
+ # @param ts [Numeric]
76
+ # @param acq_time [Numeric]
77
+ # @param instrument [NilClass,Any]
78
+ # @return [void]
79
+ #
80
+ # @api private
81
+ # @since 1.7.0
82
+ # @version 1.9.0
83
+ def lock_obtained(
84
+ instrumenter,
85
+ instr_sampled,
86
+ lock_key,
87
+ ttl,
88
+ acq_id,
89
+ hst_id,
90
+ ts,
91
+ acq_time,
92
+ instrument
93
+ )
94
+ return unless instr_sampled
95
+ instrumenter.notify('redis_queued_locks.lock_obtained', {
96
+ lock_key:, ttl:, acq_id:, hst_id:, ts:, acq_time:, instrument:
97
+ }) rescue nil
98
+ end
99
+
100
+ # @param instrumenter [#notify]
101
+ # @param instr_sampled [Boolean]
102
+ # @param lock_key [String]
103
+ # @param ttl [Integer, NilClass]
104
+ # @param acq_id [String]
105
+ # @param hst_id [String]
106
+ # @param ts [Numeric]
107
+ # @param acq_time [Numeric]
108
+ # @param hold_time [Numeric]
109
+ # @param instrument [NilClass,Any]
110
+ # @return [void]
111
+ #
112
+ # @api private
113
+ # @since 1.7.0
114
+ # @version 1.9.0
115
+ def reentrant_lock_hold_completes(
116
+ instrumenter,
117
+ instr_sampled,
118
+ lock_key,
119
+ ttl,
120
+ acq_id,
121
+ hst_id,
122
+ ts,
123
+ acq_time,
124
+ hold_time,
125
+ instrument
126
+ )
127
+ return unless instr_sampled
128
+ instrumenter.notify('redis_queued_locks.reentrant_lock_hold_completes', {
129
+ hold_time:, ttl:, acq_id:, hst_id:, ts:, lock_key:, acq_time:, instrument:
130
+ }) rescue nil
131
+ end
132
+
133
+ # @param instrumenter [#notify]
134
+ # @param instr_sampled [Boolean]
135
+ # @param lock_key [String]
136
+ # @param ttl [Integer, NilClass]
137
+ # @param acq_id [String]
138
+ # @param hst_id [String]
139
+ # @param ts [Numeric]
140
+ # @param acq_time [Numeric]
141
+ # @param hold_time [Numeric]
142
+ # @param instrument [NilClass,Any]
143
+ # @return [void]
144
+ #
145
+ # @api private
146
+ # @since 1.7.0
147
+ # @version 1.9.0
148
+ def lock_hold_and_release(
149
+ instrumenter,
150
+ instr_sampled,
151
+ lock_key,
152
+ ttl,
153
+ acq_id,
154
+ hst_id,
155
+ ts,
156
+ acq_time,
157
+ hold_time,
158
+ instrument
159
+ )
160
+ return unless instr_sampled
161
+ instrumenter.notify('redis_queued_locks.lock_hold_and_release', {
162
+ hold_time:, ttl:, acq_id:, hst_id:, ts:, lock_key:, acq_time:, instrument:
163
+ }) rescue nil
164
+ end
165
+ end
166
+ end