redis_queued_locks 1.23.0 → 1.24.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/.claude/project-overview.md +70 -33
- data/.claude/rules/acquirer.md +6 -3
- data/.claude/rules/arguments.md +2 -2
- data/.claude/rules/git.md +1 -1
- data/.claude/rules/logic.md +5 -4
- data/.claude/rules/readme.md +40 -0
- data/.claude/rules/swarm.md +2 -2
- data/.claude/rules/tests.md +3 -2
- data/.claude/rules/type-checking.md +3 -2
- data/.claude/rules/visitors.md +3 -2
- data/.claude/skills/rql-code-review/SKILL.md +6 -3
- data/.claude/skills/rql-project-full-review/SKILL.md +171 -0
- data/.claude/skills/rql-project-full-review/templates/report.en.md +41 -0
- data/.claude/skills/rql-project-full-review/templates/report.ru.md +41 -0
- data/CHANGELOG.md +30 -9
- data/CLAUDE.md +7 -5
- data/README.md +390 -17
- data/lib/redis_queued_locks/acquirer/acquire_lock/dequeue_from_lock_queue.rb +60 -1
- data/lib/redis_queued_locks/acquirer/acquire_lock/try_to_lock/log_visitor.rb +38 -1
- data/lib/redis_queued_locks/acquirer/acquire_lock/try_to_lock.rb +31 -4
- data/lib/redis_queued_locks/acquirer/acquire_lock/with_acq_timeout.rb +6 -3
- data/lib/redis_queued_locks/acquirer/acquire_lock/yield_expire.rb +257 -32
- data/lib/redis_queued_locks/acquirer/acquire_lock.rb +103 -4
- data/lib/redis_queued_locks/acquirer/lock_series/try_to_lock_series.rb +27 -1
- data/lib/redis_queued_locks/acquirer/lock_series.rb +160 -15
- data/lib/redis_queued_locks/client.rb +96 -16
- data/lib/redis_queued_locks/config/dsl.rb +2 -0
- data/lib/redis_queued_locks/config.rb +35 -11
- data/lib/redis_queued_locks/errors.rb +19 -2
- data/lib/redis_queued_locks/lock_keeper/instr_visitor.rb +173 -0
- data/lib/redis_queued_locks/lock_keeper/lease.rb +434 -0
- data/lib/redis_queued_locks/lock_keeper/lock_lease.rb +106 -0
- data/lib/redis_queued_locks/lock_keeper/log_visitor.rb +187 -0
- data/lib/redis_queued_locks/lock_keeper.rb +1007 -0
- data/lib/redis_queued_locks/resource.rb +1 -1
- data/lib/redis_queued_locks/swarm/swarm_element/threaded.rb +2 -2
- data/lib/redis_queued_locks/utilities.rb +1 -15
- data/lib/redis_queued_locks/version.rb +2 -2
- data/lib/redis_queued_locks.rb +1 -0
- data/sig/redis_queued_locks/acquirer/acquire_lock/dequeue_from_lock_queue.rbs +14 -0
- data/sig/redis_queued_locks/acquirer/acquire_lock/try_to_lock/log_visitor.rbs +12 -0
- data/sig/redis_queued_locks/acquirer/acquire_lock/try_to_lock.rbs +2 -0
- data/sig/redis_queued_locks/acquirer/acquire_lock/yield_expire.rbs +30 -2
- data/sig/redis_queued_locks/acquirer/acquire_lock.rbs +6 -1
- data/sig/redis_queued_locks/acquirer/lock_series.rbs +12 -1
- data/sig/redis_queued_locks/client.rbs +14 -0
- data/sig/redis_queued_locks/config.rbs +15 -1
- data/sig/redis_queued_locks/errors.rbs +12 -0
- data/sig/redis_queued_locks/instrument/void_notifier.rbs +2 -2
- data/sig/redis_queued_locks/lock_keeper/instr_visitor.rbs +67 -0
- data/sig/redis_queued_locks/lock_keeper/lease.rbs +78 -0
- data/sig/redis_queued_locks/lock_keeper/lock_lease.rbs +19 -0
- data/sig/redis_queued_locks/lock_keeper/log_visitor.rbs +62 -0
- data/sig/redis_queued_locks/lock_keeper.rbs +108 -0
- data/sig/redis_queued_locks/utilities.rbs +0 -2
- data/sig/vendor/redis_client.rbs +1 -0
- metadata +15 -1
|
@@ -130,7 +130,7 @@ module RedisQueuedLocks::Resource
|
|
|
130
130
|
|
|
131
131
|
# rubocop:disable Metrics/ClassLength
|
|
132
132
|
class << self
|
|
133
|
-
# Returns
|
|
133
|
+
# Returns a unique identifier (16 hex characters, 8 random bytes). It is used for uniquely
|
|
134
134
|
# identify current process between different nodes/pods of your application
|
|
135
135
|
# during the lock obtaining and self-identifying in the lock queue.
|
|
136
136
|
#
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# @api private
|
|
4
4
|
# @since 1.9.0
|
|
5
|
-
# @version 1.
|
|
5
|
+
# @version 1.22.0
|
|
6
6
|
# rubocop:disable Metrics/ClassLength
|
|
7
7
|
class RedisQueuedLocks::Swarm::SwarmElement::Threaded
|
|
8
8
|
# @since 1.9.0
|
|
@@ -341,7 +341,7 @@ class RedisQueuedLocks::Swarm::SwarmElement::Threaded
|
|
|
341
341
|
#
|
|
342
342
|
# @api private
|
|
343
343
|
# @since 1.9.0
|
|
344
|
-
# @version 1.
|
|
344
|
+
# @version 1.22.0
|
|
345
345
|
def swarm_element__terminate
|
|
346
346
|
return if idle? || swarmed__dead?
|
|
347
347
|
sync.synchronize do
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# @api private
|
|
4
4
|
# @since 1.0.0
|
|
5
|
-
# @version 1.
|
|
5
|
+
# @version 1.24.0
|
|
6
6
|
module RedisQueuedLocks::Utilities
|
|
7
7
|
require_relative 'utilities/lock'
|
|
8
8
|
|
|
@@ -36,12 +36,6 @@ module RedisQueuedLocks::Utilities
|
|
|
36
36
|
# @since 1.9.0
|
|
37
37
|
RACTOR_STATUS_PATTERN = /\A.*?\s(?<status>\w+)>\z/i
|
|
38
38
|
|
|
39
|
-
# @return [Boolean]
|
|
40
|
-
#
|
|
41
|
-
# @api public
|
|
42
|
-
# @since 1.16.0
|
|
43
|
-
RUBY_OVER_4 = Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('4.0.0')
|
|
44
|
-
|
|
45
39
|
# @yield
|
|
46
40
|
# @yieldreturn [Any]
|
|
47
41
|
# @return [Any]
|
|
@@ -104,12 +98,4 @@ module RedisQueuedLocks::Utilities
|
|
|
104
98
|
return 'failed' if status == nil
|
|
105
99
|
status #: String
|
|
106
100
|
end
|
|
107
|
-
|
|
108
|
-
# @return [Boolean]
|
|
109
|
-
#
|
|
110
|
-
# @api public
|
|
111
|
-
# @since 1.16.0
|
|
112
|
-
def ruby_over_4?
|
|
113
|
-
RUBY_OVER_4
|
|
114
|
-
end
|
|
115
101
|
end
|
data/lib/redis_queued_locks.rb
CHANGED
|
@@ -18,6 +18,7 @@ module RedisQueuedLocks
|
|
|
18
18
|
require_relative 'redis_queued_locks/acquirer'
|
|
19
19
|
require_relative 'redis_queued_locks/instrument'
|
|
20
20
|
require_relative 'redis_queued_locks/swarm'
|
|
21
|
+
require_relative 'redis_queued_locks/lock_keeper'
|
|
21
22
|
require_relative 'redis_queued_locks/client'
|
|
22
23
|
require_relative 'redis_queued_locks/config'
|
|
23
24
|
|
|
@@ -19,6 +19,20 @@ module RedisQueuedLocks
|
|
|
19
19
|
bool log_sampled,
|
|
20
20
|
bool instr_sampled
|
|
21
21
|
) -> { ok: bool, result: Integer }
|
|
22
|
+
|
|
23
|
+
def release_unconfirmed_lock: (
|
|
24
|
+
RC::client redis,
|
|
25
|
+
RQL::loggerObj logger,
|
|
26
|
+
String lock_key,
|
|
27
|
+
RQL::readWriteMode rw_mode,
|
|
28
|
+
String lock_readers_key,
|
|
29
|
+
String? read_lock_key,
|
|
30
|
+
Integer queue_ttl,
|
|
31
|
+
String acquirer_id,
|
|
32
|
+
String host_id,
|
|
33
|
+
RQL::accessStrategy access_strategy,
|
|
34
|
+
bool log_sampled
|
|
35
|
+
) -> void
|
|
22
36
|
end
|
|
23
37
|
end
|
|
24
38
|
end
|
|
@@ -235,6 +235,18 @@ module RedisQueuedLocks
|
|
|
235
235
|
Integer? ahead_priority
|
|
236
236
|
) -> void
|
|
237
237
|
|
|
238
|
+
def self.exit__reentrant_lock_is_changed: (
|
|
239
|
+
RQL::loggerObj logger,
|
|
240
|
+
bool log_sampled,
|
|
241
|
+
bool log_lock_try,
|
|
242
|
+
String lock_key,
|
|
243
|
+
Integer queue_ttl,
|
|
244
|
+
String acquirer_id,
|
|
245
|
+
String host_id,
|
|
246
|
+
RQL::accessStrategy access_strategy,
|
|
247
|
+
RQL::readWriteMode rw_mode
|
|
248
|
+
) -> void
|
|
249
|
+
|
|
238
250
|
def self.exit__read_lock_still_obtained: (
|
|
239
251
|
RQL::loggerObj logger,
|
|
240
252
|
bool log_sampled,
|
|
@@ -17,6 +17,7 @@ module RedisQueuedLocks
|
|
|
17
17
|
QUEUE_LOCK_INDEX_REPLIES: Integer
|
|
18
18
|
READ_LOCK_EXTENSION_COMMANDS: Integer
|
|
19
19
|
MAX_DEAD_REQUEST_REMOVALS: Integer
|
|
20
|
+
MAX_REENTRANT_EXTENSION_RETRIES: Integer
|
|
20
21
|
|
|
21
22
|
# { ok: bool, result: Symbol }
|
|
22
23
|
# { ok: bool, result: Symbol }
|
|
@@ -57,6 +58,7 @@ module RedisQueuedLocks
|
|
|
57
58
|
RQL::accessStrategy access_strategy,
|
|
58
59
|
Hash[String|Symbol,untyped]? meta,
|
|
59
60
|
bool retry_attempt,
|
|
61
|
+
Hash[Symbol,untyped] acq_process,
|
|
60
62
|
bool log_sampled,
|
|
61
63
|
bool instr_sampled
|
|
62
64
|
) -> { ok: bool, result: Symbol|Hash[Symbol,untyped] }
|
|
@@ -6,6 +6,8 @@ module RedisQueuedLocks
|
|
|
6
6
|
module AcquireLock
|
|
7
7
|
module YieldExpire
|
|
8
8
|
DECREASE_LOCK_PTTL: String
|
|
9
|
+
RELEASE_OWN_LOCK: String
|
|
10
|
+
DECREASE_OWN_LOCK_PTTL: String
|
|
9
11
|
|
|
10
12
|
def yield_expire: (
|
|
11
13
|
RC::client redis,
|
|
@@ -14,6 +16,7 @@ module RedisQueuedLocks
|
|
|
14
16
|
String lock_readers_key,
|
|
15
17
|
String? read_lock_key,
|
|
16
18
|
RQL::readWriteMode rw_mode,
|
|
19
|
+
String lock_name,
|
|
17
20
|
String acquirer_id,
|
|
18
21
|
String host_id,
|
|
19
22
|
RQL::accessStrategy access_strategy,
|
|
@@ -21,23 +24,48 @@ module RedisQueuedLocks
|
|
|
21
24
|
Integer|Float ttl_shift,
|
|
22
25
|
Integer ttl,
|
|
23
26
|
Integer queue_ttl,
|
|
27
|
+
bool lock_index_enabled,
|
|
28
|
+
Integer lock_index_grace_period,
|
|
24
29
|
Hash[String|Symbol,untyped]? meta,
|
|
25
30
|
bool log_sampled,
|
|
26
31
|
bool instr_sampled,
|
|
27
32
|
bool should_expire,
|
|
28
|
-
bool should_decrease
|
|
33
|
+
bool should_decrease,
|
|
34
|
+
RQL::LockKeeper lock_keeper,
|
|
35
|
+
bool auto_extend,
|
|
36
|
+
Integer? auto_extend_ttl,
|
|
37
|
+
Integer? max_hold_time_during_auto_extend,
|
|
38
|
+
Integer try_start_time,
|
|
39
|
+
RQL::instrObj instrumenter,
|
|
40
|
+
untyped? instrument
|
|
29
41
|
) ?{ (?) -> untyped } -> untyped?
|
|
30
42
|
|
|
31
43
|
private
|
|
32
44
|
|
|
45
|
+
def timed_block_budget: (Integer? time_limit, Integer|Float ttl_shift) -> Float?
|
|
46
|
+
|
|
33
47
|
def yield_with_timeout: (
|
|
34
|
-
Float timeout,
|
|
48
|
+
Float? timeout,
|
|
35
49
|
String lock_key,
|
|
36
50
|
Integer lock_ttl,
|
|
51
|
+
Integer? max_hold_time_during_auto_extend,
|
|
52
|
+
RQL::LockKeeper lock_keeper,
|
|
53
|
+
RQL::LockKeeper::Lease? lock_lease,
|
|
54
|
+
RQL::LockKeeper::LockLease? lease_handle,
|
|
37
55
|
String acquirer_id,
|
|
38
56
|
String host_id,
|
|
39
57
|
Hash[String|Symbol,untyped]? meta,
|
|
40
58
|
) { (?) -> untyped } -> untyped
|
|
59
|
+
|
|
60
|
+
def raise_timed_block_error: (
|
|
61
|
+
String lock_key,
|
|
62
|
+
Integer lock_ttl,
|
|
63
|
+
Integer? max_hold_time_during_auto_extend,
|
|
64
|
+
RQL::LockKeeper::Lease? lock_lease,
|
|
65
|
+
String acquirer_id,
|
|
66
|
+
String host_id,
|
|
67
|
+
Hash[String|Symbol,untyped]? meta
|
|
68
|
+
) -> void
|
|
41
69
|
end
|
|
42
70
|
end
|
|
43
71
|
end
|
|
@@ -25,6 +25,10 @@ module RedisQueuedLocks
|
|
|
25
25
|
lock_index_grace_period: Integer,
|
|
26
26
|
timeout: Integer?,
|
|
27
27
|
timed: bool,
|
|
28
|
+
auto_extend: bool,
|
|
29
|
+
auto_extend_ttl: Integer?,
|
|
30
|
+
max_hold_time_during_auto_extend: Integer?,
|
|
31
|
+
lock_keeper: RQL::LockKeeper,
|
|
28
32
|
retry_count: Integer?,
|
|
29
33
|
retry_delay: Integer,
|
|
30
34
|
retry_jitter: Integer,
|
|
@@ -38,7 +42,8 @@ module RedisQueuedLocks
|
|
|
38
42
|
log_lock_try: bool,
|
|
39
43
|
instrument: untyped?,
|
|
40
44
|
conflict_strategy: RQL::conflictStrategy,
|
|
41
|
-
|
|
45
|
+
# NOTE: (rbs test) validated at runtime (Step 0.1 (RW)): any Symbol is accepted here
|
|
46
|
+
rw_mode: Symbol,
|
|
42
47
|
access_strategy: RQL::accessStrategy,
|
|
43
48
|
priority: RQL::lockPriority,
|
|
44
49
|
lock_priorities: Hash[Symbol, Integer],
|
|
@@ -9,6 +9,8 @@ module RedisQueuedLocks
|
|
|
9
9
|
extend RQL::Acquirer::AcquireLock::YieldExpire
|
|
10
10
|
extend RQL::Acquirer::LockSeries::TryToLockSeries
|
|
11
11
|
|
|
12
|
+
MAX_REENTRANT_EXTENSION_RETRIES: Integer
|
|
13
|
+
|
|
12
14
|
type lockSeriesResult = ({ ok: bool, result: untyped }|untyped)
|
|
13
15
|
def self.lock_series: (
|
|
14
16
|
RC::client redis,
|
|
@@ -24,6 +26,10 @@ module RedisQueuedLocks
|
|
|
24
26
|
lock_index_grace_period: Integer,
|
|
25
27
|
timeout: Integer?,
|
|
26
28
|
timed: bool,
|
|
29
|
+
auto_extend: bool,
|
|
30
|
+
auto_extend_ttl: Integer?,
|
|
31
|
+
max_hold_time_during_auto_extend: Integer?,
|
|
32
|
+
lock_keeper: RQL::LockKeeper,
|
|
27
33
|
retry_count: Integer?,
|
|
28
34
|
retry_delay: Integer,
|
|
29
35
|
retry_jitter: Integer,
|
|
@@ -37,7 +43,8 @@ module RedisQueuedLocks
|
|
|
37
43
|
logger: RQL::loggerObj,
|
|
38
44
|
log_lock_try: bool,
|
|
39
45
|
conflict_strategy: RQL::conflictStrategy,
|
|
40
|
-
|
|
46
|
+
# NOTE: (rbs test) validated at runtime (Step 0.1 (RW)): any Symbol is accepted here
|
|
47
|
+
rw_mode: Symbol,
|
|
41
48
|
access_strategy: RQL::accessStrategy,
|
|
42
49
|
priority: RQL::lockPriority,
|
|
43
50
|
lock_priorities: Hash[Symbol, Integer],
|
|
@@ -58,6 +65,10 @@ module RedisQueuedLocks
|
|
|
58
65
|
bool timed,
|
|
59
66
|
Integer|Float ttl_shift,
|
|
60
67
|
Integer ttl,
|
|
68
|
+
Integer? max_hold_time_during_auto_extend,
|
|
69
|
+
RQL::LockKeeper lock_keeper,
|
|
70
|
+
RQL::LockKeeper::Lease? lock_lease,
|
|
71
|
+
RQL::LockKeeper::LockLease? lease_handle,
|
|
61
72
|
Hash[String|Symbol,untyped]? meta
|
|
62
73
|
) ?{ (?) -> untyped } -> untyped?
|
|
63
74
|
|
|
@@ -7,11 +7,13 @@ module RedisQueuedLocks
|
|
|
7
7
|
@redis_client: RC::client
|
|
8
8
|
@uniq_identity: String
|
|
9
9
|
@swarm: RQL::Swarm
|
|
10
|
+
@lock_keeper: RQL::LockKeeper
|
|
10
11
|
|
|
11
12
|
attr_reader config: RQL::Config
|
|
12
13
|
attr_reader redis_client: RC::client
|
|
13
14
|
attr_accessor uniq_identity: String
|
|
14
15
|
attr_reader swarm: RQL::Swarm
|
|
16
|
+
attr_reader lock_keeper: RQL::LockKeeper
|
|
15
17
|
|
|
16
18
|
def initialize: (RC::client redis_client) ?{ (RQL::Config) -> void } -> void
|
|
17
19
|
def configure: () ?{ (RQL::Config) -> void } -> void
|
|
@@ -39,6 +41,9 @@ module RedisQueuedLocks
|
|
|
39
41
|
?lock_index_grace_period: Integer,
|
|
40
42
|
?timeout: Integer?,
|
|
41
43
|
?timed: bool,
|
|
44
|
+
?auto_extend: bool,
|
|
45
|
+
?auto_extend_ttl: Integer?,
|
|
46
|
+
?max_hold_time_during_auto_extend: Integer?,
|
|
42
47
|
?retry_count: Integer?,
|
|
43
48
|
?retry_delay: Integer,
|
|
44
49
|
?retry_jitter: Integer,
|
|
@@ -72,6 +77,9 @@ module RedisQueuedLocks
|
|
|
72
77
|
?lock_index_grace_period: Integer,
|
|
73
78
|
?timeout: Integer?,
|
|
74
79
|
?timed: bool,
|
|
80
|
+
?auto_extend: bool,
|
|
81
|
+
?auto_extend_ttl: Integer?,
|
|
82
|
+
?max_hold_time_during_auto_extend: Integer?,
|
|
75
83
|
?retry_count: Integer?,
|
|
76
84
|
?retry_delay: Integer,
|
|
77
85
|
?retry_jitter: Integer,
|
|
@@ -105,6 +113,9 @@ module RedisQueuedLocks
|
|
|
105
113
|
?lock_index_grace_period: Integer,
|
|
106
114
|
?timeout: Integer?,
|
|
107
115
|
?timed: bool,
|
|
116
|
+
?auto_extend: bool,
|
|
117
|
+
?auto_extend_ttl: Integer?,
|
|
118
|
+
?max_hold_time_during_auto_extend: Integer?,
|
|
108
119
|
?retry_count: Integer?,
|
|
109
120
|
?retry_delay: Integer,
|
|
110
121
|
?retry_jitter: Integer,
|
|
@@ -139,6 +150,9 @@ module RedisQueuedLocks
|
|
|
139
150
|
?lock_index_grace_period: Integer,
|
|
140
151
|
?timeout: Integer?,
|
|
141
152
|
?timed: bool,
|
|
153
|
+
?auto_extend: bool,
|
|
154
|
+
?auto_extend_ttl: Integer?,
|
|
155
|
+
?max_hold_time_during_auto_extend: Integer?,
|
|
142
156
|
?retry_count: Integer?,
|
|
143
157
|
?retry_delay: Integer,
|
|
144
158
|
?retry_jitter: Integer,
|
|
@@ -8,7 +8,11 @@ module RedisQueuedLocks
|
|
|
8
8
|
|
|
9
9
|
@config_state: configState
|
|
10
10
|
@configuring: bool
|
|
11
|
-
|
|
11
|
+
# NOTE: (rbs test) `%a{rbs:test:skip}`: the hottest call of the runtime checks: it runs twice
|
|
12
|
+
# per `config['...']` (`Client#lock` reads ~25 defaults) and rbs/test walks every key of the
|
|
13
|
+
# hash on each call; the values stay checked per key by the `Config#[]` overloads (Steep still
|
|
14
|
+
# checks the reader).
|
|
15
|
+
%a{rbs:test:skip} attr_reader config_state: configState
|
|
12
16
|
|
|
13
17
|
def initialize: () ?{ (RedisQueuedLocks::Config) -> void } -> void
|
|
14
18
|
def configure: () ?{ (RedisQueuedLocks::Config) -> void } -> void
|
|
@@ -34,6 +38,16 @@ module RedisQueuedLocks
|
|
|
34
38
|
| ("lock_index_enabled") -> bool
|
|
35
39
|
| ("lock_index_grace_period") -> Integer
|
|
36
40
|
| ("is_timed_by_default") -> bool
|
|
41
|
+
| ("is_auto_extended_by_default") -> bool
|
|
42
|
+
| ("default_auto_extend_ttl") -> Integer?
|
|
43
|
+
| ("default_max_hold_time_during_auto_extend") -> Integer?
|
|
44
|
+
| ("lock_keeper.idle_timeout") -> Integer
|
|
45
|
+
| ("lock_keeper.min_idle_wake_up_interval") -> Integer
|
|
46
|
+
| ("lock_keeper.extension_retry_ratio") -> Integer
|
|
47
|
+
| ("lock_keeper.extension_batching_ratio") -> Integer
|
|
48
|
+
| ("lock_keeper.schedule_slot") -> Integer
|
|
49
|
+
| ("lock_keeper.fiber_interruption_timeout") -> Integer
|
|
50
|
+
| ("lock_keeper.fiber_interruption_wait_step") -> (Float | Integer)
|
|
37
51
|
| ("default_conflict_strategy") -> RedisQueuedLocks::conflictStrategy
|
|
38
52
|
| ("default_access_strategy") -> RedisQueuedLocks::accessStrategy
|
|
39
53
|
| ("lock_priorities") -> Hash[Symbol, Integer]
|
|
@@ -26,6 +26,18 @@ module RedisQueuedLocks
|
|
|
26
26
|
class TimedLockTimeoutError < Error
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
+
class LockTtlTimeBudgetIsSpentError < TimedLockTimeoutError
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
class TimedBlockExceedsLockTtlError < TimedLockTimeoutError
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class TimedBlockExceedsMaxHoldTimeError < TimedLockTimeoutError
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
class TimedBlockLostLockError < TimedLockTimeoutError
|
|
39
|
+
end
|
|
40
|
+
|
|
29
41
|
class ConflictLockObtainError < Error
|
|
30
42
|
end
|
|
31
43
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
module RedisQueuedLocks
|
|
2
2
|
module Instrument
|
|
3
3
|
module VoidNotifier
|
|
4
|
-
# NOTE: (rbs test) not hooked: `Instrument.valid_interface?` introspects `#parameters` of
|
|
5
|
-
# and a hooked method has the `(*rest, &block)` parameters;
|
|
4
|
+
# NOTE: (rbs test) not hooked: `Instrument.valid_interface?` introspects `#parameters` of
|
|
5
|
+
# `notify`, and a hooked method has the `(*rest, &block)` parameters;
|
|
6
6
|
%a{rbs:test:skip} def self.notify: (String event, ?Hash[untyped,untyped] payload) -> void
|
|
7
7
|
end
|
|
8
8
|
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
use RedisQueuedLocks as RQL
|
|
2
|
+
|
|
3
|
+
module RedisQueuedLocks
|
|
4
|
+
class LockKeeper
|
|
5
|
+
module InstrVisitor
|
|
6
|
+
def self.lock_auto_extended: (
|
|
7
|
+
RQL::instrObj instrumenter,
|
|
8
|
+
bool instr_sampled,
|
|
9
|
+
String lock_key,
|
|
10
|
+
RQL::readWriteMode rw_mode,
|
|
11
|
+
Integer ext_ttl,
|
|
12
|
+
Integer rem_ttl,
|
|
13
|
+
String acq_id,
|
|
14
|
+
String hst_id,
|
|
15
|
+
untyped? instrument
|
|
16
|
+
) -> void
|
|
17
|
+
|
|
18
|
+
def self.lock_auto_extension_failed: (
|
|
19
|
+
RQL::instrObj instrumenter,
|
|
20
|
+
bool instr_sampled,
|
|
21
|
+
String lock_key,
|
|
22
|
+
RQL::readWriteMode rw_mode,
|
|
23
|
+
Integer ext_ttl,
|
|
24
|
+
String acq_id,
|
|
25
|
+
String hst_id,
|
|
26
|
+
String error,
|
|
27
|
+
untyped? instrument
|
|
28
|
+
) -> void
|
|
29
|
+
|
|
30
|
+
def self.auto_extended_lock_lost: (
|
|
31
|
+
RQL::instrObj instrumenter,
|
|
32
|
+
bool instr_sampled,
|
|
33
|
+
String lock_key,
|
|
34
|
+
RQL::readWriteMode rw_mode,
|
|
35
|
+
String acq_id,
|
|
36
|
+
String hst_id,
|
|
37
|
+
Integer hold_time,
|
|
38
|
+
untyped? instrument
|
|
39
|
+
) -> void
|
|
40
|
+
|
|
41
|
+
def self.lock_hold_limit_reached: (
|
|
42
|
+
RQL::instrObj instrumenter,
|
|
43
|
+
bool instr_sampled,
|
|
44
|
+
String lock_key,
|
|
45
|
+
RQL::readWriteMode rw_mode,
|
|
46
|
+
Integer? max_hold_time_during_auto_extend,
|
|
47
|
+
String acq_id,
|
|
48
|
+
String hst_id,
|
|
49
|
+
untyped? instrument
|
|
50
|
+
) -> void
|
|
51
|
+
|
|
52
|
+
def self.lock_hold_limit_extended: (
|
|
53
|
+
RQL::instrObj instrumenter,
|
|
54
|
+
bool instr_sampled,
|
|
55
|
+
String lock_key,
|
|
56
|
+
RQL::readWriteMode rw_mode,
|
|
57
|
+
Integer hold_time,
|
|
58
|
+
Integer? rem_hold_time,
|
|
59
|
+
Integer ext_ttl,
|
|
60
|
+
Integer rem_ttl,
|
|
61
|
+
String acq_id,
|
|
62
|
+
String hst_id,
|
|
63
|
+
untyped? instrument
|
|
64
|
+
) -> void
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
use RedisQueuedLocks as RQL
|
|
2
|
+
|
|
3
|
+
module RedisQueuedLocks
|
|
4
|
+
class LockKeeper
|
|
5
|
+
class Lease
|
|
6
|
+
interface _FiberScheduler
|
|
7
|
+
def fiber_interrupt: (Fiber fiber, ::Exception exception) -> untyped
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
attr_reader lock_keys: Array[String]
|
|
11
|
+
attr_reader lock_readers_keys: Array[String]
|
|
12
|
+
attr_reader read_lock_keys: Array[String?]
|
|
13
|
+
attr_reader rw_modes: Array[RQL::readWriteMode]
|
|
14
|
+
attr_reader lock_names: Array[String]
|
|
15
|
+
attr_reader acquirer_id: String
|
|
16
|
+
attr_reader host_id: String
|
|
17
|
+
attr_reader extension_ttl: Integer
|
|
18
|
+
attr_reader extension_interval: Integer
|
|
19
|
+
attr_reader max_hold_time_during_auto_extend: Integer?
|
|
20
|
+
attr_reader started_at: Integer
|
|
21
|
+
attr_reader next_extension_at: Integer
|
|
22
|
+
attr_reader lock_index_enabled: bool
|
|
23
|
+
attr_reader lock_index_grace_period: Integer
|
|
24
|
+
attr_accessor timed_fiber: Fiber?
|
|
25
|
+
attr_accessor interrupted_thread: Thread?
|
|
26
|
+
attr_accessor fiber_scheduler: _FiberScheduler?
|
|
27
|
+
attr_reader logger: RQL::loggerObj
|
|
28
|
+
attr_reader log_sampled: bool
|
|
29
|
+
attr_reader instrumenter: RQL::instrObj
|
|
30
|
+
attr_reader instr_sampled: bool
|
|
31
|
+
attr_reader instrument: untyped?
|
|
32
|
+
|
|
33
|
+
@hold_deadline: Integer?
|
|
34
|
+
@lost_locks: Array[bool]
|
|
35
|
+
@lost: bool
|
|
36
|
+
@hold_stopped: bool
|
|
37
|
+
@hold_moved: bool
|
|
38
|
+
@pending_interruption: RQL::TimedLockIntermediateTimeoutError?
|
|
39
|
+
|
|
40
|
+
def initialize: (
|
|
41
|
+
Array[String] lock_keys,
|
|
42
|
+
Array[String] lock_readers_keys,
|
|
43
|
+
Array[String?] read_lock_keys,
|
|
44
|
+
Array[RQL::readWriteMode] rw_modes,
|
|
45
|
+
Array[String] lock_names,
|
|
46
|
+
String acquirer_id,
|
|
47
|
+
String host_id,
|
|
48
|
+
Integer started_at,
|
|
49
|
+
Integer ttl,
|
|
50
|
+
Integer extension_ttl,
|
|
51
|
+
Integer? max_hold_time_during_auto_extend,
|
|
52
|
+
bool lock_index_enabled,
|
|
53
|
+
Integer lock_index_grace_period,
|
|
54
|
+
RQL::loggerObj logger,
|
|
55
|
+
bool log_sampled,
|
|
56
|
+
RQL::instrObj instrumenter,
|
|
57
|
+
bool instr_sampled,
|
|
58
|
+
untyped? instrument
|
|
59
|
+
) -> void
|
|
60
|
+
|
|
61
|
+
def lost?: () -> bool
|
|
62
|
+
def lock_lost?: (Integer lock_index) -> bool
|
|
63
|
+
def lose_lock: (Integer lock_index) -> void
|
|
64
|
+
def all_locks_lost?: () -> bool
|
|
65
|
+
def interruptible?: () -> bool
|
|
66
|
+
def interrupt: (String message) -> void
|
|
67
|
+
def take_pending_interruption: (::Exception? raised_error) -> RQL::TimedLockIntermediateTimeoutError?
|
|
68
|
+
def hold_limit_reached?: (Integer time) -> bool
|
|
69
|
+
def hold_until: (Integer hold_deadline) -> void
|
|
70
|
+
def hold_moved?: () -> bool
|
|
71
|
+
def hold_time_left: (Integer time) -> Integer?
|
|
72
|
+
def stop_hold: () -> void
|
|
73
|
+
def hold_stopped?: () -> bool
|
|
74
|
+
def extension_ttl_at: (Integer time) -> Integer
|
|
75
|
+
def schedule_extension: (Integer time) -> void
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
use RedisQueuedLocks as RQL
|
|
2
|
+
use RedisClient as RC
|
|
3
|
+
|
|
4
|
+
module RedisQueuedLocks
|
|
5
|
+
class LockKeeper
|
|
6
|
+
class LockLease
|
|
7
|
+
type holdForResult = { ok: bool, result: :extended | :lock_lost | :hold_limit_reached | :released }
|
|
8
|
+
|
|
9
|
+
@lock_keeper: RQL::LockKeeper
|
|
10
|
+
@lease: RQL::LockKeeper::Lease
|
|
11
|
+
@redis: RC::client
|
|
12
|
+
|
|
13
|
+
def initialize: (RQL::LockKeeper lock_keeper, RQL::LockKeeper::Lease lease, RC::client redis) -> void
|
|
14
|
+
def hold_for: (Integer hold_time) -> holdForResult
|
|
15
|
+
def lost?: () -> bool
|
|
16
|
+
def hold_time_left: () -> Integer?
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
use RedisQueuedLocks as RQL
|
|
2
|
+
|
|
3
|
+
module RedisQueuedLocks
|
|
4
|
+
class LockKeeper
|
|
5
|
+
module LogVisitor
|
|
6
|
+
def self.lock_auto_extended: (
|
|
7
|
+
RQL::loggerObj logger,
|
|
8
|
+
bool log_sampled,
|
|
9
|
+
String lock_key,
|
|
10
|
+
RQL::readWriteMode rw_mode,
|
|
11
|
+
Integer ext_ttl,
|
|
12
|
+
Integer rem_ttl,
|
|
13
|
+
String acquirer_id,
|
|
14
|
+
String host_id
|
|
15
|
+
) -> void
|
|
16
|
+
|
|
17
|
+
def self.lock_auto_extension_failed: (
|
|
18
|
+
RQL::loggerObj logger,
|
|
19
|
+
bool log_sampled,
|
|
20
|
+
String lock_key,
|
|
21
|
+
RQL::readWriteMode rw_mode,
|
|
22
|
+
Integer ext_ttl,
|
|
23
|
+
String acquirer_id,
|
|
24
|
+
String host_id,
|
|
25
|
+
String error
|
|
26
|
+
) -> void
|
|
27
|
+
|
|
28
|
+
def self.auto_extended_lock_lost: (
|
|
29
|
+
RQL::loggerObj logger,
|
|
30
|
+
bool log_sampled,
|
|
31
|
+
String lock_key,
|
|
32
|
+
RQL::readWriteMode rw_mode,
|
|
33
|
+
String acquirer_id,
|
|
34
|
+
String host_id,
|
|
35
|
+
Integer hold_time
|
|
36
|
+
) -> void
|
|
37
|
+
|
|
38
|
+
def self.lock_hold_limit_reached: (
|
|
39
|
+
RQL::loggerObj logger,
|
|
40
|
+
bool log_sampled,
|
|
41
|
+
String lock_key,
|
|
42
|
+
RQL::readWriteMode rw_mode,
|
|
43
|
+
Integer? max_hold_time_during_auto_extend,
|
|
44
|
+
String acquirer_id,
|
|
45
|
+
String host_id
|
|
46
|
+
) -> void
|
|
47
|
+
|
|
48
|
+
def self.lock_hold_limit_extended: (
|
|
49
|
+
RQL::loggerObj logger,
|
|
50
|
+
bool log_sampled,
|
|
51
|
+
String lock_key,
|
|
52
|
+
RQL::readWriteMode rw_mode,
|
|
53
|
+
Integer hold_time,
|
|
54
|
+
Integer? rem_hold_time,
|
|
55
|
+
Integer ext_ttl,
|
|
56
|
+
Integer rem_ttl,
|
|
57
|
+
String acquirer_id,
|
|
58
|
+
String host_id
|
|
59
|
+
) -> void
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|