Module: RedisQueuedLocks::Acquirer::ReleaseLocksOf Private

Extended by:
Utilities
Defined in:
lib/redis_queued_locks/acquirer/release_locks_of.rb

Overview

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

Since:

  • 1.14.0

Constant Summary

Constants included from Utilities

Utilities::RACTOR_LIVENESS_PATTERN, Utilities::RACTOR_STATUS_PATTERN, Utilities::RUBY_OVER_4

Class Method Summary collapse

Methods included from Utilities

clock_gettime, ractor_alive?, ractor_status, ruby_over_4?, run_non_critical, thread_state

Class Method Details

.release_locks_of(refused_host_id, refused_acquirer_id, redis, 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) ⇒ Hash<Symbol,Any>

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.

Release all queues and locks that belong to the given host and its associated acquirer.

rubocop:disable Metrics/MethodLength

Parameters:

  • refused_host_id (String) —

    A host whose locks and queues should be released.

  • refused_acquirer_id (String) —

    An acquirer (of the passed host) whose locks and queues should be released.

  • redis (RedisClient) —

    Redis connection client.

  • lock_scan_size (Integer) —

    The number of lock keys that should be released in a time. Affects the RubyVM memmory (cuz each found lock will be temporary stored in memory for subsequent removal from redis in one query at a time).

  • queue_scan_size (Integer) —

    The number of lock queues that should be scanned removing an acquirer from them (at a time).

  • logger (::Logger, #debug) —
    • Logger object used from configuration layer (see config);
    • See RedisQueuedLocks::Logging::VoidLogger for example;
  • instrumenter (#notify) —

    See RedisQueuedLocks::Instrument::ActiveSupport for example.

  • instrument (NilClass, Any) —
    • Custom instrumentation data wich will be passed to the instrumenter's payload with :instrument key;
  • 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>;
  • 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;
  • 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);
  • log_sample_this (Boolean) —
    • marks the method that everything should be logged despite the enabled log sampling;
    • makes sense when log sampling is enabled;
  • 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>;
  • 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;
  • 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);
  • instr_sample_this (Boolean) —
    • marks the method that everything should be instrumneted despite the enabled instrumentation sampling;
    • makes sense when instrumentation sampling is enabled;

Returns:

  • (Hash<Symbol,Any>) —

    Format: { ok: true, result: { rel_key_cnt: Integer, tch_queue_cnt: Integer, rel_time: Numeric } }

Since:

  • 1.14.0

Version:

  • 1.15.0



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/redis_queued_locks/acquirer/release_locks_of.rb', line 89

def release_locks_of(
  refused_host_id,
  refused_acquirer_id,
  redis,
  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
) # TODO: move from SCAN to indexes :thinking:
  rel_start_time = clock_gettime

  # steep:ignore:start
  fully_release_locks_of(
    refused_host_id,
    refused_acquirer_id,
    redis,
    lock_scan_size,
    queue_scan_size
  ) => { ok:, result: }
  # steep:ignore:end

  # @type var ok: bool
  # @type var result: Hash[Symbol,Integer]

  time_at = Time.now.to_f
  rel_end_time = clock_gettime
  rel_time = ((rel_end_time - rel_start_time) / 1_000.0).ceil(2)

  instr_sampled = RedisQueuedLocks::Instrument.should_instrument?(
    instr_sampling_enabled,
    instr_sample_this,
    instr_sampling_percent,
    instr_sampler
  )

  run_non_critical do
    instrumenter.notify('redis_queued_locks.release_locks_of', {
      at: time_at,
      hst_id: refused_host_id,
      acq_id: refused_acquirer_id,
      rel_time: rel_time,
      rel_key_cnt: result[:rel_key_cnt],
      tch_queue_cnt: result[:tch_queue_cnt]
    })
  end if instr_sampled

  {
    ok: true,
    result: {
      rel_key_cnt: result[:rel_key_cnt],
      tch_queue_cnt: result[:tch_queue_cnt],
      rel_time: rel_time
    }
  }
end