redis_queued_locks 1.21.0 → 1.22.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 (64) hide show
  1. checksums.yaml +4 -4
  2. data/.claude/project-overview.md +216 -25
  3. data/.claude/rules/acquirer.md +6 -5
  4. data/.claude/rules/arguments.md +2 -2
  5. data/.claude/rules/changelog.md +27 -0
  6. data/.claude/rules/git.md +1 -1
  7. data/.claude/rules/logic.md +10 -12
  8. data/.claude/rules/swarm.md +3 -4
  9. data/.claude/rules/tests.md +6 -6
  10. data/.claude/rules/type-checking.md +13 -14
  11. data/.claude/rules/visitors.md +5 -5
  12. data/.claude/skills/rql-code-review/SKILL.md +112 -35
  13. data/CHANGELOG.md +98 -244
  14. data/CLAUDE.md +9 -8
  15. data/README.md +275 -85
  16. data/Rakefile +11 -0
  17. data/lib/redis_queued_locks/acquirer/acquire_lock/instr_visitor.rb +28 -12
  18. data/lib/redis_queued_locks/acquirer/acquire_lock/log_visitor.rb +38 -16
  19. data/lib/redis_queued_locks/acquirer/acquire_lock/try_to_lock/log_visitor.rb +92 -15
  20. data/lib/redis_queued_locks/acquirer/acquire_lock/try_to_lock.rb +430 -63
  21. data/lib/redis_queued_locks/acquirer/acquire_lock.rb +72 -22
  22. data/lib/redis_queued_locks/acquirer/clear_dead_requests.rb +240 -45
  23. data/lib/redis_queued_locks/acquirer/extend_lock_ttl.rb +3 -1
  24. data/lib/redis_queued_locks/acquirer/keys.rb +6 -2
  25. data/lib/redis_queued_locks/acquirer/lock_series_poc/instr_visitor.rb +10 -5
  26. data/lib/redis_queued_locks/acquirer/lock_series_poc/log_visitor.rb +18 -9
  27. data/lib/redis_queued_locks/acquirer/lock_series_poc.rb +52 -23
  28. data/lib/redis_queued_locks/acquirer/locks.rb +6 -2
  29. data/lib/redis_queued_locks/acquirer/queue_info.rb +30 -7
  30. data/lib/redis_queued_locks/acquirer/queues.rb +17 -6
  31. data/lib/redis_queued_locks/acquirer/release_all_locks.rb +6 -2
  32. data/lib/redis_queued_locks/acquirer/release_locks_of.rb +6 -2
  33. data/lib/redis_queued_locks/client.rb +66 -24
  34. data/lib/redis_queued_locks/config.rb +93 -1
  35. data/lib/redis_queued_locks/resource.rb +124 -9
  36. data/lib/redis_queued_locks/swarm/swarm_element/threaded.rb +6 -5
  37. data/lib/redis_queued_locks/swarm/zombie_info.rb +6 -2
  38. data/lib/redis_queued_locks/version.rb +2 -2
  39. data/rbs_collection.lock.yaml +4 -0
  40. data/rbs_collection.yaml +2 -1
  41. data/sig/manifest.yml +1 -0
  42. data/sig/redis_queued_locks/acquirer/acquire_lock/dequeue_from_lock_queue/log_visitor.rbs +2 -2
  43. data/sig/redis_queued_locks/acquirer/acquire_lock/dequeue_from_lock_queue.rbs +2 -2
  44. data/sig/redis_queued_locks/acquirer/acquire_lock/instr_visitor.rbs +12 -6
  45. data/sig/redis_queued_locks/acquirer/acquire_lock/log_visitor.rbs +21 -14
  46. data/sig/redis_queued_locks/acquirer/acquire_lock/try_to_lock/log_visitor.rbs +61 -40
  47. data/sig/redis_queued_locks/acquirer/acquire_lock/try_to_lock.rbs +59 -11
  48. data/sig/redis_queued_locks/acquirer/acquire_lock/{yield_with_expire → yield_expire}/log_visitor.rbs +4 -4
  49. data/sig/redis_queued_locks/acquirer/acquire_lock/yield_expire.rbs +2 -2
  50. data/sig/redis_queued_locks/acquirer/acquire_lock.rbs +5 -3
  51. data/sig/redis_queued_locks/acquirer/clear_dead_requests.rbs +14 -1
  52. data/sig/redis_queued_locks/acquirer/extend_lock_ttl.rbs +2 -2
  53. data/sig/redis_queued_locks/acquirer/queues.rbs +1 -1
  54. data/sig/redis_queued_locks/client.rbs +10 -7
  55. data/sig/redis_queued_locks/config.rbs +54 -1
  56. data/sig/redis_queued_locks/instrument/sampler.rbs +3 -1
  57. data/sig/redis_queued_locks/instrument/void_notifier.rbs +3 -1
  58. data/sig/redis_queued_locks/logging/sampler.rbs +3 -1
  59. data/sig/redis_queued_locks/resource.rbs +22 -12
  60. data/sig/redis_queued_locks/swarm/swarm_element/threaded.rbs +1 -1
  61. data/sig/redis_queued_locks/utilities.rbs +2 -1
  62. data/sig/redis_queued_locks.rbs +7 -0
  63. metadata +4 -3
  64. /data/sig/redis_queued_locks/{acquier.rbs → acquirer.rbs} +0 -0
@@ -2,7 +2,7 @@
2
2
 
3
3
  # @api private
4
4
  # @since 1.7.0
5
- # @version 1.18.0
5
+ # @version 1.22.0
6
6
  # rubocop:disable Metrics/ModuleLength
7
7
  module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
8
8
  # rubocop:disable Metrics/ClassLength
@@ -349,11 +349,12 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
349
349
  # @param host_id [String]
350
350
  # @param access_strategy [Symbol]
351
351
  # @param rw_mode [Symbol]
352
+ # @param priority [Integer] The lock request priority.
352
353
  # @return [void]
353
354
  #
354
355
  # @api private
355
356
  # @since 1.7.0
356
- # @version 1.18.0
357
+ # @version 1.22.0
357
358
  def acq_added_to_queue(
358
359
  logger,
359
360
  log_sampled,
@@ -363,7 +364,8 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
363
364
  acquirer_id,
364
365
  host_id,
365
366
  access_strategy,
366
- rw_mode
367
+ rw_mode,
368
+ priority
367
369
  )
368
370
  return unless log_sampled && log_lock_try
369
371
 
@@ -374,7 +376,8 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
374
376
  "acq_id => '#{acquirer_id}' " \
375
377
  "hst_id => '#{host_id}' " \
376
378
  "acs_strat => '#{access_strategy}' " \
377
- "rw_mode => '#{rw_mode}'"
379
+ "rw_mode => '#{rw_mode}' " \
380
+ "priority => #{priority}"
378
381
  end rescue nil
379
382
  end
380
383
 
@@ -416,6 +419,52 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
416
419
  end rescue nil
417
420
  end
418
421
 
422
+ # (priorities) A dead lock request of another priority band blocked the lock request: it is
423
+ # dropped with all dead lock requests of its band (both lock queues).
424
+ #
425
+ # @param logger [::Logger,#debug]
426
+ # @param log_sampled [Boolean]
427
+ # @param log_lock_try [Boolean]
428
+ # @param lock_key [String]
429
+ # @param queue_ttl [Integer]
430
+ # @param acquirer_id [String]
431
+ # @param host_id [String]
432
+ # @param access_strategy [Symbol]
433
+ # @param rw_mode [Symbol]
434
+ # @param dead_acquirer [String] The acquirer of the dropped blocking lock request.
435
+ # @param dead_priority [Integer] The priority of the dropped blocking lock request.
436
+ # @return [void]
437
+ #
438
+ # @api private
439
+ # @since 1.22.0
440
+ def dead_request_removed(
441
+ logger,
442
+ log_sampled,
443
+ log_lock_try,
444
+ lock_key,
445
+ queue_ttl,
446
+ acquirer_id,
447
+ host_id,
448
+ access_strategy,
449
+ rw_mode,
450
+ dead_acquirer,
451
+ dead_priority
452
+ )
453
+ return unless log_sampled && log_lock_try
454
+
455
+ logger.debug do
456
+ "[redis_queued_locks.try_lock.dead_request_removed] " \
457
+ "lock_key => '#{lock_key}' " \
458
+ "queue_ttl => #{queue_ttl} " \
459
+ "acq_id => '#{acquirer_id}' " \
460
+ "hst_id => '#{host_id}' " \
461
+ "acs_strat => '#{access_strategy}' " \
462
+ "rw_mode => '#{rw_mode}' " \
463
+ "dead_acq_id => '#{dead_acquirer}' " \
464
+ "dead_priority => #{dead_priority}"
465
+ end rescue nil
466
+ end
467
+
419
468
  # @param logger [::Logger,#debug]
420
469
  # @param log_sampled [Boolean]
421
470
  # @param log_lock_try [Boolean]
@@ -426,11 +475,14 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
426
475
  # @param access_strategy [Symbol]
427
476
  # @param rw_mode [Symbol]
428
477
  # @param waiting_acquirer [String,NilClass]
478
+ # @param waiting_priority [Integer,NilClass]
479
+ # The priority of the first request (decoded for logs only: `nil` without logs and
480
+ # without the first request; logged as `nil` without the first request).
429
481
  # @return [void]
430
482
  #
431
483
  # @api private
432
484
  # @since 1.7.0
433
- # @version 1.18.0
485
+ # @version 1.22.0
434
486
  def get_first_from_queue(
435
487
  logger,
436
488
  log_sampled,
@@ -441,7 +493,8 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
441
493
  host_id,
442
494
  access_strategy,
443
495
  rw_mode,
444
- waiting_acquirer
496
+ waiting_acquirer,
497
+ waiting_priority
445
498
  )
446
499
  return unless log_sampled && log_lock_try
447
500
 
@@ -453,7 +506,8 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
453
506
  "hst_id => '#{host_id}' " \
454
507
  "acs_strat => '#{access_strategy}' " \
455
508
  "rw_mode => '#{rw_mode}' " \
456
- "first_acq_id_in_queue => '#{waiting_acquirer}'"
509
+ "first_acq_id_in_queue => '#{waiting_acquirer}' " \
510
+ "first_priority_in_queue => #{waiting_priority.inspect}"
457
511
  end rescue nil
458
512
  end
459
513
 
@@ -505,12 +559,14 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
505
559
  # @param access_strategy [Symbol]
506
560
  # @param rw_mode [Symbol]
507
561
  # @param waiting_acquirer [String,NilClass]
562
+ # @param waiting_priority [Integer,NilClass]
563
+ # The priority of the first request (decoded for logs only: `nil` without logs).
508
564
  # @param current_lock_data [Hash<String,Any>]
509
565
  # @return [void]
510
566
  #
511
567
  # @api private
512
568
  # @since 1.7.0
513
- # @version 1.18.0
569
+ # @version 1.22.0
514
570
  def exit__no_first(
515
571
  logger,
516
572
  log_sampled,
@@ -522,6 +578,7 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
522
578
  access_strategy,
523
579
  rw_mode,
524
580
  waiting_acquirer,
581
+ waiting_priority,
525
582
  current_lock_data
526
583
  )
527
584
  return unless log_sampled && log_lock_try
@@ -535,6 +592,7 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
535
592
  "acs_strat => '#{access_strategy}' " \
536
593
  "rw_mode => '#{rw_mode}' " \
537
594
  "first_acq_id_in_queue => '#{waiting_acquirer}' " \
595
+ "first_priority_in_queue => #{waiting_priority.inspect} " \
538
596
  "<current_lock_data> => <<#{current_lock_data}>>"
539
597
  end rescue nil
540
598
  end
@@ -549,13 +607,15 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
549
607
  # @param access_strategy [Symbol]
550
608
  # @param rw_mode [Symbol]
551
609
  # @param waiting_acquirer [String,NilClass]
610
+ # @param waiting_priority [Integer,NilClass]
611
+ # The priority of the first request (decoded for logs only: `nil` without logs).
552
612
  # @param locked_by_acquirer [String]
553
613
  # @param current_lock_data [Hash<String,Any>]
554
614
  # @return [void]
555
615
  #
556
616
  # @api private
557
617
  # @since 1.7.0
558
- # @version 1.18.0
618
+ # @version 1.22.0
559
619
  def exit__lock_still_obtained(
560
620
  logger,
561
621
  log_sampled,
@@ -567,6 +627,7 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
567
627
  access_strategy,
568
628
  rw_mode,
569
629
  waiting_acquirer,
630
+ waiting_priority,
570
631
  locked_by_acquirer,
571
632
  current_lock_data
572
633
  )
@@ -581,6 +642,7 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
581
642
  "acs_strat => '#{access_strategy}' " \
582
643
  "rw_mode => '#{rw_mode}' " \
583
644
  "first_acq_id_in_queue => '#{waiting_acquirer}' " \
645
+ "first_priority_in_queue => #{waiting_priority.inspect} " \
584
646
  "locked_by_acq_id => '#{locked_by_acquirer}' " \
585
647
  "<current_lock_data> => <<#{current_lock_data}>>"
586
648
  end rescue nil
@@ -598,10 +660,13 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
598
660
  # @param access_strategy [Symbol]
599
661
  # @param rw_mode [Symbol]
600
662
  # @param ahead_acquirer [String]
663
+ # @param ahead_priority [Integer,NilClass]
664
+ # The priority of the request ahead (decoded for logs only: `nil` without logs).
601
665
  # @return [void]
602
666
  #
603
667
  # @api private
604
668
  # @since 1.18.0
669
+ # @version 1.22.0
605
670
  def exit__write_request_ahead(
606
671
  logger,
607
672
  log_sampled,
@@ -612,7 +677,8 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
612
677
  host_id,
613
678
  access_strategy,
614
679
  rw_mode,
615
- ahead_acquirer
680
+ ahead_acquirer,
681
+ ahead_priority
616
682
  )
617
683
  return unless log_sampled && log_lock_try
618
684
 
@@ -624,7 +690,8 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
624
690
  "hst_id => '#{host_id}' " \
625
691
  "acs_strat => '#{access_strategy}' " \
626
692
  "rw_mode => '#{rw_mode}' " \
627
- "ahead_acq_id => '#{ahead_acquirer}'"
693
+ "ahead_acq_id => '#{ahead_acquirer}' " \
694
+ "ahead_priority => #{ahead_priority}"
628
695
  end rescue nil
629
696
  end
630
697
 
@@ -640,10 +707,13 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
640
707
  # @param access_strategy [Symbol]
641
708
  # @param rw_mode [Symbol]
642
709
  # @param ahead_acquirer [String]
710
+ # @param ahead_priority [Integer,NilClass]
711
+ # The priority of the request ahead (decoded for logs only: `nil` without logs).
643
712
  # @return [void]
644
713
  #
645
714
  # @api private
646
715
  # @since 1.18.0
716
+ # @version 1.22.0
647
717
  def exit__read_request_ahead(
648
718
  logger,
649
719
  log_sampled,
@@ -654,7 +724,8 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
654
724
  host_id,
655
725
  access_strategy,
656
726
  rw_mode,
657
- ahead_acquirer
727
+ ahead_acquirer,
728
+ ahead_priority
658
729
  )
659
730
  return unless log_sampled && log_lock_try
660
731
 
@@ -666,7 +737,8 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
666
737
  "hst_id => '#{host_id}' " \
667
738
  "acs_strat => '#{access_strategy}' " \
668
739
  "rw_mode => '#{rw_mode}' " \
669
- "ahead_acq_id => '#{ahead_acquirer}'"
740
+ "ahead_acq_id => '#{ahead_acquirer}' " \
741
+ "ahead_priority => #{ahead_priority}"
670
742
  end rescue nil
671
743
  end
672
744
 
@@ -683,10 +755,13 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
683
755
  # @param access_strategy [Symbol]
684
756
  # @param rw_mode [Symbol]
685
757
  # @param waiting_acquirer [String,NilClass]
758
+ # @param waiting_priority [Integer,NilClass]
759
+ # The priority of the first request (decoded for logs only: `nil` without logs).
686
760
  # @return [void]
687
761
  #
688
762
  # @api private
689
763
  # @since 1.18.0
764
+ # @version 1.22.0
690
765
  def exit__read_lock_still_obtained(
691
766
  logger,
692
767
  log_sampled,
@@ -697,7 +772,8 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
697
772
  host_id,
698
773
  access_strategy,
699
774
  rw_mode,
700
- waiting_acquirer
775
+ waiting_acquirer,
776
+ waiting_priority
701
777
  )
702
778
  return unless log_sampled && log_lock_try
703
779
 
@@ -709,7 +785,8 @@ module RedisQueuedLocks::Acquirer::AcquireLock::TryToLock::LogVisitor
709
785
  "hst_id => '#{host_id}' " \
710
786
  "acs_strat => '#{access_strategy}' " \
711
787
  "rw_mode => '#{rw_mode}' " \
712
- "first_acq_id_in_queue => '#{waiting_acquirer}'"
788
+ "first_acq_id_in_queue => '#{waiting_acquirer}' " \
789
+ "first_priority_in_queue => #{waiting_priority.inspect}"
713
790
  end rescue nil
714
791
  end
715
792