redis_queued_locks 1.6.0 → 1.8.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -1
- data/README.md +224 -53
- data/lib/redis_queued_locks/acquier/acquire_lock/dequeue_from_lock_queue/log_visitor.rb +36 -0
- data/lib/redis_queued_locks/acquier/acquire_lock/dequeue_from_lock_queue.rb +39 -0
- data/lib/redis_queued_locks/acquier/acquire_lock/instr_visitor.rb +151 -0
- data/lib/redis_queued_locks/acquier/acquire_lock/log_visitor.rb +192 -0
- data/lib/redis_queued_locks/acquier/acquire_lock/try_to_lock/log_visitor.rb +485 -0
- data/lib/redis_queued_locks/acquier/acquire_lock/try_to_lock.rb +73 -198
- data/lib/redis_queued_locks/acquier/acquire_lock/with_acq_timeout.rb +41 -7
- data/lib/redis_queued_locks/acquier/acquire_lock/yield_expire/log_visitor.rb +68 -0
- data/lib/redis_queued_locks/acquier/acquire_lock/yield_expire.rb +25 -26
- data/lib/redis_queued_locks/acquier/acquire_lock.rb +100 -112
- data/lib/redis_queued_locks/client.rb +83 -2
- data/lib/redis_queued_locks/utilities.rb +0 -1
- data/lib/redis_queued_locks/version.rb +2 -2
- data/lib/redis_queued_locks/watcher.rb +1 -0
- data/redis_queued_locks.gemspec +19 -3
- metadata +22 -6
@@ -0,0 +1,151 @@
|
|
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 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
|
+
def extendable_reentrant_lock_obtained(
|
21
|
+
instrumenter,
|
22
|
+
instr_sampled,
|
23
|
+
lock_key,
|
24
|
+
ttl,
|
25
|
+
acq_id,
|
26
|
+
ts,
|
27
|
+
acq_time,
|
28
|
+
instrument
|
29
|
+
)
|
30
|
+
return unless instr_sampled
|
31
|
+
instrumenter.notify('redis_queued_locks.extendable_reentrant_lock_obtained', {
|
32
|
+
lock_key:, ttl:, acq_id:, ts:, acq_time:, instrument:
|
33
|
+
}) rescue nil
|
34
|
+
end
|
35
|
+
|
36
|
+
# @param instrumenter [#notify]
|
37
|
+
# @param instr_sampled [Boolean]
|
38
|
+
# @param lock_key [String]
|
39
|
+
# @param ttl [Integer, NilClass]
|
40
|
+
# @param acq_id [String]
|
41
|
+
# @param ts [Numeric]
|
42
|
+
# @param acq_time [Numeric]
|
43
|
+
# @param instrument [NilClass,Any]
|
44
|
+
# @return [void]
|
45
|
+
#
|
46
|
+
# @api private
|
47
|
+
# @since 1.7.0
|
48
|
+
def reentrant_lock_obtained(
|
49
|
+
instrumenter,
|
50
|
+
instr_sampled,
|
51
|
+
lock_key,
|
52
|
+
ttl,
|
53
|
+
acq_id,
|
54
|
+
ts,
|
55
|
+
acq_time,
|
56
|
+
instrument
|
57
|
+
)
|
58
|
+
return unless instr_sampled
|
59
|
+
instrumenter.notify('redis_queued_locks.reentrant_lock_obtained', {
|
60
|
+
lock_key:, ttl:, acq_id:, ts:, acq_time:, instrument:
|
61
|
+
}) rescue nil
|
62
|
+
end
|
63
|
+
|
64
|
+
# @param instrumenter [#notify]
|
65
|
+
# @param instr_sampled [Boolean]
|
66
|
+
# @param lock_key [String]
|
67
|
+
# @param ttl [Integer, NilClass]
|
68
|
+
# @param acq_id [String]
|
69
|
+
# @param ts [Numeric]
|
70
|
+
# @param acq_time [Numeric]
|
71
|
+
# @param instrument [NilClass,Any]
|
72
|
+
# @return [void]
|
73
|
+
#
|
74
|
+
# @api private
|
75
|
+
# @since 1.7.0
|
76
|
+
def lock_obtained(
|
77
|
+
instrumenter,
|
78
|
+
instr_sampled,
|
79
|
+
lock_key,
|
80
|
+
ttl,
|
81
|
+
acq_id,
|
82
|
+
ts,
|
83
|
+
acq_time,
|
84
|
+
instrument
|
85
|
+
)
|
86
|
+
return unless instr_sampled
|
87
|
+
instrumenter.notify('redis_queued_locks.lock_obtained', {
|
88
|
+
lock_key:, ttl:, acq_id:, ts:, acq_time:, instrument:
|
89
|
+
}) rescue nil
|
90
|
+
end
|
91
|
+
|
92
|
+
# @param instrumenter [#notify]
|
93
|
+
# @param instr_sampled [Boolean]
|
94
|
+
# @param lock_key [String]
|
95
|
+
# @param ttl [Integer, NilClass]
|
96
|
+
# @param acq_id [String]
|
97
|
+
# @param ts [Numeric]
|
98
|
+
# @param acq_time [Numeric]
|
99
|
+
# @param hold_time [Numeric]
|
100
|
+
# @param instrument [NilClass,Any]
|
101
|
+
# @return [void]
|
102
|
+
#
|
103
|
+
# @api private
|
104
|
+
# @since 1.7.0
|
105
|
+
def reentrant_lock_hold_completes(
|
106
|
+
instrumenter,
|
107
|
+
instr_sampled,
|
108
|
+
lock_key,
|
109
|
+
ttl,
|
110
|
+
acq_id,
|
111
|
+
ts,
|
112
|
+
acq_time,
|
113
|
+
hold_time,
|
114
|
+
instrument
|
115
|
+
)
|
116
|
+
return unless instr_sampled
|
117
|
+
instrumenter.notify('redis_queued_locks.reentrant_lock_hold_completes', {
|
118
|
+
hold_time:, ttl:, acq_id:, ts:, lock_key:, acq_time:, instrument:
|
119
|
+
}) rescue nil
|
120
|
+
end
|
121
|
+
|
122
|
+
# @param instrumenter [#notify]
|
123
|
+
# @param instr_sampled [Boolean]
|
124
|
+
# @param lock_key [String]
|
125
|
+
# @param ttl [Integer, NilClass]
|
126
|
+
# @param acq_id [String]
|
127
|
+
# @param ts [Numeric]
|
128
|
+
# @param acq_time [Numeric]
|
129
|
+
# @param hold_time [Numeric]
|
130
|
+
# @param instrument [NilClass,Any]
|
131
|
+
# @return [void]
|
132
|
+
#
|
133
|
+
# @api private
|
134
|
+
# @since 1.7.0
|
135
|
+
def lock_hold_and_release(
|
136
|
+
instrumenter,
|
137
|
+
instr_sampled,
|
138
|
+
lock_key,
|
139
|
+
ttl,
|
140
|
+
acq_id,
|
141
|
+
ts,
|
142
|
+
acq_time,
|
143
|
+
hold_time,
|
144
|
+
instrument
|
145
|
+
)
|
146
|
+
return unless instr_sampled
|
147
|
+
instrumenter.notify('redis_queued_locks.lock_hold_and_release', {
|
148
|
+
hold_time:, ttl:, acq_id:, ts:, lock_key:, acq_time:, instrument:
|
149
|
+
}) rescue nil
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,192 @@
|
|
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 access_strategy [Symbol]
|
15
|
+
# @return [void]
|
16
|
+
#
|
17
|
+
# @api private
|
18
|
+
# @since 1.7.0
|
19
|
+
def start_lock_obtaining(
|
20
|
+
logger,
|
21
|
+
log_sampled,
|
22
|
+
lock_key,
|
23
|
+
queue_ttl,
|
24
|
+
acquier_id,
|
25
|
+
access_strategy
|
26
|
+
)
|
27
|
+
return unless log_sampled
|
28
|
+
|
29
|
+
logger.debug do
|
30
|
+
"[redis_queued_locks.start_lock_obtaining] " \
|
31
|
+
"lock_key => '#{lock_key}' " \
|
32
|
+
"queue_ttl => #{queue_ttl} " \
|
33
|
+
"acq_id => '#{acquier_id}' " \
|
34
|
+
"acs_strat => '#{access_strategy}'"
|
35
|
+
end rescue nil
|
36
|
+
end
|
37
|
+
|
38
|
+
# @param logger [::Logger,#debug]
|
39
|
+
# @param log_sampled [Boolean]
|
40
|
+
# @param lock_key [String]
|
41
|
+
# @param queue_ttl [Integer]
|
42
|
+
# @param acquier_id [String]
|
43
|
+
# @param access_strategy [Symbol]
|
44
|
+
# @return [void]
|
45
|
+
#
|
46
|
+
# @api private
|
47
|
+
# @since 1.7.0
|
48
|
+
def start_try_to_lock_cycle(
|
49
|
+
logger,
|
50
|
+
log_sampled,
|
51
|
+
lock_key,
|
52
|
+
queue_ttl,
|
53
|
+
acquier_id,
|
54
|
+
access_strategy
|
55
|
+
)
|
56
|
+
return unless log_sampled
|
57
|
+
|
58
|
+
logger.debug do
|
59
|
+
"[redis_queued_locks.start_try_to_lock_cycle] " \
|
60
|
+
"lock_key => '#{lock_key}' " \
|
61
|
+
"queue_ttl => #{queue_ttl} " \
|
62
|
+
"acq_id => '#{acquier_id}' " \
|
63
|
+
"acs_strat => '#{access_strategy}'"
|
64
|
+
end rescue nil
|
65
|
+
end
|
66
|
+
|
67
|
+
# @param logger [::Logger,#debug]
|
68
|
+
# @param log_sampled [Boolean]
|
69
|
+
# @param lock_key [String]
|
70
|
+
# @param queue_ttl [Integer]
|
71
|
+
# @param acquier_id [String]
|
72
|
+
# @param access_strategy [Symbol]
|
73
|
+
# @return [void]
|
74
|
+
#
|
75
|
+
# @api private
|
76
|
+
# @since 1.7.0
|
77
|
+
def dead_score_reached__reset_acquier_position(
|
78
|
+
logger,
|
79
|
+
log_sampled,
|
80
|
+
lock_key,
|
81
|
+
queue_ttl,
|
82
|
+
acquier_id,
|
83
|
+
access_strategy
|
84
|
+
)
|
85
|
+
return unless log_sampled
|
86
|
+
|
87
|
+
logger.debug do
|
88
|
+
"[redis_queued_locks.dead_score_reached__reset_acquier_position] " \
|
89
|
+
"lock_key => '#{lock_key}' " \
|
90
|
+
"queue_ttl => #{queue_ttl} " \
|
91
|
+
"acq_id => '#{acquier_id}' " \
|
92
|
+
"acs_strat => '#{access_strategy}'"
|
93
|
+
end rescue nil
|
94
|
+
end
|
95
|
+
|
96
|
+
# @param logger [::Logger,#debug]
|
97
|
+
# @param log_sampled [Boolean]
|
98
|
+
# @param lock_key [String]
|
99
|
+
# @param queue_ttl [Integer]
|
100
|
+
# @param acquier_id [String]
|
101
|
+
# @param acq_time [Numeric]
|
102
|
+
# @param access_strategy [Symbol]
|
103
|
+
# @return [void]
|
104
|
+
#
|
105
|
+
# @api private
|
106
|
+
# @since 1.7.0
|
107
|
+
def extendable_reentrant_lock_obtained(
|
108
|
+
logger,
|
109
|
+
log_sampled,
|
110
|
+
lock_key,
|
111
|
+
queue_ttl,
|
112
|
+
acquier_id,
|
113
|
+
acq_time,
|
114
|
+
access_strategy
|
115
|
+
)
|
116
|
+
return unless log_sampled
|
117
|
+
|
118
|
+
logger.debug do
|
119
|
+
"[redis_queued_locks.extendable_reentrant_lock_obtained] " \
|
120
|
+
"lock_key => '#{lock_key}' " \
|
121
|
+
"queue_ttl => #{queue_ttl} " \
|
122
|
+
"acq_id => '#{acquier_id}' " \
|
123
|
+
"acs_strat => '#{access_strategy}' " \
|
124
|
+
"acq_time => #{acq_time} (ms)"
|
125
|
+
end rescue nil
|
126
|
+
end
|
127
|
+
|
128
|
+
# @param logger [::Logger,#debug]
|
129
|
+
# @param log_sampled [Boolean]
|
130
|
+
# @param lock_key [String]
|
131
|
+
# @param queue_ttl [Integer]
|
132
|
+
# @param acquier_id [String]
|
133
|
+
# @param acq_time [Numeric]
|
134
|
+
# @param access_strategy [Symbol]
|
135
|
+
# @return [void]
|
136
|
+
#
|
137
|
+
# @api private
|
138
|
+
# @since 1.7.0
|
139
|
+
def reentrant_lock_obtained(
|
140
|
+
logger,
|
141
|
+
log_sampled,
|
142
|
+
lock_key,
|
143
|
+
queue_ttl,
|
144
|
+
acquier_id,
|
145
|
+
acq_time,
|
146
|
+
access_strategy
|
147
|
+
)
|
148
|
+
return unless log_sampled
|
149
|
+
|
150
|
+
logger.debug do
|
151
|
+
"[redis_queued_locks.reentrant_lock_obtained] " \
|
152
|
+
"lock_key => '#{lock_key}' " \
|
153
|
+
"queue_ttl => #{queue_ttl} " \
|
154
|
+
"acq_id => '#{acquier_id}' " \
|
155
|
+
"acs_strat => '#{access_strategy}' " \
|
156
|
+
"acq_time => #{acq_time} (ms)"
|
157
|
+
end rescue nil
|
158
|
+
end
|
159
|
+
|
160
|
+
# @param logger [::Logger,#debug]
|
161
|
+
# @param log_sampled [Boolean]
|
162
|
+
# @param lock_key [String]
|
163
|
+
# @param queue_ttl [Integer]
|
164
|
+
# @param acquier_id [String]
|
165
|
+
# @param acq_time [Numeric]
|
166
|
+
# @param access_strategy [Symbol]
|
167
|
+
# @return [void]
|
168
|
+
#
|
169
|
+
# @api private
|
170
|
+
# @since 1.7.0
|
171
|
+
def lock_obtained(
|
172
|
+
logger,
|
173
|
+
log_sampled,
|
174
|
+
lock_key,
|
175
|
+
queue_ttl,
|
176
|
+
acquier_id,
|
177
|
+
acq_time,
|
178
|
+
access_strategy
|
179
|
+
)
|
180
|
+
return unless log_sampled
|
181
|
+
|
182
|
+
logger.debug do
|
183
|
+
"[redis_queued_locks.lock_obtained] " \
|
184
|
+
"lock_key => '#{lock_key}' " \
|
185
|
+
"queue_ttl => #{queue_ttl} " \
|
186
|
+
"acq_id => '#{acquier_id}' " \
|
187
|
+
"acs_strat => '#{access_strategy}' " \
|
188
|
+
"acq_time => #{acq_time} (ms)"
|
189
|
+
end rescue nil
|
190
|
+
end
|
191
|
+
end
|
192
|
+
# rubocop:enable Metrics/ModuleLength
|