Class: RedisQueuedLocks::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_queued_locks/client.rb

Overview

rubocop:disable Metrics/ClassLength

Since:

  • 1.0.0

Version:

  • 1.16.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis_client, &configuration) ⇒ void

Parameters:

  • redis_client (RedisClient) —

    Redis connection manager, which will be used for the lock acquirerment and distribution. It should be an instance of RedisClient.

  • configuration (Block) —

    Custom configs for in-runtime configuration.

Since:

  • 1.0.0

Version:

  • 1.13.0



44
45
46
47
48
49
50
# File 'lib/redis_queued_locks/client.rb', line 44

def initialize(redis_client, &configuration)
  @config = RedisQueuedLocks::Config.new(&configuration)
  @uniq_identity = config['uniq_identifier'].call #: String
  @redis_client = redis_client
  @swarm = RedisQueuedLocks::Swarm.new(self)
  @swarm.swarm! if config['swarm.auto_swarm']
end

Instance Attribute Details

#config ⇒ RedisQueuedLocks::Config (readonly)

Returns:

Since:

  • 1.13.0



32
33
34
# File 'lib/redis_queued_locks/client.rb', line 32

def config
  @config
end

#redis_client ⇒ RedisClient (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (RedisClient)

Since:

  • 1.0.0



12
13
14
# File 'lib/redis_queued_locks/client.rb', line 12

def redis_client
  @redis_client
end

#swarm ⇒ RedisQueuedLocks::Swarm (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

Since:

  • 1.9.0



26
27
28
# File 'lib/redis_queued_locks/client.rb', line 26

def swarm
  @swarm
end

#uniq_identity ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

NOTE: attr_access here is chosen intentionally in order to have an ability to change uniq_identity value for debug purposes in runtime;

Returns:

  • (String)

Since:

  • 1.0.0



20
21
22
# File 'lib/redis_queued_locks/client.rb', line 20

def uniq_identity
  @uniq_identity
end

Instance Method Details

#clear_current_locks(lock_scan_size: config['clear_locks_of__lock_scan_size'], queue_scan_size: config['clear_locks_of__queue_scan_size'], logger: config['logger'], instrumenter: config['instrumenter'], instrument: nil, log_sampling_enabled: config['log_sampling_enabled'], log_sampling_percent: config['log_sampling_percent'], log_sampler: config['log_sampler'], log_sample_this: false, instr_sampling_enabled: config['instr_sampling_enabled'], instr_sampling_percent: config['instr_sampling_percent'], instr_sampler: config['instr_sampler'], instr_sample_this: false) ⇒ Hash<Symbol,Boolean|Hash<Symbol,Numeric>> Also known as: release_current_locks

Release all locks of the current acquirer/host and remove the current acquirer/host from all queues;

Parameters:

  • batch_size (Hash) —

    a customizable set of options

  • logger (Hash) (defaults to: config['logger']) —

    a customizable set of options

  • instrumenter (Hash) (defaults to: config['instrumenter']) —

    a customizable set of options

  • instrument (Hash) (defaults to: nil) —

    a customizable set of options

  • log_sampling_enabled (Hash) (defaults to: config['log_sampling_enabled']) —

    a customizable set of options

  • log_sampling_percent (Hash) (defaults to: config['log_sampling_percent']) —

    a customizable set of options

  • log_sampler (Hash) (defaults to: config['log_sampler']) —

    a customizable set of options

  • log_sample_this (Hash) (defaults to: false) —

    a customizable set of options

  • instr_sampling_enabled (Hash) (defaults to: config['instr_sampling_enabled']) —

    a customizable set of options

  • instr_sampling_percent (Hash) (defaults to: config['instr_sampling_percent']) —

    a customizable set of options

  • instr_sampler (Hash) (defaults to: config['instr_sampler']) —

    a customizable set of options

  • instr_sample_this (Hash) (defaults to: false) —

    a customizable set of options

Options Hash (logger:):

Options Hash (instrumenter:):

  • See (#notify) —

    config['instrumenter'] docs for details.

Options Hash (instrument:):

  • (NilClass, Any)

Options Hash (log_sampling_enabled:):

  • (Boolean)

Options Hash (log_sampling_percent:):

  • (Integer)

Options Hash (log_sampler:):

Options Hash (log_sample_this:):

  • (Boolean)

Options Hash (instr_sampling_enabled:):

  • (Boolean)

Options Hash (instr_sampling_percent:):

  • (Integer)

Options Hash (instr_sampler:):

Options Hash (instr_sample_this:):

  • (Boolean)

Returns:

  • (Hash<Symbol,Boolean|Hash<Symbol,Numeric>>) —

    Example: { ok: true, result: { rel_key_cnt: 100, tch_queue_cnt: 2, rel_time: 0.01 } }

See Also:

Since:

  • 1.14.0



1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
# File 'lib/redis_queued_locks/client.rb', line 1004

def clear_current_locks(
  lock_scan_size: config['clear_locks_of__lock_scan_size'], # steep:ignore
  queue_scan_size: config['clear_locks_of__queue_scan_size'], # steep:ingore
  logger: config['logger'], # steep:ignore
  instrumenter: config['instrumenter'], # steep:ignore
  instrument: nil,
  log_sampling_enabled: config['log_sampling_enabled'], # steep:ignore
  log_sampling_percent: config['log_sampling_percent'], # steep:ignore
  log_sampler: config['log_sampler'], # steep:ignore
  log_sample_this: false,
  instr_sampling_enabled: config['instr_sampling_enabled'], # steep:ignore
  instr_sampling_percent: config['instr_sampling_percent'], # steep:ignore
  instr_sampler: config['instr_sampler'], # steep:ignore
  instr_sample_this: false
)
  clear_locks_of(
    host_id: current_host_id,
    acquirer_id: current_acquirer_id,
    lock_scan_size:,
    queue_scan_size:,
    logger:,
    instrumenter:,
    instrument:,
    log_sampling_enabled:,
    log_sampling_percent:,
    log_sampler:,
    log_sample_this:,
    instr_sampling_enabled:,
    instr_sampling_percent:,
    instr_sampler:,
    instr_sample_this:
  )
end

#clear_dead_requests(dead_ttl: config['dead_request_ttl'], scan_size: config['lock_release_batch_size'], logger: config['logger'], instrumenter: config['instrumenter'], instrument: nil, log_sampling_enabled: config['log_sampling_enabled'], log_sampling_percent: config['log_sampling_percent'], log_sampler: config['log_sampler'], log_sample_this: false, instr_sampling_enabled: config['instr_sampling_enabled'], instr_sampling_percent: config['instr_sampling_percent'], instr_sampler: config['instr_sampler'], instr_sample_this: false) ⇒ Hash<Symbol,Boolean|Hash<Symbol,Set<String>>>

Returns Format: { ok: true, result: { processed_queus: Set } }.

Parameters:

  • dead_ttl (Hash) (defaults to: config['dead_request_ttl']) —

    a customizable set of options

  • scan_size (Hash) (defaults to: config['lock_release_batch_size']) —

    a customizable set of options

  • logger (Hash) (defaults to: config['logger']) —

    a customizable set of options

  • instrumenter (Hash) (defaults to: config['instrumenter']) —

    a customizable set of options

  • instrument (Hash) (defaults to: nil) —

    a customizable set of options

  • log_sampling_enabled (Hash) (defaults to: config['log_sampling_enabled']) —

    a customizable set of options

  • log_sampling_percent (Hash) (defaults to: config['log_sampling_percent']) —

    a customizable set of options

  • log_sampler (Hash) (defaults to: config['log_sampler']) —

    a customizable set of options

  • log_sample_this (Hash) (defaults to: false) —

    a customizable set of options

  • instr_sampling_enabled (Hash) (defaults to: config['instr_sampling_enabled']) —

    a customizable set of options

  • instr_sampling_percent (Hash) (defaults to: config['instr_sampling_percent']) —

    a customizable set of options

  • instr_sampler (Hash) (defaults to: config['instr_sampler']) —

    a customizable set of options

  • instr_sample_this (Hash) (defaults to: false) —

    a customizable set of options

Options Hash (dead_ttl:):

  • - (Integer) —

    the time period (in millsiecnds) after whcih the lock request is considered as dead;

    • config['dead_request_ttl'] is used by default;

Options Hash (scan_size:):

  • - (Integer) —

    the batch of scanned keys for Redis'es SCAN command;

    • config['lock_release_batch_size'] is used by default;

Options Hash (logger:):

Options Hash (instrumenter:):

  • (#notify)

Options Hash (instrument:):

  • (NilClass, Any)

Options Hash (log_sampling_enabled:):

  • (Boolean)

Options Hash (log_sampling_percent:):

  • (Integer)

Options Hash (log_sampler:):

Options Hash (log_sample_this:):

  • (Boolean)

Options Hash (instr_sampling_enabled:):

  • (Boolean)

Options Hash (instr_sampling_percent:):

  • (Integer)

Options Hash (instr_sampler:):

Options Hash (instr_sample_this:):

  • (Boolean)

Returns:

  • (Hash<Symbol,Boolean|Hash<Symbol,Set<String>>>) —

    Format: { ok: true, result: { processed_queus: Set } }

Since:

  • 1.0.0

Version:

  • 1.6.0



1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
# File 'lib/redis_queued_locks/client.rb', line 1137

def clear_dead_requests(
  dead_ttl: config['dead_request_ttl'], # steep:ignore
  scan_size: config['lock_release_batch_size'], # steep:ignore
  logger: config['logger'], # steep:ignore
  instrumenter: config['instrumenter'], # steep:ignore
  instrument: nil,
  log_sampling_enabled: config['log_sampling_enabled'], # steep:ignore
  log_sampling_percent: config['log_sampling_percent'], # steep:ignore
  log_sampler: config['log_sampler'], # steep:ignore
  log_sample_this: false,
  instr_sampling_enabled: config['instr_sampling_enabled'], # steep:ignore
  instr_sampling_percent: config['instr_sampling_percent'], # steep:ignore
  instr_sampler: config['instr_sampler'], # steep:ignore
  instr_sample_this: false
)
  RedisQueuedLocks::Acquirer::ClearDeadRequests.clear_dead_requests(
    redis_client,
    scan_size,
    dead_ttl,
    logger,
    instrumenter,
    instrument,
    log_sampling_enabled,
    log_sampling_percent,
    log_sampler,
    log_sample_this,
    instr_sampling_enabled,
    instr_sampling_percent,
    instr_sampler,
    instr_sample_this
  )
end

#clear_locks(batch_size: config['lock_release_batch_size'], logger: config['logger'], instrumenter: config['instrumenter'], instrument: nil, log_sampling_enabled: config['log_sampling_enabled'], log_sampling_percent: config['log_sampling_percent'], log_sampler: config['log_sampler'], log_sample_this: false, instr_sampling_enabled: config['instr_sampling_enabled'], instr_sampling_percent: config['instr_sampling_percent'], instr_sampler: config['instr_sampler'], instr_sample_this: false) ⇒ Hash<Symbol,Boolean|Hash<Symbol,Numeric>> Also known as: release_locks

Releases all queues and locks. Returns:

- :rel_time - (milliseconds) - time spent to release all locks and queues;
- :rel_key_cnt - (integer) - the number of released redis keys (queus+locks);

Parameters:

  • batch_size (Hash) (defaults to: config['lock_release_batch_size']) —

    a customizable set of options

  • logger (Hash) (defaults to: config['logger']) —

    a customizable set of options

  • instrumenter (Hash) (defaults to: config['instrumenter']) —

    a customizable set of options

  • instrument (Hash) (defaults to: nil) —

    a customizable set of options

  • log_sampling_enabled (Hash) (defaults to: config['log_sampling_enabled']) —

    a customizable set of options

  • log_sampling_percent (Hash) (defaults to: config['log_sampling_percent']) —

    a customizable set of options

  • log_sampler (Hash) (defaults to: config['log_sampler']) —

    a customizable set of options

  • log_sample_this (Hash) (defaults to: false) —

    a customizable set of options

  • instr_sampling_enabled (Hash) (defaults to: config['instr_sampling_enabled']) —

    a customizable set of options

  • instr_sampling_percent (Hash) (defaults to: config['instr_sampling_percent']) —

    a customizable set of options

  • instr_sampler (Hash) (defaults to: config['instr_sampler']) —

    a customizable set of options

  • instr_sample_this (Hash) (defaults to: false) —

    a customizable set of options

Options Hash (batch_size:):

  • (Integer)

Options Hash (logger:):

Options Hash (instrumenter:):

  • See (#notify) —

    config['instrumenter'] docs for details.

Options Hash (instrument:):

  • (NilClass, Any)

Options Hash (log_sampling_enabled:):

  • (Boolean)

Options Hash (log_sampling_percent:):

  • (Integer)

Options Hash (log_sampler:):

Options Hash (log_sample_this:):

  • (Boolean)

Options Hash (instr_sampling_enabled:):

  • (Boolean)

Options Hash (instr_sampling_percent:):

  • (Integer)

Options Hash (instr_sampler:):

Options Hash (instr_sample_this:):

  • (Boolean)

Returns:

  • (Hash<Symbol,Boolean|Hash<Symbol,Numeric>>) —

    Example: { ok: true, result { rel_key_cnt: 100, rel_time: 0.01 } }

Since:

  • 1.0.0

Version:

  • 1.6.0



859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
# File 'lib/redis_queued_locks/client.rb', line 859

def clear_locks(
  batch_size: config['lock_release_batch_size'], # steep:ignore
  logger: config['logger'], # steep:ignore
  instrumenter: config['instrumenter'], # steep:ignore
  instrument: nil,
  log_sampling_enabled: config['log_sampling_enabled'], # steep:ignore
  log_sampling_percent: config['log_sampling_percent'], # steep:ignore
  log_sampler: config['log_sampler'], # steep:ignore
  log_sample_this: false,
  instr_sampling_enabled: config['instr_sampling_enabled'], # steep:ignore
  instr_sampling_percent: config['instr_sampling_percent'], # steep:ignore
  instr_sampler: config['instr_sampler'], # steep:ignore
  instr_sample_this: false
)
  RedisQueuedLocks::Acquirer::ReleaseAllLocks.release_all_locks(
    redis_client,
    batch_size,
    logger,
    instrumenter,
    instrument,
    log_sampling_enabled,
    log_sampling_percent,
    log_sampler,
    log_sample_this,
    instr_sampling_enabled,
    instr_sampling_percent,
    instr_sampler,
    instr_sample_this
  )
end

#clear_locks_of(host_id:, acquirer_id:, lock_scan_size: config['clear_locks_of__lock_scan_size'], queue_scan_size: config['clear_locks_of__queue_scan_size'], logger: config['logger'], instrumenter: config['instrumenter'], instrument: nil, log_sampling_enabled: config['log_sampling_enabled'], log_sampling_percent: config['log_sampling_percent'], log_sampler: config['log_sampler'], log_sample_this: false, instr_sampling_enabled: config['instr_sampling_enabled'], instr_sampling_percent: config['instr_sampling_percent'], instr_sampler: config['instr_sampler'], instr_sample_this: false) ⇒ Hash<Symbol,Boolean|Hash<Symbol,Numeric>> Also known as: release_locks_of

Release all locks of the passed acquirer/host and remove this acquirer/host from all queues;

This is a cleanup helper intended for operational and debugging scenarios (for example: your current puma request thread is killed by Rack::Timeout and you need to cleanup all zombie RQL locks and lock reuqests obtained during the request processing).

Identifiers can be extracted via:

- `#current_host_id`
- `#current_acquirer_id`
- `#possible_host_ids`
- lock data (extracted from Redis via #lock_info, #locks_info, #queue_info, #queues_info)

Examples:

Release locks of the current process:

client.clear_locks_of(
  host_id: client.current_host_id,
  acquirer_id: client.current_acquirer_id
)

Release locks of a different host/acquirer:

client.clear_locks_of(
  host_id: "rql:hst:62681/2016/2032/b30ec5e4bea10512",
  acquirer_id: "ral:acq:62681/2016/2024/2032/b30ec5e4bea10512"
)

Parameters:

  • host_id (Hash) —

    a customizable set of options

  • acquirer_id (Hash) —

    a customizable set of options

  • lock_scan_size (Hash) (defaults to: config['clear_locks_of__lock_scan_size']) —

    a customizable set of options

  • queue_scan_size (Hash) (defaults to: config['clear_locks_of__queue_scan_size']) —

    a customizable set of options

  • logger (Hash) (defaults to: config['logger']) —

    a customizable set of options

  • instrumenter (Hash) (defaults to: config['instrumenter']) —

    a customizable set of options

  • instrument (Hash) (defaults to: nil) —

    a customizable set of options

  • log_sampling_enabled (Hash) (defaults to: config['log_sampling_enabled']) —

    a customizable set of options

  • log_sampling_percent (Hash) (defaults to: config['log_sampling_percent']) —

    a customizable set of options

  • log_sampler (Hash) (defaults to: config['log_sampler']) —

    a customizable set of options

  • log_sample_this (Hash) (defaults to: false) —

    a customizable set of options

  • instr_sampling_enabled (Hash) (defaults to: config['instr_sampling_enabled']) —

    a customizable set of options

  • instr_sampling_percent (Hash) (defaults to: config['instr_sampling_percent']) —

    a customizable set of options

  • instr_sampler (Hash) (defaults to: config['instr_sampler']) —

    a customizable set of options

  • instr_sample_this (Hash) (defaults to: false) —

    a customizable set of options

Options Hash (host_id:):

  • Host (String) —

    identifier whose locks/queues should be released.

Options Hash (acquirer_id:):

  • Acquirer (String) —

    identifier, associated with the host_id.

Options Hash (lock_scan_size:):

  • (Integer)

Options Hash (queue_scan_size:):

  • (Integer)

Options Hash (logger:):

Options Hash (instrumenter:):

  • See (#notify) —

    config['instrumenter'] docs for details.

Options Hash (instrument:):

  • (NilClass, Any)

Options Hash (log_sampling_enabled:):

  • (Boolean)

Options Hash (log_sampling_percent:):

  • (Integer)

Options Hash (log_sampler:):

Options Hash (log_sample_this:):

  • (Boolean)

Options Hash (instr_sampling_enabled:):

  • (Boolean)

Options Hash (instr_sampling_percent:):

  • (Integer)

Options Hash (instr_sampler:):

Options Hash (instr_sample_this:):

  • (Boolean)

Returns:

  • (Hash<Symbol,Boolean|Hash<Symbol,Numeric>>) —

    Example: { ok: true, result: { rel_key_cnt: 100, tch_queue_cnt: 2, rel_time: 0.01 } }

See Also:

Since:

  • 1.14.0



944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
# File 'lib/redis_queued_locks/client.rb', line 944

def clear_locks_of(
  host_id:,
  acquirer_id:,
  lock_scan_size: config['clear_locks_of__lock_scan_size'], # steep:ignore
  queue_scan_size: config['clear_locks_of__queue_scan_size'], # steep:ingore
  logger: config['logger'], # steep:ignore
  instrumenter: config['instrumenter'], # steep:ignore
  instrument: nil,
  log_sampling_enabled: config['log_sampling_enabled'], # steep:ignore
  log_sampling_percent: config['log_sampling_percent'], # steep:ignore
  log_sampler: config['log_sampler'], # steep:ignore
  log_sample_this: false,
  instr_sampling_enabled: config['instr_sampling_enabled'], # steep:ignore
  instr_sampling_percent: config['instr_sampling_percent'], # steep:ignore
  instr_sampler: config['instr_sampler'], # steep:ignore
  instr_sample_this: false
)
  RedisQueuedLocks::Acquirer::ReleaseLocksOf.release_locks_of(
    host_id,
    acquirer_id,
    redis_client,
    lock_scan_size,
    queue_scan_size,
    logger,
    instrumenter,
    instrument,
    log_sampling_enabled,
    log_sampling_percent,
    log_sampler,
    log_sample_this,
    instr_sampling_enabled,
    instr_sampling_percent,
    instr_sampler,
    instr_sample_this
  )
end

#configure(&configuration) ⇒ void

This method returns an undefined value.

Parameters:

  • configuration (Block)

Since:

  • 1.13.0



57
58
59
# File 'lib/redis_queued_locks/client.rb', line 57

def configure(&configuration)
  config.configure(&configuration)
end

#current_acquirer_id(process_id: RedisQueuedLocks::Resource.get_process_id, thread_id: RedisQueuedLocks::Resource.get_thread_id, fiber_id: RedisQueuedLocks::Resource.get_fiber_id, ractor_id: RedisQueuedLocks::Resource.get_ractor_id, identity: uniq_identity) ⇒ String Also known as: current_acq_id, acq_id

Retrun the current acquirer identifier.

Parameters:

  • process_id (Hash) (defaults to: RedisQueuedLocks::Resource.get_process_id) —

    a customizable set of options

  • thread_id (Hash) (defaults to: RedisQueuedLocks::Resource.get_thread_id) —

    a customizable set of options

  • fiber_id (Hash) (defaults to: RedisQueuedLocks::Resource.get_fiber_id) —

    a customizable set of options

  • ractor_id (Hash) (defaults to: RedisQueuedLocks::Resource.get_ractor_id) —

    a customizable set of options

  • identity (Hash) (defaults to: uniq_identity) —

    a customizable set of options

Options Hash (process_id:):

  • Process (Integer, Any) —

    identifier.

Options Hash (thread_id:):

  • Thread (Integer, Any) —

    identifier.

Options Hash (fiber_id:):

  • Fiber (Integer, Any) —

    identifier.

Options Hash (ractor_id:):

  • Ractor (Integer, Any) —

    identifier.

Options Hash (identity:):

  • Unique (String) —

    per-process string. See config['uniq_identifier'].

Returns:

  • (String)

See Also:

Since:

  • 1.8.0



710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
# File 'lib/redis_queued_locks/client.rb', line 710

def current_acquirer_id(
  process_id: RedisQueuedLocks::Resource.get_process_id,
  thread_id: RedisQueuedLocks::Resource.get_thread_id,
  fiber_id: RedisQueuedLocks::Resource.get_fiber_id,
  ractor_id: RedisQueuedLocks::Resource.get_ractor_id,
  identity: uniq_identity
)
  RedisQueuedLocks::Resource.acquirer_identifier(
    process_id,
    thread_id,
    fiber_id,
    ractor_id,
    identity
  )
end

#current_host_id(process_id: RedisQueuedLocks::Resource.get_process_id, thread_id: RedisQueuedLocks::Resource.get_thread_id, ractor_id: RedisQueuedLocks::Resource.get_ractor_id, identity: uniq_identity) ⇒ String Also known as: current_hst_id, hst_id

Retrun the current host identifier.

Parameters:

  • process_id (Hash) (defaults to: RedisQueuedLocks::Resource.get_process_id) —

    a customizable set of options

  • thread_id (Hash) (defaults to: RedisQueuedLocks::Resource.get_thread_id) —

    a customizable set of options

  • fiber_id (Hash) —

    a customizable set of options

  • ractor_id (Hash) (defaults to: RedisQueuedLocks::Resource.get_ractor_id) —

    a customizable set of options

  • identity (Hash) (defaults to: uniq_identity) —

    a customizable set of options

Options Hash (process_id:):

  • Process (Integer, Any) —

    identifier.

Options Hash (thread_id:):

  • Thread (Integer, Any) —

    identifier.

Options Hash (ractor_id:):

  • Ractor (Integer, Any) —

    identifier.

Options Hash (identity:):

  • Unique (String) —

    per-process string. See config['uniq_identifier'].

Returns:

  • (String)

See Also:

Since:

  • 1.9.0



745
746
747
748
749
750
751
752
753
754
755
756
757
# File 'lib/redis_queued_locks/client.rb', line 745

def current_host_id(
  process_id: RedisQueuedLocks::Resource.get_process_id,
  thread_id: RedisQueuedLocks::Resource.get_thread_id,
  ractor_id: RedisQueuedLocks::Resource.get_ractor_id,
  identity: uniq_identity
)
  RedisQueuedLocks::Resource.host_identifier(
    process_id,
    thread_id,
    ractor_id,
    identity
  )
end

#deswarmize! ⇒ Hash<Symbol,Boolean|Symbol>

Returns:

  • (Hash<Symbol,Boolean|Symbol>)

Since:

  • 1.9.0



73
74
75
# File 'lib/redis_queued_locks/client.rb', line 73

def deswarmize!
  swarm.deswarm!
end

#extend_lock_ttl(lock_name, milliseconds, logger: config['logger'], instrumenter: config['instrumenter'], instrument: nil, log_sampling_enabled: config['log_sampling_enabled'], log_sampling_percent: config['log_sampling_percent'], log_sampler: config['log_sampler'], log_sample_this: false, instr_sampling_enabled: config['instr_sampling_enabled'], instr_sampling_percent: config['instr_sampling_percent'], instr_sampler: config['instr_sampler'], instr_sample_this: false) ⇒ Hash<Symbol,Boolean|Symbol>

This method is non-atomic cuz redis does not provide an atomic function for TTL/PTTL extension. So the methid is spliited into the two commands:

(1) read current pttl
(2) set new ttl that is calculated as "current pttl + additional milliseconds"

What can happen during these steps

  • lock is expired between commands or before the first command;
  • lock is expired before the second command;
  • lock is expired AND newly acquired by another process (so you will extend the totally new lock with fresh PTTL); Use it at your own risk and consider async nature when calling this method.

Parameters:

  • lock_name (String)
  • milliseconds (Integer) —

    How many milliseconds should be added.

  • logger (Hash) (defaults to: config['logger']) —

    a customizable set of options

  • instrumenter (Hash) (defaults to: config['instrumenter']) —

    a customizable set of options

  • instrument (Hash) (defaults to: nil) —

    a customizable set of options

  • log_sampling_enabled (Hash) (defaults to: config['log_sampling_enabled']) —

    a customizable set of options

  • log_sampling_percent (Hash) (defaults to: config['log_sampling_percent']) —

    a customizable set of options

  • log_sampler (Hash) (defaults to: config['log_sampler']) —

    a customizable set of options

  • log_sample_this (Hash) (defaults to: false) —

    a customizable set of options

  • instr_sampling_enabled (Hash) (defaults to: config['instr_sampling_enabled']) —

    a customizable set of options

  • instr_sampling_percent (Hash) (defaults to: config['instr_sampling_percent']) —

    a customizable set of options

  • instr_sampler (Hash) (defaults to: config['instr_sampler']) —

    a customizable set of options

  • instr_sample_this (Hash) (defaults to: false) —

    a customizable set of options

Options Hash (logger:):

Options Hash (instrumenter:):

  • See (#notify) —

    config['instrumenter'] docs for details.

Options Hash (instrument:):

  • (NilClass, Any)

Options Hash (log_sampling_enabled:):

  • (Boolean)

Options Hash (log_sampling_percent:):

  • (Integer)

Options Hash (log_sampler:):

Options Hash (log_sample_this:):

  • (Boolean)

Options Hash (instr_sampling_enabled:):

  • (Boolean)

Options Hash (instr_sampling_percent:):

  • (Integer)

Options Hash (instr_sampler:):

Options Hash (instr_sample_this:):

  • (Boolean)

Returns:

  • (Hash<Symbol,Boolean|Symbol>) —
    • { ok: true, result: :ttl_extended }
    • { ok: false, result: :async_expire_or_no_lock }

Since:

  • 1.0.0

Version:

  • 1.6.0



803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
# File 'lib/redis_queued_locks/client.rb', line 803

def extend_lock_ttl(
  lock_name,
  milliseconds,
  logger: config['logger'], # steep:ignore
  instrumenter: config['instrumenter'], # steep:ignore
  instrument: nil,
  log_sampling_enabled: config['log_sampling_enabled'], # steep:ignore
  log_sampling_percent: config['log_sampling_percent'], # steep:ignore
  log_sampler: config['log_sampler'], # steep:ignore
  log_sample_this: false,
  instr_sampling_enabled: config['instr_sampling_enabled'], # steep:ignore
  instr_sampling_percent: config['instr_sampling_percent'], # steep:ignore
  instr_sampler: config['instr_sampler'], # steep:ignore
  instr_sample_this: false
)
  RedisQueuedLocks::Acquirer::ExtendLockTTL.extend_lock_ttl(
    redis_client,
    lock_name,
    milliseconds,
    logger,
    instrumenter,
    instrument,
    log_sampling_enabled,
    log_sampling_percent,
    log_sampler,
    log_sample_this,
    instr_sampling_enabled,
    instr_sampling_percent,
    instr_sampler,
    instr_sample_this
  )
end

#flush_zombies(zombie_ttl: config['swarm.flush_zombies.zombie_ttl'], lock_scan_size: config['swarm.flush_zombies.zombie_lock_scan_size'], queue_scan_size: config['swarm.flush_zombies.zombie_queue_scan_size']) ⇒ Hash<Symbol,Boolean|Set<String>>

Parameters:

  • zombie_ttl (Hash) (defaults to: config['swarm.flush_zombies.zombie_ttl']) —

    a customizable set of options

  • lock_scan_size (Hash) (defaults to: config['swarm.flush_zombies.zombie_lock_scan_size']) —

    a customizable set of options

  • queue_scan_size (Hash) (defaults to: config['swarm.flush_zombies.zombie_queue_scan_size']) —

    a customizable set of options

Options Hash (zombie_ttl:):

  • (Integer)

Options Hash (lock_scan_size:):

  • (Integer)

Options Hash (queue_scan_size:):

  • (Integer)

Returns:

  • (Hash<Symbol,Boolean|Set<String>>)

Since:

  • 1.9.0



110
111
112
113
114
115
116
# File 'lib/redis_queued_locks/client.rb', line 110

def flush_zombies(
  zombie_ttl: config['swarm.flush_zombies.zombie_ttl'], # steep:ignore
  lock_scan_size: config['swarm.flush_zombies.zombie_lock_scan_size'], # steep:ignore
  queue_scan_size: config['swarm.flush_zombies.zombie_queue_scan_size'] # steep:ignore
)
  swarm.flush_zombies(zombie_ttl:, lock_scan_size:, queue_scan_size:)
end

#keys(scan_size: config['key_extraction_batch_size']) ⇒ Set<String>

Parameters:

  • scan_size (Hash) (defaults to: config['key_extraction_batch_size']) —

    a customizable set of options

Options Hash (scan_size:):

  • (Integer)

Returns:

  • (Set<String>)

Since:

  • 1.0.0



1109
1110
1111
# File 'lib/redis_queued_locks/client.rb', line 1109

def keys(scan_size: config['key_extraction_batch_size']) # steep:ignore
  RedisQueuedLocks::Acquirer::Keys.keys(redis_client, scan_size:)
end

#lock(lock_name, ttl: config['default_lock_ttl'], queue_ttl: config['default_queue_ttl'], timeout: config['try_to_lock_timeout'], timed: config['is_timed_by_default'], retry_count: config['retry_count'], retry_delay: config['retry_delay'], retry_jitter: config['retry_jitter'], raise_errors: false, fail_fast: false, conflict_strategy: config['default_conflict_strategy'], read_write_mode: :write, access_strategy: config['default_access_strategy'], identity: uniq_identity, meta: nil, detailed_acq_timeout_error: config['detailed_acq_timeout_error'], logger: config['logger'], log_lock_try: config['log_lock_try'], instrumenter: config['instrumenter'], instrument: nil, log_sampling_enabled: config['log_sampling_enabled'], log_sampling_percent: config['log_sampling_percent'], log_sampler: config['log_sampler'], log_sample_this: false, instr_sampling_enabled: config['instr_sampling_enabled'], instr_sampling_percent: config['instr_sampling_percent'], instr_sampler: config['instr_sampler'], instr_sample_this: false) { ... } ⇒ Hash<Symbol,Any>, yield

rubocop:disable Metrics/MethodLength

Parameters:

  • lock_name (String) —

    Lock name to be obtained.

  • ttl (Hash) (defaults to: config['default_lock_ttl']) —

    a customizable set of options

  • queue_ttl (Hash) (defaults to: config['default_queue_ttl']) —

    a customizable set of options

  • timeout (Hash) (defaults to: config['try_to_lock_timeout']) —

    a customizable set of options

  • timed (Hash) (defaults to: config['is_timed_by_default']) —

    a customizable set of options

  • retry_count (Hash) (defaults to: config['retry_count']) —

    a customizable set of options

  • retry_delay (Hash) (defaults to: config['retry_delay']) —

    a customizable set of options

  • retry_jitter (Hash) (defaults to: config['retry_jitter']) —

    a customizable set of options

  • raise_errors (Hash) (defaults to: false) —

    a customizable set of options

  • identity (Hash) (defaults to: uniq_identity) —

    a customizable set of options

  • fail_fast (Hash) (defaults to: false) —

    a customizable set of options

  • conflict_strategy (Hash) (defaults to: config['default_conflict_strategy']) —

    a customizable set of options

  • read_write_mode (Hash) (defaults to: :write) —

    a customizable set of options

  • access_strategy (Hash) (defaults to: config['default_access_strategy']) —

    a customizable set of options

  • meta (Hash) (defaults to: nil) —

    a customizable set of options

  • detailed_acq_timeout_error (Hash) (defaults to: config['detailed_acq_timeout_error']) —

    a customizable set of options

  • logger (Hash) (defaults to: config['logger']) —

    a customizable set of options

  • log_lock_try (Hash) (defaults to: config['log_lock_try']) —

    a customizable set of options

  • instrumenter (Hash) (defaults to: config['instrumenter']) —

    a customizable set of options

  • instrument (Hash) (defaults to: nil) —

    a customizable set of options

  • log_sampling_enabled (Hash) (defaults to: config['log_sampling_enabled']) —

    a customizable set of options

  • log_sampling_percent (Hash) (defaults to: config['log_sampling_percent']) —

    a customizable set of options

  • log_sampler (Hash) (defaults to: config['log_sampler']) —

    a customizable set of options

  • log_sample_this (Hash) (defaults to: false) —

    a customizable set of options

  • instr_sampling_enabled (Hash) (defaults to: config['instr_sampling_enabled']) —

    a customizable set of options

  • instr_sampling_percent (Hash) (defaults to: config['instr_sampling_percent']) —

    a customizable set of options

  • instr_sampler (Hash) (defaults to: config['instr_sampler']) —

    a customizable set of options

  • instr_sample_this (Hash) (defaults to: false) —

    a customizable set of options

Options Hash (ttl:):

  • Lock's (Integer) —

    time to live (in milliseconds).

Options Hash (queue_ttl:):

  • Lifetime (Integer) —

    of the acuier's lock request. In seconds.

Options Hash (timeout:):

  • Time (Integer, NilClass) —

    period whe should try to acquire the lock (in seconds). Nil means "without timeout".

Options Hash (timed:):

  • Limit (Boolean) —

    the invocation time period of the passed block of code by the lock's TTL.

Options Hash (retry_count:):

  • How (Integer, NilClass) —

    many times we should try to acquire a lock. Nil means "infinite retries".

Options Hash (retry_delay:):

  • A (Integer) —

    time-interval between the each retry (in milliseconds).

Options Hash (retry_jitter:):

  • Time-shift (Integer) —

    range for retry-delay (in milliseconds).

Options Hash (raise_errors:):

  • Raise (Boolean) —

    errors on library-related limits such as timeout or failed lock obtain.

Options Hash (fail_fast:):

  • - (Boolean) —

    Should the required lock to be checked before the try and exit immidietly if lock is already obtained;

    • Should the logic exit immidietly after the first try if the lock was obtained by another process while the lock request queue was initially empty;

Options Hash (conflict_strategy:):

  • - (Symbol) —

    The conflict strategy mode for cases when the process that obtained the lock want to acquire this lock again;

    • By default uses :wait_for_lock strategy;
    • pre-confured in config['default_conflict_strategy'];
    • Supports:
      • :work_through - continue working under the lock without lock's TTL extension;
      • :extendable_work_through - continue working under the lock with lock's TTL extension;
      • :wait_for_lock - (default) - work in classic way (with timeouts, retry delays, retry limits, etc - in classic way :));
      • :dead_locking - fail with deadlock exception;

Options Hash (read_write_mode:):

  • - (Symbol) —

    ?

Options Hash (access_strategy:):

  • - (Symbol) —

    The way in which the lock will be obtained;

    • By default it uses :queued strategy;
    • Supports following strategies:
      • :queued (FIFO): the classic queued behavior (default), your lock will be obitaned if you are first in queue and the required lock is free;
      • :random (RANDOM): obtain a lock without checking the positions in the queue (but with checking the limist, retries, timeouts and so on). if lock is free to obtain - it will be obtained;
    • pre-configured in config['default_access_strategy'];

Options Hash (identity:):

  • Unique (String) —

    acquire identifier that is also should be unique between processes and pods on different machines. By default the uniq identity string is represented as 10 bytes hexstr.

Options Hash (meta:):

  • - (NilClass, Hash<String|Symbol,Any>) —

    A custom metadata wich will be passed to the lock data in addition to the existing data;

    • Metadata can not contain reserved lock data keys;

Options Hash (detailed_acq_timeout_error:):

  • - (Boolean) —

    When the lock acquirement try reached the acquirement time limit (:timeout option) the RedisQueuedLocks::LockAcquirementTimeoutError is raised (when raise_errors option set to true). The error message contains the lock key name and the timeout value).

    • option adds the additional details to the error message:
      • current lock queue state (you can see which acquirer blocks your request and how much acquirers are in queue);
      • current lock data stored inside (for example: you can check the current acquirer and the lock meta state if you store some additional data there);
    • Realized as an option because of the additional lock data requires two additional Redis queries: (1) get the current lock from redis and (2) fetch the lock queue state;
    • These two additional Redis queries has async nature so you can receive inconsistent data of the lock and of the lock queue in your error emssage because:
      • required lock can be released after the error moment and before the error message build;
      • required lock can be obtained by other process after the error moment and before the error message build;
      • required lock queue can reach a state when the blocking acquirer start to obtain the lock and moved from the lock queue after the error moment and before the error message build;
    • You should consider the async nature of this error message and should use received data from error message correspondingly;
    • pre-configred in config['detailed_acq_timeout_error'];

Options Hash (logger:):

  • - (::Logger, #debug) —

    Logger object used from the configuration layer (see config);

    • See RedisQueuedLocks::Logging::VoidLogger for example;
    • Supports SemanticLogger::Logger (see "semantic_logger" gem)

Options Hash (log_lock_try:):

  • - (Boolean) —

    should be logged the each try of lock acquiring (a lot of logs can be generated depending on your retry configurations);

    • see config['log_lock_try'];

Options Hash (instrumenter:):

  • - (#notify) —

    Custom instrumenter that will be invoked via #notify method with event and payload data;

    • See RedisQueuedLocks::Instrument::ActiveSupport for examples and implementation details;
    • See Instrumentation section of docs;
    • pre-configured in config['isntrumenter'] with void notifier (RedisQueuedLocks::Instrumenter::VoidNotifier);

Options Hash (instrument:):

  • - (NilClass, Any) —

    Custom instrumentation data wich will be passed to the instrumenter's payload with :instrument key;

Options Hash (log_sampling_enabled:):

  • - (Boolean) —

    enables : only the configured percent of RQL cases will be logged;

    • disabled by default;
    • works in tandem with <config and <config>;

Options Hash (log_sampling_percent:):

  • - (Integer) —

    the percent of cases that should be logged;

    • take an effect when <config> is true;
    • works in tandem with <config> and <config> configs;

Options Hash (log_sampler:):

  • - (#sampling_happened?, Module<RedisQueuedLocks::Logging::Sampler>) —

    percent-based log sampler that decides should be RQL case logged or not;

    • works in tandem with <config> and <config> configs;
    • based on the ultra simple percent-based (weight-based) algorithm that uses SecureRandom.rand method so the algorithm error is ~(0%..13%);
    • you can provide your own log sampler with bettter algorithm that should realize sampling_happened?(percent) => boolean interface (see RedisQueuedLocks::Logging::Sampler for example);

Options Hash (log_sample_this:):

  • - (Boolean) —

    marks the method that everything should be logged despite the enabled log sampling;

    • makes sense when log sampling is enabled;

Options Hash (instr_sampling_enabled:):

  • - (Boolean) —

    enables : only the configured percent of RQL cases will be instrumented;

    • disabled by default;
    • works in tandem with <config> and <config>;

Options Hash (instr_sampling_percent:):

  • - (Integer) —

    the percent of cases that should be instrumented;

    • take an effect when <config> is true;
    • works in tandem with <config> and <config> configs;

Options Hash (instr_sampler:):

  • - (#sampling_happened?, Module<RedisQueuedLocks::Instrument::Sampler>) —

    percent-based log sampler that decides should be RQL case instrumented or not;

    • works in tandem with <config> and <config> configs;
    • based on the ultra simple percent-based (weight-based) algorithm that uses SecureRandom.rand method so the algorithm error is ~(0%..13%);
    • you can provide your own log sampler with bettter algorithm that should realize sampling_happened?(percent) => boolean interface (see RedisQueuedLocks::Instrument::Sampler for example);

Options Hash (instr_sample_this:):

  • - (Boolean) —

    marks the method that everything should be instrumneted despite the enabled instrumentation sampling;

    • makes sense when instrumentation sampling is enabled;

Yields:

  • A block of code that should be executed after the successfully acquired lock. @yieldreturn [Any]

Returns:

  • (Hash<Symbol,Any>, yield) —
    • Format: { ok: true/false, result: Symbol/Hash }.
    • If block is given the result of block's yield will be returned.

Since:

  • 1.0.0

Version:

  • 1.13.0



314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/redis_queued_locks/client.rb', line 314

def lock(
  lock_name,
  ttl: config['default_lock_ttl'], # steep:ignore
  queue_ttl: config['default_queue_ttl'], # steep:ignore
  timeout: config['try_to_lock_timeout'], # steep:ignore
  timed: config['is_timed_by_default'], # steep:ignore
  retry_count: config['retry_count'], # steep:ignore
  retry_delay: config['retry_delay'], # steep:ignore
  retry_jitter: config['retry_jitter'], # steep:ignore
  raise_errors: false,
  fail_fast: false,
  conflict_strategy: config['default_conflict_strategy'], # steep:ignore
  read_write_mode: :write,
  access_strategy: config['default_access_strategy'], # steep:ignore
  identity: uniq_identity,
  meta: nil,
  detailed_acq_timeout_error: config['detailed_acq_timeout_error'], # steep:ignore
  logger: config['logger'], # steep:ignore
  log_lock_try: config['log_lock_try'], # steep:ignore
  instrumenter: config['instrumenter'], # steep:ignore
  instrument: nil,
  log_sampling_enabled: config['log_sampling_enabled'], # steep:ignore
  log_sampling_percent: config['log_sampling_percent'], # steep:ignore
  log_sampler: config['log_sampler'], # steep:ignore
  log_sample_this: false,
  instr_sampling_enabled: config['instr_sampling_enabled'], # steep:ignore
  instr_sampling_percent: config['instr_sampling_percent'], # steep:ignore
  instr_sampler: config['instr_sampler'], # steep:ignore
  instr_sample_this: false,
  &block
)
  RedisQueuedLocks::Acquirer::AcquireLock.acquire_lock(
    redis_client,
    lock_name,
    process_id: RedisQueuedLocks::Resource.get_process_id,
    thread_id: RedisQueuedLocks::Resource.get_thread_id,
    fiber_id: RedisQueuedLocks::Resource.get_fiber_id,
    ractor_id: RedisQueuedLocks::Resource.get_ractor_id,
    ttl:,
    queue_ttl:,
    timeout:,
    timed:,
    retry_count:,
    retry_delay:,
    retry_jitter:,
    raise_errors:,
    instrumenter:,
    identity:,
    fail_fast:,
    conflict_strategy:,
    read_write_mode:,
    access_strategy:,
    meta:,
    detailed_acq_timeout_error:,
    logger:,
    log_lock_try:,
    instrument:,
    log_sampling_enabled:,
    log_sampling_percent:,
    log_sampler:,
    log_sample_this:,
    instr_sampling_enabled:,
    instr_sampling_percent:,
    instr_sampler:,
    instr_sample_this:,
    &block
  )
end

#lock!(lock_name, ttl: config['default_lock_ttl'], queue_ttl: config['default_queue_ttl'], timeout: config['try_to_lock_timeout'], timed: config['is_timed_by_default'], retry_count: config['retry_count'], retry_delay: config['retry_delay'], retry_jitter: config['retry_jitter'], fail_fast: false, conflict_strategy: config['default_conflict_strategy'], read_write_mode: :write, access_strategy: config['default_access_strategy'], identity: uniq_identity, instrumenter: config['instrumenter'], meta: nil, detailed_acq_timeout_error: config['detailed_acq_timeout_error'], logger: config['logger'], log_lock_try: config['log_lock_try'], instrument: nil, log_sampling_enabled: config['log_sampling_enabled'], log_sampling_percent: config['log_sampling_percent'], log_sampler: config['log_sampler'], log_sample_this: false, instr_sampling_enabled: config['instr_sampling_enabled'], instr_sampling_percent: config['instr_sampling_percent'], instr_sampler: config['instr_sampler'], instr_sample_this: false, &block) ⇒ Object

Note:

See #lock method signature.

Since:

  • 1.0.0

Version:

  • 1.13.0



534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
# File 'lib/redis_queued_locks/client.rb', line 534

def lock!(
  lock_name,
  ttl: config['default_lock_ttl'], # steep:ignore
  queue_ttl: config['default_queue_ttl'], # steep:ignore
  timeout: config['try_to_lock_timeout'], # steep:ignore
  timed: config['is_timed_by_default'], # steep:ignore
  retry_count: config['retry_count'], # steep:ignore
  retry_delay: config['retry_delay'], # steep:ignore
  retry_jitter: config['retry_jitter'], # steep:ignore
  fail_fast: false,
  conflict_strategy: config['default_conflict_strategy'], # steep:ignore
  read_write_mode: :write,
  access_strategy: config['default_access_strategy'], # steep:ignore
  identity: uniq_identity,
  instrumenter: config['instrumenter'], # steep:ignore
  meta: nil,
  detailed_acq_timeout_error: config['detailed_acq_timeout_error'], # steep:ignore
  logger: config['logger'], # steep:ignore
  log_lock_try: config['log_lock_try'], # steep:ignore
  instrument: nil,
  log_sampling_enabled: config['log_sampling_enabled'], # steep:ignore
  log_sampling_percent: config['log_sampling_percent'], # steep:ignore
  log_sampler: config['log_sampler'], # steep:ignore
  log_sample_this: false,
  instr_sampling_enabled: config['instr_sampling_enabled'], # steep:ignore
  instr_sampling_percent: config['instr_sampling_percent'], # steep:ignore
  instr_sampler: config['instr_sampler'], # steep:ignore
  instr_sample_this: false,
  &block
)
  lock(
    lock_name,
    ttl:,
    queue_ttl:,
    timeout:,
    timed:,
    retry_count:,
    retry_delay:,
    retry_jitter:,
    raise_errors: true,
    identity:,
    fail_fast:,
    logger:,
    log_lock_try:,
    meta:,
    detailed_acq_timeout_error:,
    instrument:,
    instrumenter:,
    conflict_strategy:,
    read_write_mode:,
    access_strategy:,
    log_sampling_enabled:,
    log_sampling_percent:,
    log_sampler:,
    log_sample_this:,
    instr_sampling_enabled:,
    instr_sampling_percent:,
    instr_sampler:,
    instr_sample_this:,
    &block
  )
end

#lock_info(lock_name) ⇒ Hash<String,String|Numeric>, NilClass

Parameters:

  • lock_name (String)

Returns:

  • (Hash<String,String|Numeric>, NilClass)

Since:

  • 1.0.0



679
680
681
# File 'lib/redis_queued_locks/client.rb', line 679

def lock_info(lock_name)
  RedisQueuedLocks::Acquirer::LockInfo.lock_info(redis_client, lock_name)
end

#lock_series(*lock_names, detailed_result: false, ttl: config['default_lock_ttl'], queue_ttl: config['default_queue_ttl'], timeout: config['try_to_lock_timeout'], timed: config['is_timed_by_default'], retry_count: config['retry_count'], retry_delay: config['retry_delay'], retry_jitter: config['retry_jitter'], raise_errors: false, fail_fast: false, conflict_strategy: config['default_conflict_strategy'], read_write_mode: :write, access_strategy: config['default_access_strategy'], identity: uniq_identity, meta: nil, detailed_acq_timeout_error: config['detailed_acq_timeout_error'], logger: config['logger'], log_lock_try: config['log_lock_try'], instrumenter: config['instrumenter'], instrument: nil, log_sampling_enabled: config['log_sampling_enabled'], log_sampling_percent: config['log_sampling_percent'], log_sampler: config['log_sampler'], log_sample_this: false, instr_sampling_enabled: config['instr_sampling_enabled'], instr_sampling_percent: config['instr_sampling_percent'], instr_sampler: config['instr_sampler'], instr_sample_this: false, &block) ⇒ Object

NOTE: Lock Series PoC rubocop:disable all

Since:

  • 1.16.0



388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/redis_queued_locks/client.rb', line 388

def lock_series( # steep:ignore
  *lock_names,
  detailed_result: false,
  ttl: config['default_lock_ttl'], # steep:ignore
  queue_ttl: config['default_queue_ttl'], # steep:ignore
  timeout: config['try_to_lock_timeout'], # steep:ignore
  timed: config['is_timed_by_default'], # steep:ignore
  retry_count: config['retry_count'], # steep:ignore
  retry_delay: config['retry_delay'], # steep:ignore
  retry_jitter: config['retry_jitter'], # steep:ignore
  raise_errors: false,
  fail_fast: false,
  conflict_strategy: config['default_conflict_strategy'], # steep:ignore
  read_write_mode: :write,
  access_strategy: config['default_access_strategy'], # steep:ignore
  identity: uniq_identity,
  meta: nil,
  detailed_acq_timeout_error: config['detailed_acq_timeout_error'], # steep:ignore
  logger: config['logger'], # steep:ignore
  log_lock_try: config['log_lock_try'], # steep:ignore
  instrumenter: config['instrumenter'], # steep:ignore
  instrument: nil,
  log_sampling_enabled: config['log_sampling_enabled'], # steep:ignore
  log_sampling_percent: config['log_sampling_percent'], # steep:ignore
  log_sampler: config['log_sampler'], # steep:ignore
  log_sample_this: false,
  instr_sampling_enabled: config['instr_sampling_enabled'], # steep:ignore
  instr_sampling_percent: config['instr_sampling_percent'], # steep:ignore
  instr_sampler: config['instr_sampler'], # steep:ignore
  instr_sample_this: false,
  &block
)
  RedisQueuedLocks::Acquirer::LockSeriesPoC.lock_series_poc( # steep:ignore
    redis_client,
    lock_names,
    detailed_result:,
    process_id: RedisQueuedLocks::Resource.get_process_id,
    thread_id: RedisQueuedLocks::Resource.get_thread_id,
    fiber_id: RedisQueuedLocks::Resource.get_fiber_id,
    ractor_id: RedisQueuedLocks::Resource.get_ractor_id,
    ttl:,
    queue_ttl:,
    timeout:,
    timed:,
    retry_count:,
    retry_delay:,
    retry_jitter:,
    raise_errors:,
    instrumenter:,
    identity:,
    fail_fast:,
    conflict_strategy:,
    read_write_mode:,
    access_strategy:,
    meta:,
    detailed_acq_timeout_error:,
    logger:,
    log_lock_try:,
    instrument:,
    log_sampling_enabled:,
    log_sampling_percent:,
    log_sampler:,
    log_sample_this:,
    instr_sampling_enabled:,
    instr_sampling_percent:,
    instr_sampler:,
    instr_sample_this:,
    &block
  )
end

#lock_series!(*lock_names, detailed_result: false, ttl: config['default_lock_ttl'], queue_ttl: config['default_queue_ttl'], timeout: config['try_to_lock_timeout'], timed: config['is_timed_by_default'], retry_count: config['retry_count'], retry_delay: config['retry_delay'], retry_jitter: config['retry_jitter'], fail_fast: false, conflict_strategy: config['default_conflict_strategy'], read_write_mode: :write, access_strategy: config['default_access_strategy'], identity: uniq_identity, meta: nil, detailed_acq_timeout_error: config['detailed_acq_timeout_error'], logger: config['logger'], log_lock_try: config['log_lock_try'], instrumenter: config['instrumenter'], instrument: nil, log_sampling_enabled: config['log_sampling_enabled'], log_sampling_percent: config['log_sampling_percent'], log_sampler: config['log_sampler'], log_sample_this: false, instr_sampling_enabled: config['instr_sampling_enabled'], instr_sampling_percent: config['instr_sampling_percent'], instr_sampler: config['instr_sampler'], instr_sample_this: false, &block) ⇒ Object

NOTE: Lock Series PoC rubocop:disable all

Since:

  • 1.16.0



464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
# File 'lib/redis_queued_locks/client.rb', line 464

def lock_series!( # steep:ignore
  *lock_names,
  detailed_result: false,
  ttl: config['default_lock_ttl'], # steep:ignore
  queue_ttl: config['default_queue_ttl'], # steep:ignore
  timeout: config['try_to_lock_timeout'], # steep:ignore
  timed: config['is_timed_by_default'], # steep:ignore
  retry_count: config['retry_count'], # steep:ignore
  retry_delay: config['retry_delay'], # steep:ignore
  retry_jitter: config['retry_jitter'], # steep:ignore
  fail_fast: false,
  conflict_strategy: config['default_conflict_strategy'], # steep:ignore
  read_write_mode: :write,
  access_strategy: config['default_access_strategy'], # steep:ignore
  identity: uniq_identity,
  meta: nil,
  detailed_acq_timeout_error: config['detailed_acq_timeout_error'], # steep:ignore
  logger: config['logger'], # steep:ignore
  log_lock_try: config['log_lock_try'], # steep:ignore
  instrumenter: config['instrumenter'], # steep:ignore
  instrument: nil,
  log_sampling_enabled: config['log_sampling_enabled'], # steep:ignore
  log_sampling_percent: config['log_sampling_percent'], # steep:ignore
  log_sampler: config['log_sampler'], # steep:ignore
  log_sample_this: false,
  instr_sampling_enabled: config['instr_sampling_enabled'], # steep:ignore
  instr_sampling_percent: config['instr_sampling_percent'], # steep:ignore
  instr_sampler: config['instr_sampler'], # steep:ignore
  instr_sample_this: false,
  &block
)
  lock_series( # steep:ignore
    *lock_names, # steep:ignore
    detailed_result:,
    ttl:,
    queue_ttl:,
    timeout:,
    timed:,
    retry_count:,
    retry_delay:,
    retry_jitter:,
    raise_errors: true,
    fail_fast:,
    conflict_strategy:,
    read_write_mode:,
    access_strategy:,
    identity:,
    meta:,
    detailed_acq_timeout_error:,
    logger:,
    log_lock_try:,
    instrumenter:,
    instrument:,
    log_sampling_enabled:,
    log_sampling_percent:,
    log_sampler:,
    log_sample_this:,
    instr_sampling_enabled:,
    instr_sampling_percent:,
    instr_sampler:,
    instr_sample_this:,
    &block
  )
end

#locked?(lock_name) ⇒ Boolean

Parameters:

  • lock_name (String)

Returns:

  • (Boolean)

Since:

  • 1.0.0



661
662
663
# File 'lib/redis_queued_locks/client.rb', line 661

def locked?(lock_name)
  RedisQueuedLocks::Acquirer::IsLocked.locked?(redis_client, lock_name)
end

#locks(scan_size: config['key_extraction_batch_size'], with_info: false) ⇒ Set<String>, Set<Hash<Symbol,Any>>

Parameters:

  • scan_size (Hash) (defaults to: config['key_extraction_batch_size']) —

    a customizable set of options

  • with_info (Hash) (defaults to: false) —

    a customizable set of options

Options Hash (scan_size:):

  • The (Integer) —

    batch of scanned keys for Redis'es SCAN command.

Options Hash (with_info:):

  • Extract (Boolean) —

    lock info or not. If you want to extract a lock info too you have to consider that during info extration the lock key may expire. The keys extraction (SCAN) without any info extraction is doing first. Possible options:

    • true => returns a set of hashes that represents the lock state: <lock:, status:, info:>
      • :lock (String) - the lock key in Redis database;
      • :status (Symbol) - lock key state in redis. possible values:
        • :released - the lock is expired/released during the info extraction;
        • :alive - the lock still obtained;
      • :info (Hash) - see #lock_info method for detals;
    • false => returns a set of strings that represents an active locks at the moment of Redis'es SCAN;

Returns:

  • (Set<String>, Set<Hash<Symbol,Any>>)

Since:

  • 1.0.0



1058
1059
1060
# File 'lib/redis_queued_locks/client.rb', line 1058

def locks(scan_size: config['key_extraction_batch_size'], with_info: false) # steep:ignore
  RedisQueuedLocks::Acquirer::Locks.locks(redis_client, scan_size:, with_info:)
end

#locks_info(scan_size: config['key_extraction_batch_size']) ⇒ Set<Hash<String,Any>>

Extracts lock keys with their info. See #locks(with_info: true) for details.

Parameters:

  • scan_size (Hash) (defaults to: config['key_extraction_batch_size']) —

    a customizable set of options

Options Hash (scan_size:):

  • (Integer)

Returns:

  • (Set<Hash<String,Any>>)

Since:

  • 1.0.0



1069
1070
1071
# File 'lib/redis_queued_locks/client.rb', line 1069

def locks_info(scan_size: config['key_extraction_batch_size']) # steep:ignore
  locks(scan_size:, with_info: true)
end

#possible_host_ids(identity = uniq_identity) ⇒ Array<String>

Return the list of possible host identifiers that can be reached from the current ractor.

Parameters:

  • identity (String) (defaults to: uniq_identity) —

    Unique identity (RedisQueuedLocks::Client#uniq_identity by default)

Returns:

  • (Array<String>)

Since:

  • 1.9.0



768
769
770
# File 'lib/redis_queued_locks/client.rb', line 768

def possible_host_ids(identity = uniq_identity)
  RedisQueuedLocks::Resource.possible_host_identifiers(identity)
end

#probe_hosts ⇒ Hash<Symbol,Boolean|String|Float>

Returns:

  • (Hash<Symbol,Boolean|String|Float>)

Since:

  • 1.9.0



99
100
101
# File 'lib/redis_queued_locks/client.rb', line 99

def probe_hosts
  swarm.probe_hosts
end

#queue_info(lock_name) ⇒ Hash<String|Array<Hash<String,String|Numeric>>,NilClass]

Returns Hash<String|Array<Hash<String,String|Numeric>>,NilClass].

Parameters:

  • lock_name (String)

Returns:

  • (Hash<String|Array<Hash<String,String|Numeric>>,NilClass]) —

    Hash<String|Array<Hash<String,String|Numeric>>,NilClass]

Since:

  • 1.0.0



688
689
690
# File 'lib/redis_queued_locks/client.rb', line 688

def queue_info(lock_name)
  RedisQueuedLocks::Acquirer::QueueInfo.queue_info(redis_client, lock_name)
end

#queued?(lock_name) ⇒ Boolean

Parameters:

  • lock_name (String)

Returns:

  • (Boolean)

Since:

  • 1.0.0



670
671
672
# File 'lib/redis_queued_locks/client.rb', line 670

def queued?(lock_name)
  RedisQueuedLocks::Acquirer::IsQueued.queued?(redis_client, lock_name)
end

#queues(scan_size: config['key_extraction_batch_size'], with_info: false) ⇒ Set<String>, String<Hash<Symbol,Any>>

Parameters:

  • scan_size (Hash) (defaults to: config['key_extraction_batch_size']) —

    a customizable set of options

  • with_info (Hash) (defaults to: false) —

    a customizable set of options

Options Hash (scan_size:):

  • The (Integer) —

    batch of scanned keys for Redis'es SCAN command.

Options Hash (with_info:):

  • Extract (Boolean) —

    lock qeue info or not. If you want to extract a lock queue info too you have to consider that during info extration the lock queue may become empty. The queue key extraction (SCAN) without queue info extraction is doing first. Possible options:

    • true => returns a set of hashes that represents the queue state: <queue:, containing:>
      • :queue (String) - the lock queue key in Redis database;
      • :requests (Array<Hash<String,Any>>) - queue state in redis. see #queue_info for details;
    • false => returns a set of strings that represents an active queues at the moment of Redis'es SCAN;

Returns:

  • (Set<String>, String<Hash<Symbol,Any>>)

Since:

  • 1.0.0



1089
1090
1091
# File 'lib/redis_queued_locks/client.rb', line 1089

def queues(scan_size: config['key_extraction_batch_size'], with_info: false) # steep:ignore
  RedisQueuedLocks::Acquirer::Queues.queues(redis_client, scan_size:, with_info:)
end

#queues_info(scan_size: config['key_extraction_batch_size']) ⇒ Set<Hash<Symbol,Any>>

Extracts lock queues with their info. See #queues(with_info: true) for details.

Parameters:

  • scan_size (Hash) (defaults to: config['key_extraction_batch_size']) —

    a customizable set of options

Options Hash (scan_size:):

  • (Integer)

Returns:

  • (Set<Hash<Symbol,Any>>)

Since:

  • 1.0.0



1100
1101
1102
# File 'lib/redis_queued_locks/client.rb', line 1100

def queues_info(scan_size: config['key_extraction_batch_size']) # steep:ignore
  queues(scan_size:, with_info: true)
end

#swarm_info(zombie_ttl: config['swarm.flush_zombies.zombie_ttl']) ⇒ Hash<String,Hash<Symbol,Float|Time>>

Parameters:

  • zombie_ttl (Hash) (defaults to: config['swarm.flush_zombies.zombie_ttl']) —

    a customizable set of options

Options Hash (zombie_ttl:):

  • (Integer)

Returns:

  • (Hash<String,Hash<Symbol,Float|Time>>)

Since:

  • 1.9.0



82
83
84
# File 'lib/redis_queued_locks/client.rb', line 82

def swarm_info(zombie_ttl: config['swarm.flush_zombies.zombie_ttl']) # steep:ignore
  swarm.swarm_info(zombie_ttl:)
end

#swarm_status ⇒ Hash<Symbol,Boolean|<Hash<Symbol,Boolean>>] Also known as: swarm_state

Returns Hash<Symbol,Boolean|<Hash<Symbol,Boolean>>].

Returns:

  • (Hash<Symbol,Boolean|<Hash<Symbol,Boolean>>]) —

    Hash<Symbol,Boolean|<Hash<Symbol,Boolean>>]

Since:

  • 1.9.0



90
91
92
# File 'lib/redis_queued_locks/client.rb', line 90

def swarm_status
  swarm.swarm_status
end

#swarmize! ⇒ Hash<Symbol,Boolean|Symbol>

Returns:

  • (Hash<Symbol,Boolean|Symbol>)

Since:

  • 1.9.0



65
66
67
# File 'lib/redis_queued_locks/client.rb', line 65

def swarmize!
  swarm.swarm!
end

#unlock(lock_name, logger: config['logger'], instrumenter: config['instrumenter'], instrument: nil, log_sampling_enabled: config['log_sampling_enabled'], log_sampling_percent: config['log_sampling_percent'], log_sampler: config['log_sampler'], log_sample_this: false, instr_sampling_enabled: config['instr_sampling_enabled'], instr_sampling_percent: config['instr_sampling_percent'], instr_sampler: config['instr_sampler'], instr_sample_this: false) ⇒ Hash<Symbol,Any> Also known as: release_lock

Returns Format: { ok: true/false, result: { rel_time: Integer, # rel_key: String, # lock key rel_queue: String, # lock queue queue_res: Symbol, # :released or :nothing_to_release lock_res: Symbol # :released or :nothing_to_release } }.

Parameters:

  • lock_name (String) —

    The lock name that should be released.

  • logger (Hash) (defaults to: config['logger']) —

    a customizable set of options

  • instrumenter (Hash) (defaults to: config['instrumenter']) —

    a customizable set of options

  • instrument (Hash) (defaults to: nil) —

    a customizable set of options

  • log_sampling_enabled (Hash) (defaults to: config['log_sampling_enabled']) —

    a customizable set of options

  • log_sampling_percent (Hash) (defaults to: config['log_sampling_percent']) —

    a customizable set of options

  • log_sampler (Hash) (defaults to: config['log_sampler']) —

    a customizable set of options

  • log_sample_this (Hash) (defaults to: false) —

    a customizable set of options

  • instr_sampling_enabled (Hash) (defaults to: config['instr_sampling_enabled']) —

    a customizable set of options

  • instr_sampling_percent (Hash) (defaults to: config['instr_sampling_percent']) —

    a customizable set of options

  • instr_sampler (Hash) (defaults to: config['instr_sampler']) —

    a customizable set of options

  • instr_sample_this (Hash) (defaults to: false) —

    a customizable set of options

Options Hash (logger:):

Options Hash (instrumenter:):

  • (#notify)

Options Hash (instrument:):

  • (NilClass, Any)

Options Hash (log_sampling_enabled:):

  • (Boolean)

Options Hash (log_sampling_percent:):

  • (Integer)

Options Hash (log_sampler:):

Options Hash (log_sample_this:):

  • (Boolean)

Options Hash (instr_sampling_enabled:):

  • (Boolean)

Options Hash (instr_sampling_percent:):

  • (Integer)

Options Hash (instr_sampler:):

Options Hash (instr_sample_this:):

  • (Boolean)

Returns:

  • (Hash<Symbol,Any>) —

    Format: { ok: true/false, result: { rel_time: Integer, # rel_key: String, # lock key rel_queue: String, # lock queue queue_res: Symbol, # :released or :nothing_to_release lock_res: Symbol # :released or :nothing_to_release } }

Since:

  • 1.0.0

Version:

  • 1.6.0



625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
# File 'lib/redis_queued_locks/client.rb', line 625

def unlock(
  lock_name,
  logger: config['logger'], # steep:ignore
  instrumenter: config['instrumenter'], # steep:ignore
  instrument: nil,
  log_sampling_enabled: config['log_sampling_enabled'], # steep:ignore
  log_sampling_percent: config['log_sampling_percent'], # steep:ignore
  log_sampler: config['log_sampler'], # steep:ignore
  log_sample_this: false,
  instr_sampling_enabled: config['instr_sampling_enabled'], # steep:ignore
  instr_sampling_percent: config['instr_sampling_percent'], # steep:ignore
  instr_sampler: config['instr_sampler'], # steep:ignore
  instr_sample_this: false
)
  RedisQueuedLocks::Acquirer::ReleaseLock.release_lock(
    redis_client,
    lock_name,
    instrumenter,
    logger,
    log_sampling_enabled,
    log_sampling_percent,
    log_sampler,
    log_sample_this,
    instr_sampling_enabled,
    instr_sampling_percent,
    instr_sampler,
    instr_sample_this
  )
end

#zombie_acquirers(zombie_ttl: config['swarm.flush_zombies.zombie_ttl'], lock_scan_size: config['swarm.flush_zombies.zombie_lock_scan_size']) ⇒ Set<String>

Parameters:

  • zombie_ttl (Hash) (defaults to: config['swarm.flush_zombies.zombie_ttl']) —

    a customizable set of options

  • lock_scan_size (Hash) (defaults to: config['swarm.flush_zombies.zombie_lock_scan_size']) —

    a customizable set of options

Options Hash (zombie_ttl:):

  • (Integer)

Options Hash (lock_scan_size:):

  • (Integer)

Returns:

  • (Set<String>)

Since:

  • 1.9.0



137
138
139
140
141
142
# File 'lib/redis_queued_locks/client.rb', line 137

def zombie_acquirers(
  zombie_ttl: config['swarm.flush_zombies.zombie_ttl'], # steep:ignore
  lock_scan_size: config['swarm.flush_zombies.zombie_lock_scan_size'] # steep:ignore
)
  swarm.zombie_acquirers(zombie_ttl:, lock_scan_size:)
end

#zombie_hosts(zombie_ttl: config['swarm.flush_zombies.zombie_ttl']) ⇒ Set<String>

Parameters:

  • zombie_ttl (Hash) (defaults to: config['swarm.flush_zombies.zombie_ttl']) —

    a customizable set of options

Options Hash (zombie_ttl:):

  • (Integer)

Returns:

  • (Set<String>)

Since:

  • 1.9.0



149
150
151
# File 'lib/redis_queued_locks/client.rb', line 149

def zombie_hosts(zombie_ttl: config['swarm.flush_zombies.zombie_ttl']) # steep:ignore
  swarm.zombie_hosts(zombie_ttl:)
end

#zombie_locks(zombie_ttl: config['swarm.flush_zombies.zombie_ttl'], lock_scan_size: config['swarm.flush_zombies.zombie_lock_scan_size']) ⇒ Set<String>

Parameters:

  • zombie_ttl (Hash) (defaults to: config['swarm.flush_zombies.zombie_ttl']) —

    a customizable set of options

  • lock_scan_size (Hash) (defaults to: config['swarm.flush_zombies.zombie_lock_scan_size']) —

    a customizable set of options

Options Hash (zombie_ttl:):

  • (Integer)

Options Hash (lock_scan_size:):

  • (Integer)

Returns:

  • (Set<String>)

Since:

  • 1.9.0



124
125
126
127
128
129
# File 'lib/redis_queued_locks/client.rb', line 124

def zombie_locks(
  zombie_ttl: config['swarm.flush_zombies.zombie_ttl'], # steep:ignore
  lock_scan_size: config['swarm.flush_zombies.zombie_lock_scan_size'] # steep:ignore
)
  swarm.zombie_locks(zombie_ttl:, lock_scan_size:)
end

#zombies_info(zombie_ttl: config['swarm.flush_zombies.zombie_ttl'], lock_scan_size: config['swarm.flush_zombies.zombie_ttl']) ⇒ Hash<Symbol,Set<String>> Also known as: zombies

Returns Format: { zombie_hosts: <Set>, zombie_acquirers: <Set>, zombie_locks: <Set> }.

Returns:

  • (Hash<Symbol,Set<String>>) —

    Format: { zombie_hosts: <Set>, zombie_acquirers: <Set>, zombie_locks: <Set> }

Since:

  • 1.9.0



162
163
164
165
166
167
# File 'lib/redis_queued_locks/client.rb', line 162

def zombies_info(
  zombie_ttl: config['swarm.flush_zombies.zombie_ttl'], # steep:ignore
  lock_scan_size: config['swarm.flush_zombies.zombie_ttl'] # steep:ignore
)
  swarm.zombies_info(zombie_ttl:, lock_scan_size:)
end