redis_queued_locks 1.23.1 → 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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.claude/project-overview.md +70 -33
  3. data/.claude/rules/acquirer.md +6 -4
  4. data/.claude/rules/arguments.md +2 -2
  5. data/.claude/rules/git.md +1 -1
  6. data/.claude/rules/logic.md +5 -4
  7. data/.claude/rules/readme.md +40 -0
  8. data/.claude/rules/swarm.md +2 -2
  9. data/.claude/rules/tests.md +3 -2
  10. data/.claude/rules/type-checking.md +3 -2
  11. data/.claude/rules/visitors.md +3 -2
  12. data/.claude/skills/rql-code-review/SKILL.md +6 -3
  13. data/.claude/skills/rql-project-full-review/SKILL.md +171 -0
  14. data/.claude/skills/rql-project-full-review/templates/report.en.md +41 -0
  15. data/.claude/skills/rql-project-full-review/templates/report.ru.md +41 -0
  16. data/CHANGELOG.md +25 -10
  17. data/CLAUDE.md +7 -5
  18. data/README.md +381 -13
  19. data/lib/redis_queued_locks/acquirer/acquire_lock/dequeue_from_lock_queue.rb +60 -1
  20. data/lib/redis_queued_locks/acquirer/acquire_lock/try_to_lock/log_visitor.rb +38 -1
  21. data/lib/redis_queued_locks/acquirer/acquire_lock/try_to_lock.rb +31 -4
  22. data/lib/redis_queued_locks/acquirer/acquire_lock/with_acq_timeout.rb +6 -3
  23. data/lib/redis_queued_locks/acquirer/acquire_lock/yield_expire.rb +243 -35
  24. data/lib/redis_queued_locks/acquirer/acquire_lock.rb +93 -3
  25. data/lib/redis_queued_locks/acquirer/lock_series/try_to_lock_series.rb +27 -1
  26. data/lib/redis_queued_locks/acquirer/lock_series.rb +150 -14
  27. data/lib/redis_queued_locks/client.rb +96 -16
  28. data/lib/redis_queued_locks/config/dsl.rb +2 -0
  29. data/lib/redis_queued_locks/config.rb +35 -11
  30. data/lib/redis_queued_locks/errors.rb +11 -2
  31. data/lib/redis_queued_locks/lock_keeper/instr_visitor.rb +173 -0
  32. data/lib/redis_queued_locks/lock_keeper/lease.rb +434 -0
  33. data/lib/redis_queued_locks/lock_keeper/lock_lease.rb +106 -0
  34. data/lib/redis_queued_locks/lock_keeper/log_visitor.rb +187 -0
  35. data/lib/redis_queued_locks/lock_keeper.rb +1007 -0
  36. data/lib/redis_queued_locks/resource.rb +1 -1
  37. data/lib/redis_queued_locks/swarm/swarm_element/threaded.rb +2 -2
  38. data/lib/redis_queued_locks/utilities.rb +1 -15
  39. data/lib/redis_queued_locks/version.rb +2 -2
  40. data/lib/redis_queued_locks.rb +1 -0
  41. data/sig/redis_queued_locks/acquirer/acquire_lock/dequeue_from_lock_queue.rbs +14 -0
  42. data/sig/redis_queued_locks/acquirer/acquire_lock/try_to_lock/log_visitor.rbs +12 -0
  43. data/sig/redis_queued_locks/acquirer/acquire_lock/try_to_lock.rbs +2 -0
  44. data/sig/redis_queued_locks/acquirer/acquire_lock/yield_expire.rbs +30 -2
  45. data/sig/redis_queued_locks/acquirer/acquire_lock.rbs +6 -1
  46. data/sig/redis_queued_locks/acquirer/lock_series.rbs +12 -1
  47. data/sig/redis_queued_locks/client.rbs +14 -0
  48. data/sig/redis_queued_locks/config.rbs +15 -1
  49. data/sig/redis_queued_locks/errors.rbs +6 -0
  50. data/sig/redis_queued_locks/instrument/void_notifier.rbs +2 -2
  51. data/sig/redis_queued_locks/lock_keeper/instr_visitor.rbs +67 -0
  52. data/sig/redis_queued_locks/lock_keeper/lease.rbs +78 -0
  53. data/sig/redis_queued_locks/lock_keeper/lock_lease.rbs +19 -0
  54. data/sig/redis_queued_locks/lock_keeper/log_visitor.rbs +62 -0
  55. data/sig/redis_queued_locks/lock_keeper.rbs +108 -0
  56. data/sig/redis_queued_locks/utilities.rbs +0 -2
  57. data/sig/vendor/redis_client.rbs +1 -0
  58. metadata +15 -1
data/README.md CHANGED
@@ -8,7 +8,7 @@ Each lock request is put into the request queue (each lock is hosted by its own
8
8
 
9
9
  In addition to the classic `queued` (FIFO) strategy RQL supports `random` (RANDOM) lock obtaining strategy when any acquirer from the lock queue can obtain the lock regardless the position in the queue.
10
10
 
11
- Supports [lock request prioritization](#lock-request-prioritization), `Read`/`Write` locks and `Reentrant` locks.
11
+ Supports `Read`/`Write` locks, `Reentrant` locks, **[lock auto extending](#lock-auto-extending)** and [lock request prioritization](#lock-request-prioritization).
12
12
 
13
13
  Provides flexible invocation flow, parametrized limits (lock request ttl, lock ttl, queue ttl, lock attempts limit, fast failing, etc), **zombie locks elimination**, **[lock indexing](#lock-index)**, logging and instrumentation (and much more).
14
14
 
@@ -73,6 +73,8 @@ Provides flexible invocation flow, parametrized limits (lock request ttl, lock t
73
73
  - [random](#lock-access-strategies)
74
74
  - [Lock Request Prioritization](#lock-request-prioritization)
75
75
  - [Read/Write Locks](#readwrite-locks)
76
+ - [Lock Auto Extending](#lock-auto-extending)
77
+ - [Manual Lock Lease extending from the running block of code](#manual-lock-lease-extending-from-the-running-block-of-code)
76
78
  - [Deadlocks and Reentrant locks](#deadlocks-and-reentrant-locks)
77
79
  - [Logging](#logging)
78
80
  - [Logging Configuration](#logging-configuration)
@@ -91,6 +93,11 @@ Provides flexible invocation flow, parametrized limits (lock request ttl, lock t
91
93
  - ["redis_queued_locks.lock_series_obtained"](#redis_queued_lockslock_series_obtained)
92
94
  - ["redis_queued_locks.lock_series_hold_and_release"](#redis_queued_lockslock_series_hold_and_release)
93
95
  - ["redis_queued_locks.lock_series_obtaining_failed"](#redis_queued_lockslock_series_obtaining_failed)
96
+ - ["redis_queued_locks.lock_auto_extended"](#redis_queued_lockslock_auto_extended)
97
+ - ["redis_queued_locks.lock_auto_extension_failed"](#redis_queued_lockslock_auto_extension_failed)
98
+ - ["redis_queued_locks.auto_extended_lock_lost"](#redis_queued_locksauto_extended_lock_lost)
99
+ - ["redis_queued_locks.lock_hold_limit_reached"](#redis_queued_lockslock_hold_limit_reached)
100
+ - ["redis_queued_locks.lock_hold_limit_extended"](#redis_queued_lockslock_hold_limit_extended)
94
101
  - ["redis_queued_locks.explicit_lock_release"](#redis_queued_locksexplicit_lock_release)
95
102
  - ["redis_queued_locks.explicit_read_lock_release"](#redis_queued_locksexplicit_read_lock_release)
96
103
  - ["redis_queued_locks.explicit_all_locks_release"](#redis_queued_locksexplicit_all_locks_release)
@@ -221,6 +228,81 @@ client = RedisQueuedLocks::Client.new(redis_client) do |config|
221
228
  # - should be all blocks of code are timed by default;
222
229
  config['is_timed_by_default'] = false
223
230
 
231
+ # (boolean) (default: false)
232
+ # - should the locks of all blocks of code be kept alive while the block is running by default
233
+ # (the `auto_extend:` option, see "Lock Auto Extending");
234
+ config['is_auto_extended_by_default'] = false
235
+
236
+ # (milliseconds) (default: nil)
237
+ # - how long an auto extended lock lives after each extension (the `auto_extend_ttl:` option,
238
+ # see "Lock Auto Extending");
239
+ # - `nil` means the ttl of the lock (`ttl:`);
240
+ # - should be `nil` or a positive Integer;
241
+ config['default_auto_extend_ttl'] = nil
242
+
243
+ # (milliseconds) (default: 3_600_000, 1 hour)
244
+ # - the protection against blocks of code that never finish: a block that hangs forever (an
245
+ # endless loop, a call without a timeout) or a block abandoned midway (a fiber that is never
246
+ # resumed: its `ensure` never runs and the lock is not released); such a block looks like a
247
+ # running one, and without a limit its lock is extended till the end of the process;
248
+ # - the limit of the auto extension of the lock (the `max_hold_time_during_auto_extend:` option, see
249
+ # "Lock Auto Extending");
250
+ # - `nil` means no limit;
251
+ # - !IMPORTANT: configure it yourself, deliberately, for your logic: `nil` (no limit) or a period
252
+ # that is longer than your longest block of code (a longer block of code loses its lock at the
253
+ # limit, a stuck block of code with `nil` holds its lock till the end of the process); the
254
+ # default is only a fallback;
255
+ # - should be `nil` or a positive Integer;
256
+ config['default_max_hold_time_during_auto_extend'] = 3_600_000
257
+
258
+ # (milliseconds) (default: 60_000)
259
+ # - the lock keeper thread (see "Lock Auto Extending") stops after this time without new blocks
260
+ # of code with `auto_extend: true` (and starts again on demand);
261
+ # - should be a positive Integer;
262
+ config['lock_keeper.idle_timeout'] = 60_000
263
+
264
+ # (milliseconds) (default: 100)
265
+ # - an idle lock keeper follows the rhythm of the extensions, but it does not wake up more often
266
+ # than this: a block of code with a shorter extension interval wakes it up by itself;
267
+ # - should be a positive Integer;
268
+ config['lock_keeper.min_idle_wake_up_interval'] = 100
269
+
270
+ # (integer) (default: 3)
271
+ # - a failed extension (Redis is not available, for example) is retried sooner:
272
+ # in `extension interval / extension_retry_ratio` (the extension interval is `auto_extend_ttl / 3`);
273
+ # - should be a positive Integer;
274
+ config['lock_keeper.extension_retry_ratio'] = 3
275
+
276
+ # (integer) (default: 10)
277
+ # - the locks that are due in `extension interval / extension_batching_ratio` are extended with
278
+ # the due ones: one pipeline instead of a wake-up per block of code;
279
+ # - should be a positive Integer;
280
+ config['lock_keeper.extension_batching_ratio'] = 10
281
+
282
+ # (milliseconds) (default: 10)
283
+ # - the schedule of the lock keeper is a set of slots of this length by the time of the next
284
+ # extension: a wake-up looks at the due slots only, not at all running blocks of code (the
285
+ # work of the keeper does not grow with the number of the running blocks of code);
286
+ # - should be a positive Integer;
287
+ config['lock_keeper.schedule_slot'] = 10
288
+
289
+ # (milliseconds) (default: 1_000)
290
+ # - a `timed` block of code of a fiber scheduler task (see "Lock Auto Extending") is interrupted
291
+ # through its fiber scheduler, and the interruption comes at the next suspension point of the
292
+ # fiber; when the block ends before it comes, the fiber waits for it this time at most (a
293
+ # scheduler that does not raise it in this time is not waited for anymore);
294
+ # - should be a positive Integer;
295
+ config['lock_keeper.fiber_interruption_timeout'] = 1_000
296
+
297
+ # (seconds) (default: 0.001)
298
+ # - the step of this wait (`Kernel#sleep`): each step suspends the fiber, so its scheduler gets
299
+ # the control and raises the interruption;
300
+ # - should be a positive Float or Integer;
301
+ config['lock_keeper.fiber_interruption_wait_step'] = 0.001
302
+
303
+ # NOTE: the `lock_keeper.*` settings are read when the lock keeper thread starts: a changed
304
+ # setting takes effect at the next start of the thread (after its idle timeout);
305
+
224
306
  # (boolean) (default: false)
225
307
  # - When the lock acquirement try reached the acquirement time limit (:timeout option) the
226
308
  # `RedisQueuedLocks::LockAcquirementTimeoutError` is raised (when `raise_errors` option
@@ -390,6 +472,11 @@ client = RedisQueuedLocks::Client.new(redis_client) do |config|
390
472
  # - "[redis_queued_locks.dequeue_from_lock_series_queues]" (logs "lock_keys", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode", "priority");
391
473
  # - "[redis_queued_locks.expire_lock_series]" (logs "lock_keys", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode", "priority");
392
474
  # - "[redis_queued_locks.decrease_lock_series]" (logs "lock_keys", "decreased_ttl", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode", "priority");
475
+ # - "[redis_queued_locks.lock_auto_extended]" (logs "lock_key", "rw_mode", "ext_ttl", "rem_ttl", "acq_id", "hst_id");
476
+ # - "[redis_queued_locks.lock_auto_extension_failed]" (logs "lock_key", "rw_mode", "ext_ttl", "acq_id", "hst_id", "error");
477
+ # - "[redis_queued_locks.auto_extended_lock_lost]" (logs "lock_key", "rw_mode", "acq_id", "hst_id", "hold_time");
478
+ # - "[redis_queued_locks.lock_hold_limit_reached]" (logs "lock_key", "rw_mode", "max_hold_time_during_auto_extend", "acq_id", "hst_id");
479
+ # - "[redis_queued_locks.lock_hold_limit_extended]" (logs "lock_key", "rw_mode", "hold_time", "rem_hold_time", "ext_ttl", "rem_ttl", "acq_id", "hst_id");
393
480
  # - "[redis_queued_locks.explicit_lock_release]" (logs "lock_key", "lock_key_queue", "rel_time", "at");
394
481
  # - "[redis_queued_locks.explicit_read_lock_release]" (logs "lock_key", "acq_id", "lock_res", "rel_time", "at");
395
482
  # - "[redis_queued_locks.explicit_all_locks_release]" (logs "at", "rel_time", "rel_key_cnt");
@@ -424,6 +511,7 @@ client = RedisQueuedLocks::Client.new(redis_client) do |config|
424
511
  # - "[redis_queued_locks.try_lock.exit__write_request_ahead]" (logs "lock_key", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode", "ahead_acq_id", "ahead_priority");
425
512
  # - "[redis_queued_locks.try_lock.exit__read_request_ahead]" (logs "lock_key", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode", "ahead_acq_id", "ahead_priority");
426
513
  # - "[redis_queued_locks.try_lock.exit__read_lock_still_obtained]" (logs "lock_key", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode", "first_acq_id_in_queue", "first_priority_in_queue");
514
+ # - "[redis_queued_locks.try_lock.exit__reentrant_lock_is_changed]" (logs "lock_key", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode");
427
515
  # - "[redis_queued_locks.try_lock.obtain__free_to_acquire]" (logs "lock_key", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode");
428
516
  # - "rw_mode" is the requested lock mode ('write'/'read');
429
517
  config['log_lock_try'] = false
@@ -519,8 +607,9 @@ types and ranges as their `config` keys: `Integer` values only (`timeout: 0.5` i
519
607
  - if you want to timeout (fail with timeout) the block execution with lock's TTL use `timed: true` option;
520
608
  - (limitation) the write lock is released after the block without an owner check: if the block (without `timed: true`)
521
609
  runs longer than the lock's ttl, the expired lock can be already obtained by another acquirer and the release
522
- deletes that lock (the same for the ttl decrease of `:extendable_work_through` reentrant locks); use `timed: true`
523
- or extend the lock (`#extend_lock_ttl`) for long blocks (read locks are released per acquirer and are not affected);
610
+ deletes that lock (the same for the ttl decrease of `:extendable_work_through` reentrant locks); use
611
+ `auto_extend: true` (see [Lock Auto Extending](#lock-auto-extending)), `timed: true` or extend the lock
612
+ (`#extend_lock_ttl`) for long blocks (read locks are released per acquirer and are not affected);
524
613
  - the block's result will be returned;
525
614
  - If block is not passed:
526
615
  - the obtained lock will be released after lock's ttl;
@@ -534,6 +623,9 @@ def lock(
534
623
  lock_index_grace_period: config['lock_index_grace_period'],
535
624
  timeout: config['try_to_lock_timeout'],
536
625
  timed: config['is_timed_by_default'],
626
+ auto_extend: config['is_auto_extended_by_default'],
627
+ auto_extend_ttl: config['default_auto_extend_ttl'],
628
+ max_hold_time_during_auto_extend: config['default_max_hold_time_during_auto_extend'],
537
629
  retry_count: config['retry_count'],
538
630
  retry_delay: config['retry_delay'],
539
631
  retry_jitter: config['retry_jitter'],
@@ -594,8 +686,34 @@ def lock(
594
686
  - both failures have the common superclass `RedisQueuedLocks::TimedLockTimeoutError`: `RedisQueuedLocks::TimedBlockExceedsLockTtlError` (the block exceeded the time) and `RedisQueuedLocks::LockTtlTimeBudgetIsSpentError` (the block was not invoked);
595
687
  - (limitation) `timed` can only interrupt the block: a long `ensure` of the block, `rescue Exception` in the block and the code that
596
688
  can not be interrupted (a C extension holding the GVL) can outlive the lock;
689
+ - with `auto_extend: true` the block is limited by `max_hold_time_during_auto_extend` instead of the lock's TTL and it is interrupted when the lock is lost
690
+ (see [Lock Auto Extending](#lock-auto-extending)): `RedisQueuedLocks::TimedBlockExceedsMaxHoldTimeError` and `RedisQueuedLocks::TimedBlockLostLockError`
691
+ (both are `RedisQueuedLocks::TimedLockTimeoutError` subclasses);
597
692
  - pre-configured in `config['is_timed_by_default']`;
598
693
  - `false` by default;
694
+ - `auto_extend` - (optional) `[Boolean]`
695
+ - Keep the lock alive while the passed block of code is running: the block can run longer than the lock's TTL, and the crash of the process
696
+ releases the lock by the TTL. See [Lock Auto Extending](#lock-auto-extending);
697
+ - has no effect without a block of code;
698
+ - pre-configured in `config['is_auto_extended_by_default']`;
699
+ - `false` by default;
700
+ - `auto_extend_ttl` - (optional) `[Integer,NilClass]`
701
+ - How long the lock lives after each auto extension (in milliseconds): it is the time from the moment of the extension, not a sum;
702
+ - `nil` means the lock's TTL (`ttl`);
703
+ - pre-configured in `config['default_auto_extend_ttl']`;
704
+ - `nil` by default;
705
+ - `max_hold_time_during_auto_extend` - (optional) `[Integer,NilClass]`
706
+ - The protection of an auto extended lock against blocks of code that never finish: a block that hangs forever (an endless loop, a call without a timeout)
707
+ or a block abandoned midway (a fiber that is never resumed: its `ensure` never runs and the lock is not released). Such a block looks like a running one,
708
+ and without a limit its lock is extended till the end of the process;
709
+ - the limit of the auto extension (in milliseconds, from the start of the successful acquirement attempt): the lock of such a block of code expires by this time;
710
+ - **!IMPORTANT**: configure it yourself, deliberately, for your logic (per call or in `config['default_max_hold_time_during_auto_extend']`): `nil` (no limit) or a period that is longer
711
+ than your longest block of code. A block of code that runs longer loses its lock at the limit (a `timed` block is interrupted) unless it moves the limit
712
+ by `lease.hold_for`, and a stuck block of code with `nil` holds its lock till the end of the process. The default (1 hour) is only a fallback;
713
+ - should not be less than `ttl` for an auto extended lock;
714
+ - `nil` means no limit;
715
+ - pre-configured in `config['default_max_hold_time_during_auto_extend']`;
716
+ - `3_600_000` (1 hour) by default;
599
717
  - `retry_count` - (optional) `[Integer,NilClass]`
600
718
  - How many times we should try to acquire a lock. Nil means "infinite retries".
601
719
  - pre-configured in `config['retry_count']`;
@@ -992,6 +1110,9 @@ def lock!(
992
1110
  lock_index_grace_period: config['lock_index_grace_period'],
993
1111
  timeout: config['try_to_lock_timeout'],
994
1112
  timed: config['is_timed_by_default'],
1113
+ auto_extend: config['is_auto_extended_by_default'],
1114
+ auto_extend_ttl: config['default_auto_extend_ttl'],
1115
+ max_hold_time_during_auto_extend: config['default_max_hold_time_during_auto_extend'],
995
1116
  retry_count: config['retry_count'],
996
1117
  retry_delay: config['retry_delay'],
997
1118
  retry_jitter: config['retry_jitter'],
@@ -2929,6 +3050,154 @@ rql.lock('report') { rebuild_report } # rw_mode: :write by default
2929
3050
 
2930
3051
  ---
2931
3052
 
3053
+ ## Lock Auto Extending
3054
+
3055
+ <sup>\[[back to top](#table-of-contents)\]</sup>
3056
+
3057
+ > Keep the lock alive while your block of code is running.
3058
+
3059
+ The lock TTL does two different jobs: it limits how long a crashed process blocks other acquirers (a short TTL is better)
3060
+ and it has to cover the whole block of code (a long TTL is better). With `auto_extend: true` the TTL does only the first job: it is a lease
3061
+ that is extended while the block of code is running. When the process dies the extensions stop and the lock expires by itself.
3062
+
3063
+ ```ruby
3064
+ # the block can run longer than 10 seconds; a crashed process releases the lock in 10 seconds at most
3065
+ rql.lock('report', ttl: 10_000, auto_extend: true) { long_running_logic }
3066
+
3067
+ # auto extension with the time of each extension
3068
+ rql.lock(
3069
+ 'report',
3070
+ ttl: 2_000, # the first lease
3071
+ auto_extend: true,
3072
+ auto_extend_ttl: 30_000, # each extension: 30 seconds from the moment of the extension
3073
+ max_hold_time_during_auto_extend: 7_200_000 # the lock of a stuck block of code expires in 2 hours
3074
+ ) { long_running_logic }
3075
+
3076
+ # both modes, lock series, bang methods
3077
+ rql.lock('report', rw_mode: :read, auto_extend: true) { long_running_logic }
3078
+ rql.lock_series('report', 'stats', auto_extend: true) { long_running_logic }
3079
+
3080
+ # manual extension inside the block of code: the block that makes progress moves its hold limit
3081
+ # (see "Manual Lock Lease extending from the running block of code" below)
3082
+ rql.lock('report', auto_extend: true, max_hold_time_during_auto_extend: 600_000) do |lease|
3083
+ batches.each do |batch|
3084
+ process(batch)
3085
+ lease.hold_for(120_000) # keep the lock at least two more minutes from now
3086
+ end
3087
+ end
3088
+ ```
3089
+
3090
+ - `auto_extend` - keep the lock alive (`config['is_auto_extended_by_default']`, `false` by default). It has no effect without a block of code;
3091
+ - `auto_extend_ttl` - how long the lock lives after each extension (`config['default_auto_extend_ttl']`, `nil` by default: the lock's `ttl`):
3092
+ - it is the time from the moment of the extension, **not a sum**: a lock of a crashed process lives this time at most, whatever the number of extensions was;
3093
+ - extensions are made each `auto_extend_ttl / 3`;
3094
+ - it is the only knob of the trade-off: a process can stall for 2/3 of this value (see the limits below) and a crash blocks other acquirers for this value;
3095
+ - the extension never shortens the lock: with a longer `ttl` the first extension comes when it is needed;
3096
+ - `max_hold_time_during_auto_extend` - the protection against blocks of code that never finish: a block that hangs forever (an endless loop, a call without a timeout) or a block
3097
+ abandoned midway (a fiber that is never resumed: its `ensure` never runs and the lock is not released). Such a block looks like a running one, and without
3098
+ a limit it holds the lock till the end of the process. It is the limit of the extension (`config['default_max_hold_time_during_auto_extend']`, 1 hour by default, `nil` means
3099
+ no limit), counted from the start of the successful acquirement attempt: the lock is extended up to this moment exactly and expires by itself. It should not
3100
+ be less than `ttl`. A block of code that makes progress can move the limit (see [the lease of the block of code](#manual-lock-lease-extending-from-the-running-block-of-code) below);
3101
+
3102
+ > [!IMPORTANT]
3103
+ > Configure `max_hold_time_during_auto_extend` yourself, deliberately, for your logic (per call or in `config['default_max_hold_time_during_auto_extend']`): `nil` (no limit) or a period that is longer
3104
+ > than your longest block of code. A block of code that runs longer loses its lock at the limit (a `timed` block is interrupted) unless it moves the limit
3105
+ > by `lease.hold_for`, and a stuck block of code with `nil` holds its lock till the end of the process. The default (1 hour) is only a fallback, not a value for your logic.
3106
+
3107
+ **What happens**:
3108
+
3109
+ | Case | `timed: false` (default) | `timed: true` |
3110
+ |---|---|---|
3111
+ | the block of code ends | the lock is released | the lock is released |
3112
+ | the process crashes | the lock expires in `auto_extend_ttl` at most | the same |
3113
+ | `max_hold_time_during_auto_extend` is reached (or the limit moved by `lease.hold_for`) | the lock expires, the block of code continues to work, `lock_hold_limit_reached` is reported | `RedisQueuedLocks::TimedBlockExceedsMaxHoldTimeError` |
3114
+ | the lock is lost (`#unlock`, the swarm, an expiration while the process was stalled, ...) | the block of code continues to work, `auto_extended_lock_lost` is reported | `RedisQueuedLocks::TimedBlockLostLockError` (the block is not invoked when the lock is lost before it) |
3115
+
3116
+ - `timed: true` limits the block of code by `max_hold_time_during_auto_extend` instead of the lock's TTL; with `max_hold_time_during_auto_extend: nil` the block is limited by the lost lock only;
3117
+ - a lost lock is never revived, and the release after the block of code does not touch the lock of the next owner
3118
+ (the owner is checked; it is not so without `auto_extend`, see [#lock](#lock---obtain-a-lock));
3119
+ - a failed extension (Redis is not available) is reported (`lock_auto_extension_failed`) and is tried again sooner (each `auto_extend_ttl / 9` by default,
3120
+ `config['lock_keeper.extension_retry_ratio']`);
3121
+ - the lock keeper thread is tuned by `config['lock_keeper.*']` (the idle timeout, the wake-ups, the retries, the batching of the extensions, the schedule slots,
3122
+ the wait for a fiber interruption; see [Configuration](#configuration)): the defaults fit most applications;
3123
+ - `timed: true` in a non-blocking fiber (a fiber scheduler task, `async` for example): `Thread#raise` reaches the current fiber of the thread only, so the keeper
3124
+ interrupts such a block through its fiber scheduler (`Fiber::Scheduler#fiber_interrupt`, a Ruby 4.0 hook; `async` >= 2.25 implements it), the same way as
3125
+ a block of a thread: at the hold limit (moved by `lease.hold_for` too) and when the lock is lost. The scheduler raises the error at the next suspension point
3126
+ of the fiber (IO, `sleep`, ...): a CPU-bound block without them is interrupted when it yields, like by a `Timeout`. A scheduler without this hook
3127
+ (or a non-blocking fiber without a scheduler): the hold limit is a `Timeout` that `lease.hold_for` can not move, and a lost lock interrupts the block only
3128
+ when the block finds it by itself (`lease.hold_for`), otherwise it is reported only;
3129
+ - reentrant locks: the lock of a block with `auto_extend` is extended while this block is running, nested blocks do not need the option; a nested block
3130
+ with `auto_extend` keeps the lock of the outer logic alive while the nested block is running; an extension that changes the lock during a reentrant lock attempt
3131
+ repeats this attempt at once (no delay, no spent `retry_count`, no `fail_fast` failure, the `try_lock.exit__reentrant_lock_is_changed` log with `log_lock_try`);
3132
+
3133
+ #### Manual Lock Lease extending from the running block of code
3134
+
3135
+ <sup>\[[back to top](#lock-auto-extending)\]</sup>
3136
+
3137
+ A block of code with a parameter gets its lease (`RedisQueuedLocks::LockKeeper::LockLease`). A block that makes progress moves the hold limit itself, and a stuck
3138
+ block stops moving it, so its lock expires at the last limit (a dead man's switch instead of one fixed `max_hold_time_during_auto_extend`):
3139
+
3140
+ ```ruby
3141
+ rql.lock('report', ttl: 10_000, auto_extend: true, max_hold_time_during_auto_extend: 600_000) do |lease|
3142
+ batches.each do |batch|
3143
+ process(batch)
3144
+ lease.hold_for(120_000) # => { ok: true, result: :extended }: two more minutes from now
3145
+ end
3146
+ save_report unless lease.lost?
3147
+ end
3148
+ ```
3149
+
3150
+ - `lease.hold_for(milliseconds)` - keep the locks at least this time **from now**: it is not a sum (calls in a loop do not accumulate it) and the limit
3151
+ never moves back; it can move the limit beyond `max_hold_time_during_auto_extend`. The locks are extended at once (one round trip with the connection of your `redis_client`),
3152
+ each later extension is still `auto_extend_ttl` at most (a crash releases the lock in `auto_extend_ttl`, whatever the limit is). Results:
3153
+ - `{ ok: true, result: :extended }` - the limit is moved, all locks are owned and extended;
3154
+ - `{ ok: false, result: :lock_lost }` - a lock is lost (`auto_extended_lock_lost` is reported, the next calls do not move the limit); a `timed` block of code
3155
+ is interrupted right there, in any fiber (`RedisQueuedLocks::TimedBlockLostLockError`);
3156
+ - `{ ok: false, result: :hold_limit_reached }` - too late: the limit is reached and the locks are not extended anymore. Call it before the limit:
3157
+ the last extensions end the lock exactly at the limit;
3158
+ - `{ ok: false, result: :released }` - the block of code is completed;
3159
+ - `RedisQueuedLocks::ArgumentError` for a value that is not a positive Integer;
3160
+ - `lease.lost?` - a lock of the block is lost: a local check without Redis (a loss is found by an extension or by `hold_for`), so `false` does not prove
3161
+ the ownership right now;
3162
+ - `lease.hold_time_left` - milliseconds till the hold limit (`0` when it is reached, `nil`: no limit);
3163
+ - `timed: true`: the block of code is interrupted at the moved limit (the keeper thread interrupts it at the hold limit, it is not a `Timeout`; a non-blocking
3164
+ fiber whose scheduler has no `fiber_interrupt` keeps the `Timeout` of `max_hold_time_during_auto_extend`);
3165
+ - one lease per block of code: a lock series has one lease for all its locks, a nested block with `auto_extend` has its own lease; a block without
3166
+ parameters gets no lease (nothing is allocated for it);
3167
+ - call `hold_for` per a unit of progress (a batch), not per item: each call is a round trip. From another thread use it only with a connection pool
3168
+ (the connection of your client is used, like by any method of the client);
3169
+ - each moved lock is reported by `lock_hold_limit_extended`;
3170
+
3171
+ **How it works**:
3172
+
3173
+ - one background thread per `RedisQueuedLocks::Client` extends the locks of all running blocks of the client (all locks that are due in one pipeline). The thread is started on demand
3174
+ and it stops after a minute without blocks. Blocks without `auto_extend` pay nothing, a block that ends before the first extension sends no extensions to Redis;
3175
+ - the thread looks only at the locks that are due (a schedule by the time of the next extension): its work does not grow with the number of running blocks
3176
+ (tens of thousands of blocks in fibers, for example);
3177
+ - the thread has its own Redis connection, built from the config of your `redis_client`: a plain `RedisClient` is one connection that can not be shared between threads;
3178
+ - `fork`: the thread does not survive and a child process does not extend the locks of the parent process;
3179
+
3180
+ **Limits**. The background thread is a Ruby thread of your process, so it has to wait for the Global VM Lock and for the garbage collector like your code. A lock is kept
3181
+ while the delay of the thread is less than 2/3 of `auto_extend_ttl`. The delay is about **110 ms per each CPU-bound Ruby thread** of the process
3182
+ (the time slice of a Ruby thread is 100 ms) plus **the longest call that holds the GVL** (a C extension, for example `Marshal.dump` of a huge object) or the longest GC pause. So, the
3183
+ rule is: `auto_extend_ttl >= 1.5 * (0.11s * cpu_bound_threads + the longest GVL-holding call)`.
3184
+
3185
+ | `auto_extend_ttl` | CPU-bound threads, the lock is kept | CPU-bound threads, the lock is lost |
3186
+ |---|---|---|
3187
+ | 1 second | 4 | 8 |
3188
+ | 2 seconds | 8 | 16 |
3189
+ | 5 seconds | 16 | 32 |
3190
+
3191
+ - threads that wait for I/O do not count;
3192
+ - the `RUBY_THREAD_TIMESLICE` environment variable (milliseconds) decreases the delay proportionally: with `RUBY_THREAD_TIMESLICE=10` a lock with `auto_extend_ttl` of 1 second is kept next to 32 CPU-bound threads;
3193
+ - use `lock_auto_extended` event to see how much time is left at the moment of an extension (`rem_ttl`);
3194
+ - like any lease, it can not protect you from a process that is paused between the check of the lock and the write to your storage;
3195
+
3196
+ **Without the auto extension**: a long `ttl` (it is the hold limit) and the [swarm](#swarm-mode-and-zombie-locks) (it removes the locks of dead processes in about `zombie_ttl` + `zombie_flush_period`).
3197
+ There are no extensions at all, but the swarm has to run in your processes.
3198
+
3199
+ ---
3200
+
2932
3201
  ## Deadlocks and Reentrant locks
2933
3202
 
2934
3203
  <sup>\[[back to top](#table-of-contents)\]</sup>
@@ -2995,6 +3264,7 @@ rql.lock('report') { rebuild_report } # rw_mode: :write by default
2995
3264
  "[redis_queued_locks.try_lock.exit__write_request_ahead]" # (logs "lock_key", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode", "ahead_acq_id", "ahead_priority");
2996
3265
  "[redis_queued_locks.try_lock.exit__read_request_ahead]" # (logs "lock_key", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode", "ahead_acq_id", "ahead_priority");
2997
3266
  "[redis_queued_locks.try_lock.exit__read_lock_still_obtained]" # (logs "lock_key", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode", "first_acq_id_in_queue", "first_priority_in_queue");
3267
+ "[redis_queued_locks.try_lock.exit__reentrant_lock_is_changed]" # (logs "lock_key", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode");
2998
3268
  "[redis_queued_locks.try_lock.obtain__free_to_acquire]" # (logs "lock_key", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode");
2999
3269
  ```
3000
3270
 
@@ -3015,6 +3285,18 @@ rql.lock('report') { rebuild_report } # rw_mode: :write by default
3015
3285
  "[redis_queued_locks.decrease_lock_series]" # (logs "lock_keys", "decreased_ttl", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode", "priority");
3016
3286
  ```
3017
3287
 
3288
+ - lock auto extending logs (see [Lock Auto Extending](#lock-auto-extending); one log per lock; `rw_mode` is the mode of the held lock;
3289
+ raised by the lock keeper thread, except `lock_hold_limit_extended`: it is raised from the thread that called `lease.hold_for`, as well as
3290
+ `auto_extended_lock_lost` of a lock that `lease.hold_for` finds lost):
3291
+
3292
+ ```ruby
3293
+ "[redis_queued_locks.lock_auto_extended]" # (logs "lock_key", "rw_mode", "ext_ttl", "rem_ttl", "acq_id", "hst_id");
3294
+ "[redis_queued_locks.lock_auto_extension_failed]" # (logs "lock_key", "rw_mode", "ext_ttl", "acq_id", "hst_id", "error");
3295
+ "[redis_queued_locks.auto_extended_lock_lost]" # (logs "lock_key", "rw_mode", "acq_id", "hst_id", "hold_time");
3296
+ "[redis_queued_locks.lock_hold_limit_reached]" # (logs "lock_key", "rw_mode", "max_hold_time_during_auto_extend", "acq_id", "hst_id");
3297
+ "[redis_queued_locks.lock_hold_limit_extended]" # (logs "lock_key", "rw_mode", "hold_time", "rem_hold_time", "ext_ttl", "rem_ttl", "acq_id", "hst_id");
3298
+ ```
3299
+
3018
3300
  - operation logs (one log line per operation that changes Redis keys, with the time of the whole operation; the same data as
3019
3301
  the instrumentation event of the operation without `instrument`):
3020
3302
 
@@ -3074,6 +3356,11 @@ rql.lock('report') { rebuild_report } # rw_mode: :write by default
3074
3356
  # - "[redis_queued_locks.dequeue_from_lock_series_queues]" (logs "lock_keys", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode", "priority");
3075
3357
  # - "[redis_queued_locks.expire_lock_series]" (logs "lock_keys", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode", "priority");
3076
3358
  # - "[redis_queued_locks.decrease_lock_series]" (logs "lock_keys", "decreased_ttl", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode", "priority");
3359
+ # - "[redis_queued_locks.lock_auto_extended]" (logs "lock_key", "rw_mode", "ext_ttl", "rem_ttl", "acq_id", "hst_id");
3360
+ # - "[redis_queued_locks.lock_auto_extension_failed]" (logs "lock_key", "rw_mode", "ext_ttl", "acq_id", "hst_id", "error");
3361
+ # - "[redis_queued_locks.auto_extended_lock_lost]" (logs "lock_key", "rw_mode", "acq_id", "hst_id", "hold_time");
3362
+ # - "[redis_queued_locks.lock_hold_limit_reached]" (logs "lock_key", "rw_mode", "max_hold_time_during_auto_extend", "acq_id", "hst_id");
3363
+ # - "[redis_queued_locks.lock_hold_limit_extended]" (logs "lock_key", "rw_mode", "hold_time", "rem_hold_time", "ext_ttl", "rem_ttl", "acq_id", "hst_id");
3077
3364
  # - "[redis_queued_locks.explicit_lock_release]" (logs "lock_key", "lock_key_queue", "rel_time", "at");
3078
3365
  # - "[redis_queued_locks.explicit_read_lock_release]" (logs "lock_key", "acq_id", "lock_res", "rel_time", "at");
3079
3366
  # - "[redis_queued_locks.explicit_all_locks_release]" (logs "at", "rel_time", "rel_key_cnt");
@@ -3108,6 +3395,7 @@ config['logger'] = RedisQueuedLocks::Logging::VoidLogger
3108
3395
  # - "[redis_queued_locks.try_lock.exit__write_request_ahead]" (logs "lock_key", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode", "ahead_acq_id", "ahead_priority");
3109
3396
  # - "[redis_queued_locks.try_lock.exit__read_request_ahead]" (logs "lock_key", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode", "ahead_acq_id", "ahead_priority");
3110
3397
  # - "[redis_queued_locks.try_lock.exit__read_lock_still_obtained]" (logs "lock_key", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode", "first_acq_id_in_queue", "first_priority_in_queue");
3398
+ # - "[redis_queued_locks.try_lock.exit__reentrant_lock_is_changed]" (logs "lock_key", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode");
3111
3399
  # - "[redis_queued_locks.try_lock.obtain__free_to_acquire]" (logs "lock_key", "queue_ttl", "acq_id", "hst_id", "acs_strat", "rw_mode");
3112
3400
  # - "rw_mode" is the requested lock mode ('write'/'read');
3113
3401
  config['log_lock_try'] = false
@@ -3221,6 +3509,11 @@ List of instrumentation events
3221
3509
  - ["redis_queued_locks.lock_series_obtained"](#redis_queued_lockslock_series_obtained)
3222
3510
  - ["redis_queued_locks.lock_series_hold_and_release"](#redis_queued_lockslock_series_hold_and_release)
3223
3511
  - ["redis_queued_locks.lock_series_obtaining_failed"](#redis_queued_lockslock_series_obtaining_failed)
3512
+ - ["redis_queued_locks.lock_auto_extended"](#redis_queued_lockslock_auto_extended)
3513
+ - ["redis_queued_locks.lock_auto_extension_failed"](#redis_queued_lockslock_auto_extension_failed)
3514
+ - ["redis_queued_locks.auto_extended_lock_lost"](#redis_queued_locksauto_extended_lock_lost)
3515
+ - ["redis_queued_locks.lock_hold_limit_reached"](#redis_queued_lockslock_hold_limit_reached)
3516
+ - ["redis_queued_locks.lock_hold_limit_extended"](#redis_queued_lockslock_hold_limit_extended)
3224
3517
  - ["redis_queued_locks.explicit_lock_release"](#redis_queued_locksexplicit_lock_release)
3225
3518
  - ["redis_queued_locks.explicit_read_lock_release"](#redis_queued_locksexplicit_read_lock_release)
3226
3519
  - ["redis_queued_locks.explicit_all_locks_release"](#redis_queued_locksexplicit_all_locks_release)
@@ -3229,9 +3522,12 @@ List of instrumentation events
3229
3522
  - ["redis_queued_locks.clear_dead_requests"](#redis_queued_locksclear_dead_requests)
3230
3523
  - ["redis_queued_locks.reindex_locks"](#redis_queued_locksreindex_locks)
3231
3524
 
3232
- What is instrumented (each event has a log line with the same name, see [Logging](#logging)):
3525
+ What is instrumented (each event has a log line with the same name, see [Logging](#logging), except the release events: `lock_hold_and_release`,
3526
+ `reentrant_lock_hold_completes` and `lock_series_hold_and_release` are logged as `expire_lock`/`decrease_lock`(`_series`), a `:work_through` reentrant
3527
+ lock releases nothing and has no release log):
3233
3528
  - the lock acquirement (`#lock`/`#lock!`, `#lock_series`/`#lock_series!`): each meaningful outcome (the lock or the whole
3234
3529
  series is obtained, not obtained, held and released);
3530
+ - the lock auto extending: each extension of each lock and its failures (from the background thread, see [Lock Auto Extending](#lock-auto-extending));
3235
3531
  - each operation that changes Redis keys (`#unlock`, `#unlock_read`, `#clear_locks`, `#clear_locks_of`/`#clear_current_locks`,
3236
3532
  `#extend_lock_ttl`, `#clear_dead_requests`, `#reindex_locks`): one event with the time of the whole operation;
3237
3533
  - lock information queries (`#lock_info`, `#locks`, `#queues`, `#keys`, ...) are not instrumented;
@@ -3443,6 +3739,77 @@ Detalized event semantics and payload structure:
3443
3739
  no attempt was completed or some lock state was changed during the attempt);
3444
3740
  - `:instrument` - `nil`/`Any` - custom data passed to the `#lock_series`/`#lock_series!` method as `:instrument` attribute;
3445
3741
 
3742
+ ##### `"redis_queued_locks.lock_auto_extended"`
3743
+ - <sup>\[[back to the list](#instrumentation-events)\]</sup>
3744
+ - an event signalizes about the extended lock (see [Lock Auto Extending](#lock-auto-extending));
3745
+ - raised by the lock keeper thread, one event per lock per extension;
3746
+ - payload:
3747
+ - `:lock_key` - `string` - lock key (`rql:lock:<lock_name>`);
3748
+ - `:rw_mode` - `symbol` - the mode of the held lock (`:write` or `:read`);
3749
+ - `:ext_ttl` - `integer`/`milliseconds` - how long the lock should live after the extension;
3750
+ - `:rem_ttl` - `integer`/`milliseconds` - how long the lock really lives after the extension (the extension never shortens the lock);
3751
+ - `:acq_id` - `string` - lock acquirer identifier;
3752
+ - `:hst_id` - `string` - lock's host identifier;
3753
+ - `:at` - `float`/`epoch` - the time when the event was reported;
3754
+ - `:instrument` - `nil`/`Any` - custom data passed to the `#lock`/`#lock_series` method as `:instrument` attribute;
3755
+
3756
+ ##### `"redis_queued_locks.lock_auto_extension_failed"`
3757
+ - <sup>\[[back to the list](#instrumentation-events)\]</sup>
3758
+ - an event signalizes about the failed extension (Redis is not available, for example): it is tried again sooner;
3759
+ - raised by the lock keeper thread, one event per lock per failure;
3760
+ - payload:
3761
+ - `:lock_key` - `string` - lock key (`rql:lock:<lock_name>`);
3762
+ - `:rw_mode` - `symbol` - the mode of the held lock (`:write` or `:read`);
3763
+ - `:ext_ttl` - `integer`/`milliseconds` - how long the lock should live after the extension;
3764
+ - `:acq_id` - `string` - lock acquirer identifier;
3765
+ - `:hst_id` - `string` - lock's host identifier;
3766
+ - `:error` - `string` - the class name of the error;
3767
+ - `:at` - `float`/`epoch` - the time when the event was reported;
3768
+ - `:instrument` - `nil`/`Any` - custom data passed to the `#lock`/`#lock_series` method as `:instrument` attribute;
3769
+
3770
+ ##### `"redis_queued_locks.auto_extended_lock_lost"`
3771
+ - <sup>\[[back to the list](#instrumentation-events)\]</sup>
3772
+ - an event signalizes that the lock of the running block of code is lost: it is expired or released, or it is obtained by another acquirer;
3773
+ - raised by the lock keeper thread (or from the thread that called `#hold_for`, when `#hold_for` finds the lost lock), one event per lock;
3774
+ - payload:
3775
+ - `:lock_key` - `string` - lock key (`rql:lock:<lock_name>`);
3776
+ - `:rw_mode` - `symbol` - the mode of the held lock (`:write` or `:read`);
3777
+ - `:acq_id` - `string` - lock acquirer identifier;
3778
+ - `:hst_id` - `string` - lock's host identifier;
3779
+ - `:hold_time` - `integer`/`milliseconds` - time from the start of the successful acquirement attempt to the moment when the loss is found;
3780
+ - `:at` - `float`/`epoch` - the time when the event was reported;
3781
+ - `:instrument` - `nil`/`Any` - custom data passed to the `#lock`/`#lock_series` method as `:instrument` attribute;
3782
+
3783
+ ##### `"redis_queued_locks.lock_hold_limit_reached"`
3784
+ - <sup>\[[back to the list](#instrumentation-events)\]</sup>
3785
+ - an event signalizes that the block of code reached its hold limit (`max_hold_time_during_auto_extend` or the limit moved by `lease.hold_for`): the lock is not extended anymore;
3786
+ - raised by the lock keeper thread, one event per lock;
3787
+ - payload:
3788
+ - `:lock_key` - `string` - lock key (`rql:lock:<lock_name>`);
3789
+ - `:rw_mode` - `symbol` - the mode of the held lock (`:write` or `:read`);
3790
+ - `:max_hold_time_during_auto_extend` - `integer`/`milliseconds` - the `max_hold_time_during_auto_extend` option of the block of code (the initial limit:
3791
+ it stays the same when the limit is moved by `lease.hold_for`);
3792
+ - `:acq_id` - `string` - lock acquirer identifier;
3793
+ - `:hst_id` - `string` - lock's host identifier;
3794
+ - `:at` - `float`/`epoch` - the time when the event was reported;
3795
+ - `:instrument` - `nil`/`Any` - custom data passed to the `#lock`/`#lock_series` method as `:instrument` attribute;
3796
+
3797
+ ##### `"redis_queued_locks.lock_hold_limit_extended"`
3798
+ - <sup>\[[back to the list](#instrumentation-events)\]</sup>
3799
+ - an event signalizes that the block of code moved its hold limit and the lock is extended at once (`RedisQueuedLocks::LockKeeper::LockLease#hold_for`);
3800
+ - raised from the thread that called `#hold_for`, one event per lock (a lost lock is reported by `auto_extended_lock_lost` instead);
3801
+ - payload:
3802
+ - `:lock_key` - `string` - lock key (`rql:lock:<lock_name>`);
3803
+ - `:rw_mode` - `symbol` - the mode of the held lock (`:write` or `:read`);
3804
+ - `:hold_time` - `integer`/`milliseconds` - the requested time (from the moment of the call);
3805
+ - `:rem_hold_time` - `integer`/`milliseconds`/`nil` - the time left till the hold limit after the call (`nil`: no limit);
3806
+ - `:ext_ttl` - `integer`/`milliseconds` - how long the lock should live after the extension (`auto_extend_ttl`, the hold limit at most);
3807
+ - `:rem_ttl` - `integer`/`milliseconds` - how long the lock really lives after the extension (the extension never shortens the lock);
3808
+ - `:acq_id` - `string` - lock acquirer identifier;
3809
+ - `:hst_id` - `string` - lock's host identifier;
3810
+ - `:at` - `float`/`epoch` - the time when the event was reported;
3811
+ - `:instrument` - `nil`/`Any` - custom data passed to the `#lock`/`#lock_series` method as `:instrument` attribute;
3812
+
3446
3813
  ##### `"redis_queued_locks.explicit_lock_release"`
3447
3814
  - <sup>\[[back to the list](#instrumentation-events)\]</sup>
3448
3815
  - an event signalizes about the explicit lock release (invoked via `RedisQueuedLock#unlock`);
@@ -3484,7 +3851,7 @@ Detalized event semantics and payload structure:
3484
3851
  - raised from `#clear_locks_of` and `#clear_current_locks` (`#release_locks_of` and `#release_current_locks` respectively);
3485
3852
  - payload:
3486
3853
  - `:rel_time` - `float`/`milliseconds` - time spent on "release locks of" operation;
3487
- - `:at` - `float`/`epoch` - the time when the opertaion has ended;
3854
+ - `:at` - `float`/`epoch` - the time when the opertaion has ended;
3488
3855
  - `:acq_id` - `string` - refused acquirer identifier;
3489
3856
  - `:hst_id` - `string` - refused host identifier;
3490
3857
  - `:rel_key_cnt` - `integer` - released locks count (write locks and read locks);
@@ -3533,9 +3900,6 @@ Detalized event semantics and payload structure:
3533
3900
  <sup>\[[back to top](#table-of-contents)\]</sup>
3534
3901
 
3535
3902
  - **Major**:
3536
- - **Experimental feature**: (non-`timed` locks): per-ruby-block-holding-the-lock sidecar `Ractor` and `in progress queue` in RedisDB that will extend
3537
- the acquired lock for long-running blocks of code (that invoked "under" the lock
3538
- whose ttl may expire before the block execution completes). It makes sense for non-`timed` locks *only*;
3539
3903
  - think about "thread priority" configuration :thinking:;
3540
3904
  - add `hst_id` to all methods that works with queues info;
3541
3905
  - try to return the `fiber object id` to the lock host identifier (we cant use fiber object id cuz `ObjectSpace` has no access to the fiber object space after the any ractor object initialization)
@@ -3549,7 +3913,7 @@ Detalized event semantics and payload structure:
3549
3913
  the global "timeout request" queue and managed by a single global "timeout wathcer" thread). it should prevent any logic and timeout intersections,
3550
3914
  some GVL-related things and problem situations when the global watcher thread is "dead";
3551
3915
  - **strict redlock algorithm support** (support for many `RedisClient` instances that are fully independent (distributed redis instances));
3552
- - an ability to release all locks and all requests of the concrete acquirer id or host id (or both in validation-orianted combination);
3916
+ - an ability to release all locks and all requests of the concrete acquirer id only or of the concrete host id only (both together: `#clear_locks_of`);
3553
3917
  - detailed lock informotion inside the error object in cases of exceptions (at the moment we have this info inside the error message only that hard to analyze in work);
3554
3918
  - a convenient way to mark any `lock` invocation as "non-instrumentable" / "non-loggable" (as an alternative to `VoidNotifier` and to `VoidLogger`);
3555
3919
  - `README`-section `Issues with other Libs` about issues in other libraries that can broke RQL features:
@@ -3564,7 +3928,7 @@ Detalized event semantics and payload structure:
3564
3928
  - an ability to return all insturmentation metrics from the `lock` invocation (and after block `yield`ing);
3565
3929
  - think about a PG-like `stats`-data/table, that should be helpful for lock history acquirement analyzation :thinking: (suitable for cases when we want
3566
3930
  to check if the lock was acquired by some different parallel process durign the some period of time in the past or not);
3567
- - named RQL's threads (`Thread#name`) and RQL's ractors (`Ractor#name`) in order to have an ability to find and work with RQL's threads and ractors outside of RQL logic (stop threads before process forking, for example);
3931
+ - named swarm threads (`Thread#name`) and ractors (`Ractor#name`; the lock keeper thread is already named `rql.lock_keeper`) in order to have an ability to find and work with RQL's threads and ractors outside of RQL logic (stop threads before process forking, for example);
3568
3932
  - `#lock`/`#lock!` - `timeout:` option: support for granular periods (it supports only `seconds` at the moment, but we need `milliseconds`);
3569
3933
  - Add `after timeout hook` ability for timeout errors with an ability to access the binding context (if it possibly) of the thread where it failed;
3570
3934
  - Add `ignore timeout errors` ability (for debug purposes);
@@ -3577,7 +3941,7 @@ Detalized event semantics and payload structure:
3577
3941
  - Semantic error objects for unexpected Redis errors;
3578
3942
  - sized lock queues (with an ability of dynamically growing size);
3579
3943
  - better code stylization (+ some refactorings);
3580
- - `RedisQueuedLocks::Acquirer::Try.try_to_lock` - detailed successful result analization;
3944
+ - `RedisQueuedLocks::Acquirer::AcquireLock::TryToLock#try_to_lock` - detailed successful result analization;
3581
3945
  - Support for LIFO strategy;
3582
3946
  - specs refactoring with 100% test coverage (total specs rework);
3583
3947
  - statistics with UI;
@@ -3598,6 +3962,8 @@ Detalized event semantics and payload structure:
3598
3962
 
3599
3963
  ## Build and Develop
3600
3964
 
3965
+ <sup>\[[back to top](#table-of-contents)\]</sup>
3966
+
3601
3967
  - Tests (`RSpec`):
3602
3968
  ```shell
3603
3969
  bundle exec rake rspec
@@ -3626,8 +3992,10 @@ bundle exec rake steep:check
3626
3992
 
3627
3993
  - `Runtime` TypeChecking (`RBS`):
3628
3994
  ```shell
3629
- bundle exec rbs collection install && RBS_TEST_RAISE=true RUBYOPT='-rbundler/setup -rrbs/test/setup' RBS_TEST_OPT='-I sig' RBS_TEST_LOGLEVEL=error RBS_TEST_TARGET='RedisQueuedLocks::*' RBS_TEST_SKIP='::RedisQueuedLocks::Swarm::FlushZombies,::RedisQueuedLocks::Swarm::SwarmElement::Isolated,::RedisQueuedLocks::Swarm::RedisClientBuilder' bundle exec rspec
3630
- # or in parallel processes: the same environment with `bundle exec rake rspec:parallel` instead of `bundle exec rspec`
3995
+ bundle exec rbs collection install && RBS_TEST_RAISE=true RUBYOPT='-rbundler/setup -rrbs/test/setup' RBS_TEST_OPT='-I sig' RBS_TEST_LOGLEVEL=error RBS_TEST_TARGET='RedisQueuedLocks::*' RBS_TEST_SKIP='::RedisQueuedLocks::Swarm::FlushZombies,::RedisQueuedLocks::Swarm::SwarmElement::Isolated,::RedisQueuedLocks::Swarm::RedisClientBuilder' bundle exec rake rspec:parallel
3996
+ # parallel processes as in CI: `WORKERS=n` flushes db `0..2n-1` of the local Redis (see the parallel tests above);
3997
+ # or in one process (db 0 and db 1): the same environment with `bundle exec rspec` instead of `bundle exec rake rspec:parallel`;
3998
+ # CI also sets `RUBY_TCP_NO_FAST_FALLBACK=1` (no resolver threads per Redis connection: they starve the workers on a small CPU)
3631
3999
  ```
3632
4000
 
3633
4001
  ---