Module: RedisQueuedLocks::Acquirer::ReleaseAllLocks Private

Extended by:
Utilities
Defined in:
lib/redis_queued_locks/acquirer/release_all_locks.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.0.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_all_locks(redis, 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) ⇒ 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 locks:

    1. clear all lock queus: drop them all from Redis database by the lock queue pattern;
    1. delete all locks: drop lock keys from Redis by the lock key pattern;

Parameters:

  • redis (RedisClient) —

    Redis connection client.

  • batch_size (Integer) —

    The number of lock keys that should be released in 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: Hash<Symbol,Numeric> }

Since:

  • 1.0.0

Version:

  • 1.14.0



75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
# File 'lib/redis_queued_locks/acquirer/release_all_locks.rb', line 75

def release_all_locks(
  redis,
  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
)
  rel_start_time = clock_gettime
  fully_release_all_locks(redis, batch_size) => { ok:, result: } # steep:ignore

  # @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.explicit_all_locks_release', {
      at: time_at,
      rel_time: rel_time,
      rel_key_cnt: result[:rel_key_cnt]
    })
  end if instr_sampled

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