redis_queued_locks 1.8.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/CHANGELOG.md +51 -0
- data/README.md +402 -46
- data/lib/redis_queued_locks/acquier/acquire_lock/dequeue_from_lock_queue/log_visitor.rb +4 -0
- data/lib/redis_queued_locks/acquier/acquire_lock/dequeue_from_lock_queue.rb +4 -1
- data/lib/redis_queued_locks/acquier/acquire_lock/instr_visitor.rb +20 -5
- data/lib/redis_queued_locks/acquier/acquire_lock/log_visitor.rb +24 -0
- data/lib/redis_queued_locks/acquier/acquire_lock/try_to_lock/log_visitor.rb +56 -0
- data/lib/redis_queued_locks/acquier/acquire_lock/try_to_lock.rb +37 -30
- data/lib/redis_queued_locks/acquier/acquire_lock/yield_expire/log_visitor.rb +8 -0
- data/lib/redis_queued_locks/acquier/acquire_lock/yield_expire.rb +13 -9
- data/lib/redis_queued_locks/acquier/acquire_lock.rb +44 -20
- data/lib/redis_queued_locks/acquier/clear_dead_requests.rb +5 -1
- data/lib/redis_queued_locks/acquier/extend_lock_ttl.rb +5 -1
- data/lib/redis_queued_locks/acquier/lock_info.rb +4 -3
- data/lib/redis_queued_locks/acquier/locks.rb +2 -2
- data/lib/redis_queued_locks/acquier/queue_info.rb +2 -2
- data/lib/redis_queued_locks/acquier/release_all_locks.rb +12 -2
- data/lib/redis_queued_locks/acquier/release_lock.rb +12 -2
- data/lib/redis_queued_locks/client.rb +284 -34
- data/lib/redis_queued_locks/errors.rb +8 -0
- data/lib/redis_queued_locks/instrument.rb +8 -1
- data/lib/redis_queued_locks/logging.rb +8 -1
- data/lib/redis_queued_locks/resource.rb +59 -1
- data/lib/redis_queued_locks/swarm/acquirers.rb +44 -0
- data/lib/redis_queued_locks/swarm/flush_zombies.rb +133 -0
- data/lib/redis_queued_locks/swarm/probe_hosts.rb +69 -0
- data/lib/redis_queued_locks/swarm/redis_client_builder.rb +67 -0
- data/lib/redis_queued_locks/swarm/supervisor.rb +83 -0
- data/lib/redis_queued_locks/swarm/swarm_element/isolated.rb +287 -0
- data/lib/redis_queued_locks/swarm/swarm_element/threaded.rb +351 -0
- data/lib/redis_queued_locks/swarm/swarm_element.rb +8 -0
- data/lib/redis_queued_locks/swarm/zombie_info.rb +145 -0
- data/lib/redis_queued_locks/swarm.rb +241 -0
- data/lib/redis_queued_locks/utilities/lock.rb +22 -0
- data/lib/redis_queued_locks/utilities.rb +75 -0
- data/lib/redis_queued_locks/version.rb +2 -2
- data/lib/redis_queued_locks.rb +2 -0
- metadata +14 -4
- data/lib/redis_queued_locks/watcher.rb +0 -1
@@ -10,17 +10,20 @@ module RedisQueuedLocks::Acquier::AcquireLock::DequeueFromLockQueue::LogVisitor
|
|
10
10
|
# @param lock_key [String]
|
11
11
|
# @param queue_ttl [Integer]
|
12
12
|
# @param acquier_id [String]
|
13
|
+
# @param host_id [String]
|
13
14
|
# @param access_strategy [Symbol]
|
14
15
|
# @return [void]
|
15
16
|
#
|
16
17
|
# @api private
|
17
18
|
# @since 1.7.0
|
19
|
+
# @version 1.9.0
|
18
20
|
def dequeue_from_lock_queue(
|
19
21
|
logger,
|
20
22
|
log_sampled,
|
21
23
|
lock_key,
|
22
24
|
queue_ttl,
|
23
25
|
acquier_id,
|
26
|
+
host_id,
|
24
27
|
access_strategy
|
25
28
|
)
|
26
29
|
return unless log_sampled
|
@@ -30,6 +33,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::DequeueFromLockQueue::LogVisitor
|
|
30
33
|
"lock_key => '#{lock_key}' " \
|
31
34
|
"queue_ttl => #{queue_ttl} " \
|
32
35
|
"acq_id => '#{acquier_id}' " \
|
36
|
+
"hst_id => '#{host_id}' " \
|
33
37
|
"acs_strat => '#{access_strategy}"
|
34
38
|
end rescue nil
|
35
39
|
end
|
@@ -11,6 +11,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::DequeueFromLockQueue
|
|
11
11
|
# @param lock_key_queue [String]
|
12
12
|
# @param queue_ttl [Integer]
|
13
13
|
# @param acquier_id [String]
|
14
|
+
# @param host_id [String]
|
14
15
|
# @param access_strategy [Symbol]
|
15
16
|
# @param log_sampled [Boolean]
|
16
17
|
# @param instr_sampled [Boolean]
|
@@ -18,6 +19,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::DequeueFromLockQueue
|
|
18
19
|
#
|
19
20
|
# @api private
|
20
21
|
# @since 1.7.0
|
22
|
+
# @version 1.9.0
|
21
23
|
def dequeue_from_lock_queue(
|
22
24
|
redis,
|
23
25
|
logger,
|
@@ -25,6 +27,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::DequeueFromLockQueue
|
|
25
27
|
lock_key_queue,
|
26
28
|
queue_ttl,
|
27
29
|
acquier_id,
|
30
|
+
host_id,
|
28
31
|
access_strategy,
|
29
32
|
log_sampled,
|
30
33
|
instr_sampled
|
@@ -32,7 +35,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::DequeueFromLockQueue
|
|
32
35
|
result = redis.call('ZREM', lock_key_queue, acquier_id)
|
33
36
|
LogVisitor.dequeue_from_lock_queue(
|
34
37
|
logger, log_sampled,
|
35
|
-
lock_key, queue_ttl, acquier_id, access_strategy
|
38
|
+
lock_key, queue_ttl, acquier_id, host_id, access_strategy
|
36
39
|
)
|
37
40
|
RedisQueuedLocks::Data[ok: true, result: result]
|
38
41
|
end
|
@@ -10,6 +10,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::InstrVisitor
|
|
10
10
|
# @param lock_key [String]
|
11
11
|
# @param ttl [Integer, NilClass]
|
12
12
|
# @param acq_id [String]
|
13
|
+
# @param hst_id [String]
|
13
14
|
# @param ts [Numeric]
|
14
15
|
# @param acq_time [Numeric]
|
15
16
|
# @param instrument [NilClass,Any]
|
@@ -17,19 +18,21 @@ module RedisQueuedLocks::Acquier::AcquireLock::InstrVisitor
|
|
17
18
|
#
|
18
19
|
# @api private
|
19
20
|
# @since 1.7.0
|
21
|
+
# @version 1.9.0
|
20
22
|
def extendable_reentrant_lock_obtained(
|
21
23
|
instrumenter,
|
22
24
|
instr_sampled,
|
23
25
|
lock_key,
|
24
26
|
ttl,
|
25
27
|
acq_id,
|
28
|
+
hst_id,
|
26
29
|
ts,
|
27
30
|
acq_time,
|
28
31
|
instrument
|
29
32
|
)
|
30
33
|
return unless instr_sampled
|
31
34
|
instrumenter.notify('redis_queued_locks.extendable_reentrant_lock_obtained', {
|
32
|
-
lock_key:, ttl:, acq_id:, ts:, acq_time:, instrument:
|
35
|
+
lock_key:, ttl:, acq_id:, hst_id:, ts:, acq_time:, instrument:
|
33
36
|
}) rescue nil
|
34
37
|
end
|
35
38
|
|
@@ -38,6 +41,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::InstrVisitor
|
|
38
41
|
# @param lock_key [String]
|
39
42
|
# @param ttl [Integer, NilClass]
|
40
43
|
# @param acq_id [String]
|
44
|
+
# @param hst_id [String]
|
41
45
|
# @param ts [Numeric]
|
42
46
|
# @param acq_time [Numeric]
|
43
47
|
# @param instrument [NilClass,Any]
|
@@ -45,19 +49,21 @@ module RedisQueuedLocks::Acquier::AcquireLock::InstrVisitor
|
|
45
49
|
#
|
46
50
|
# @api private
|
47
51
|
# @since 1.7.0
|
52
|
+
# @version 1.9.0
|
48
53
|
def reentrant_lock_obtained(
|
49
54
|
instrumenter,
|
50
55
|
instr_sampled,
|
51
56
|
lock_key,
|
52
57
|
ttl,
|
53
58
|
acq_id,
|
59
|
+
hst_id,
|
54
60
|
ts,
|
55
61
|
acq_time,
|
56
62
|
instrument
|
57
63
|
)
|
58
64
|
return unless instr_sampled
|
59
65
|
instrumenter.notify('redis_queued_locks.reentrant_lock_obtained', {
|
60
|
-
lock_key:, ttl:, acq_id:, ts:, acq_time:, instrument:
|
66
|
+
lock_key:, ttl:, acq_id:, hst_id:, ts:, acq_time:, instrument:
|
61
67
|
}) rescue nil
|
62
68
|
end
|
63
69
|
|
@@ -66,6 +72,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::InstrVisitor
|
|
66
72
|
# @param lock_key [String]
|
67
73
|
# @param ttl [Integer, NilClass]
|
68
74
|
# @param acq_id [String]
|
75
|
+
# @param hst_id [String]
|
69
76
|
# @param ts [Numeric]
|
70
77
|
# @param acq_time [Numeric]
|
71
78
|
# @param instrument [NilClass,Any]
|
@@ -73,19 +80,21 @@ module RedisQueuedLocks::Acquier::AcquireLock::InstrVisitor
|
|
73
80
|
#
|
74
81
|
# @api private
|
75
82
|
# @since 1.7.0
|
83
|
+
# @version 1.9.0
|
76
84
|
def lock_obtained(
|
77
85
|
instrumenter,
|
78
86
|
instr_sampled,
|
79
87
|
lock_key,
|
80
88
|
ttl,
|
81
89
|
acq_id,
|
90
|
+
hst_id,
|
82
91
|
ts,
|
83
92
|
acq_time,
|
84
93
|
instrument
|
85
94
|
)
|
86
95
|
return unless instr_sampled
|
87
96
|
instrumenter.notify('redis_queued_locks.lock_obtained', {
|
88
|
-
lock_key:, ttl:, acq_id:, ts:, acq_time:, instrument:
|
97
|
+
lock_key:, ttl:, acq_id:, hst_id:, ts:, acq_time:, instrument:
|
89
98
|
}) rescue nil
|
90
99
|
end
|
91
100
|
|
@@ -94,6 +103,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::InstrVisitor
|
|
94
103
|
# @param lock_key [String]
|
95
104
|
# @param ttl [Integer, NilClass]
|
96
105
|
# @param acq_id [String]
|
106
|
+
# @param hst_id [String]
|
97
107
|
# @param ts [Numeric]
|
98
108
|
# @param acq_time [Numeric]
|
99
109
|
# @param hold_time [Numeric]
|
@@ -102,12 +112,14 @@ module RedisQueuedLocks::Acquier::AcquireLock::InstrVisitor
|
|
102
112
|
#
|
103
113
|
# @api private
|
104
114
|
# @since 1.7.0
|
115
|
+
# @version 1.9.0
|
105
116
|
def reentrant_lock_hold_completes(
|
106
117
|
instrumenter,
|
107
118
|
instr_sampled,
|
108
119
|
lock_key,
|
109
120
|
ttl,
|
110
121
|
acq_id,
|
122
|
+
hst_id,
|
111
123
|
ts,
|
112
124
|
acq_time,
|
113
125
|
hold_time,
|
@@ -115,7 +127,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::InstrVisitor
|
|
115
127
|
)
|
116
128
|
return unless instr_sampled
|
117
129
|
instrumenter.notify('redis_queued_locks.reentrant_lock_hold_completes', {
|
118
|
-
hold_time:, ttl:, acq_id:, ts:, lock_key:, acq_time:, instrument:
|
130
|
+
hold_time:, ttl:, acq_id:, hst_id:, ts:, lock_key:, acq_time:, instrument:
|
119
131
|
}) rescue nil
|
120
132
|
end
|
121
133
|
|
@@ -124,6 +136,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::InstrVisitor
|
|
124
136
|
# @param lock_key [String]
|
125
137
|
# @param ttl [Integer, NilClass]
|
126
138
|
# @param acq_id [String]
|
139
|
+
# @param hst_id [String]
|
127
140
|
# @param ts [Numeric]
|
128
141
|
# @param acq_time [Numeric]
|
129
142
|
# @param hold_time [Numeric]
|
@@ -132,12 +145,14 @@ module RedisQueuedLocks::Acquier::AcquireLock::InstrVisitor
|
|
132
145
|
#
|
133
146
|
# @api private
|
134
147
|
# @since 1.7.0
|
148
|
+
# @version 1.9.0
|
135
149
|
def lock_hold_and_release(
|
136
150
|
instrumenter,
|
137
151
|
instr_sampled,
|
138
152
|
lock_key,
|
139
153
|
ttl,
|
140
154
|
acq_id,
|
155
|
+
hst_id,
|
141
156
|
ts,
|
142
157
|
acq_time,
|
143
158
|
hold_time,
|
@@ -145,7 +160,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::InstrVisitor
|
|
145
160
|
)
|
146
161
|
return unless instr_sampled
|
147
162
|
instrumenter.notify('redis_queued_locks.lock_hold_and_release', {
|
148
|
-
hold_time:, ttl:, acq_id:, ts:, lock_key:, acq_time:, instrument:
|
163
|
+
hold_time:, ttl:, acq_id:, hst_id:, ts:, lock_key:, acq_time:, instrument:
|
149
164
|
}) rescue nil
|
150
165
|
end
|
151
166
|
end
|
@@ -11,17 +11,20 @@ module RedisQueuedLocks::Acquier::AcquireLock::LogVisitor
|
|
11
11
|
# @param lock_key [String]
|
12
12
|
# @param queue_ttl [Integer]
|
13
13
|
# @param acquier_id [String]
|
14
|
+
# @param host_id [String]
|
14
15
|
# @param access_strategy [Symbol]
|
15
16
|
# @return [void]
|
16
17
|
#
|
17
18
|
# @api private
|
18
19
|
# @since 1.7.0
|
20
|
+
# @version 1.9.0
|
19
21
|
def start_lock_obtaining(
|
20
22
|
logger,
|
21
23
|
log_sampled,
|
22
24
|
lock_key,
|
23
25
|
queue_ttl,
|
24
26
|
acquier_id,
|
27
|
+
host_id,
|
25
28
|
access_strategy
|
26
29
|
)
|
27
30
|
return unless log_sampled
|
@@ -31,6 +34,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::LogVisitor
|
|
31
34
|
"lock_key => '#{lock_key}' " \
|
32
35
|
"queue_ttl => #{queue_ttl} " \
|
33
36
|
"acq_id => '#{acquier_id}' " \
|
37
|
+
"hst_id => '#{host_id}' " \
|
34
38
|
"acs_strat => '#{access_strategy}'"
|
35
39
|
end rescue nil
|
36
40
|
end
|
@@ -40,17 +44,20 @@ module RedisQueuedLocks::Acquier::AcquireLock::LogVisitor
|
|
40
44
|
# @param lock_key [String]
|
41
45
|
# @param queue_ttl [Integer]
|
42
46
|
# @param acquier_id [String]
|
47
|
+
# @param host_id [String]
|
43
48
|
# @param access_strategy [Symbol]
|
44
49
|
# @return [void]
|
45
50
|
#
|
46
51
|
# @api private
|
47
52
|
# @since 1.7.0
|
53
|
+
# @version 1.9.0
|
48
54
|
def start_try_to_lock_cycle(
|
49
55
|
logger,
|
50
56
|
log_sampled,
|
51
57
|
lock_key,
|
52
58
|
queue_ttl,
|
53
59
|
acquier_id,
|
60
|
+
host_id,
|
54
61
|
access_strategy
|
55
62
|
)
|
56
63
|
return unless log_sampled
|
@@ -60,6 +67,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::LogVisitor
|
|
60
67
|
"lock_key => '#{lock_key}' " \
|
61
68
|
"queue_ttl => #{queue_ttl} " \
|
62
69
|
"acq_id => '#{acquier_id}' " \
|
70
|
+
"hst_id => '#{host_id}' " \
|
63
71
|
"acs_strat => '#{access_strategy}'"
|
64
72
|
end rescue nil
|
65
73
|
end
|
@@ -69,17 +77,20 @@ module RedisQueuedLocks::Acquier::AcquireLock::LogVisitor
|
|
69
77
|
# @param lock_key [String]
|
70
78
|
# @param queue_ttl [Integer]
|
71
79
|
# @param acquier_id [String]
|
80
|
+
# @param host_id [String]
|
72
81
|
# @param access_strategy [Symbol]
|
73
82
|
# @return [void]
|
74
83
|
#
|
75
84
|
# @api private
|
76
85
|
# @since 1.7.0
|
86
|
+
# @version 1.9.0
|
77
87
|
def dead_score_reached__reset_acquier_position(
|
78
88
|
logger,
|
79
89
|
log_sampled,
|
80
90
|
lock_key,
|
81
91
|
queue_ttl,
|
82
92
|
acquier_id,
|
93
|
+
host_id,
|
83
94
|
access_strategy
|
84
95
|
)
|
85
96
|
return unless log_sampled
|
@@ -89,6 +100,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::LogVisitor
|
|
89
100
|
"lock_key => '#{lock_key}' " \
|
90
101
|
"queue_ttl => #{queue_ttl} " \
|
91
102
|
"acq_id => '#{acquier_id}' " \
|
103
|
+
"hst_id => '#{host_id}' " \
|
92
104
|
"acs_strat => '#{access_strategy}'"
|
93
105
|
end rescue nil
|
94
106
|
end
|
@@ -98,18 +110,21 @@ module RedisQueuedLocks::Acquier::AcquireLock::LogVisitor
|
|
98
110
|
# @param lock_key [String]
|
99
111
|
# @param queue_ttl [Integer]
|
100
112
|
# @param acquier_id [String]
|
113
|
+
# @param host_id [String]
|
101
114
|
# @param acq_time [Numeric]
|
102
115
|
# @param access_strategy [Symbol]
|
103
116
|
# @return [void]
|
104
117
|
#
|
105
118
|
# @api private
|
106
119
|
# @since 1.7.0
|
120
|
+
# @version 1.9.0
|
107
121
|
def extendable_reentrant_lock_obtained(
|
108
122
|
logger,
|
109
123
|
log_sampled,
|
110
124
|
lock_key,
|
111
125
|
queue_ttl,
|
112
126
|
acquier_id,
|
127
|
+
host_id,
|
113
128
|
acq_time,
|
114
129
|
access_strategy
|
115
130
|
)
|
@@ -120,6 +135,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::LogVisitor
|
|
120
135
|
"lock_key => '#{lock_key}' " \
|
121
136
|
"queue_ttl => #{queue_ttl} " \
|
122
137
|
"acq_id => '#{acquier_id}' " \
|
138
|
+
"host_id => '#{host_id}' " \
|
123
139
|
"acs_strat => '#{access_strategy}' " \
|
124
140
|
"acq_time => #{acq_time} (ms)"
|
125
141
|
end rescue nil
|
@@ -130,18 +146,21 @@ module RedisQueuedLocks::Acquier::AcquireLock::LogVisitor
|
|
130
146
|
# @param lock_key [String]
|
131
147
|
# @param queue_ttl [Integer]
|
132
148
|
# @param acquier_id [String]
|
149
|
+
# @param host_id [String]
|
133
150
|
# @param acq_time [Numeric]
|
134
151
|
# @param access_strategy [Symbol]
|
135
152
|
# @return [void]
|
136
153
|
#
|
137
154
|
# @api private
|
138
155
|
# @since 1.7.0
|
156
|
+
# @version 1.9.0
|
139
157
|
def reentrant_lock_obtained(
|
140
158
|
logger,
|
141
159
|
log_sampled,
|
142
160
|
lock_key,
|
143
161
|
queue_ttl,
|
144
162
|
acquier_id,
|
163
|
+
host_id,
|
145
164
|
acq_time,
|
146
165
|
access_strategy
|
147
166
|
)
|
@@ -152,6 +171,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::LogVisitor
|
|
152
171
|
"lock_key => '#{lock_key}' " \
|
153
172
|
"queue_ttl => #{queue_ttl} " \
|
154
173
|
"acq_id => '#{acquier_id}' " \
|
174
|
+
"hst_id => '#{host_id}' " \
|
155
175
|
"acs_strat => '#{access_strategy}' " \
|
156
176
|
"acq_time => #{acq_time} (ms)"
|
157
177
|
end rescue nil
|
@@ -162,18 +182,21 @@ module RedisQueuedLocks::Acquier::AcquireLock::LogVisitor
|
|
162
182
|
# @param lock_key [String]
|
163
183
|
# @param queue_ttl [Integer]
|
164
184
|
# @param acquier_id [String]
|
185
|
+
# @param host_id [String]
|
165
186
|
# @param acq_time [Numeric]
|
166
187
|
# @param access_strategy [Symbol]
|
167
188
|
# @return [void]
|
168
189
|
#
|
169
190
|
# @api private
|
170
191
|
# @since 1.7.0
|
192
|
+
# @version 1.9.0
|
171
193
|
def lock_obtained(
|
172
194
|
logger,
|
173
195
|
log_sampled,
|
174
196
|
lock_key,
|
175
197
|
queue_ttl,
|
176
198
|
acquier_id,
|
199
|
+
host_id,
|
177
200
|
acq_time,
|
178
201
|
access_strategy
|
179
202
|
)
|
@@ -184,6 +207,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::LogVisitor
|
|
184
207
|
"lock_key => '#{lock_key}' " \
|
185
208
|
"queue_ttl => #{queue_ttl} " \
|
186
209
|
"acq_id => '#{acquier_id}' " \
|
210
|
+
"hst_id => '#{host_id}' " \
|
187
211
|
"acs_strat => '#{access_strategy}' " \
|
188
212
|
"acq_time => #{acq_time} (ms)"
|
189
213
|
end rescue nil
|