redis_queued_locks 0.0.27 → 0.0.28

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9d7bd4d48e34f520e1e7675030a15a346eca0f89429b500b7937ef36cf8107b
4
- data.tar.gz: 7c331e2a5d728a78ce8009bc6d1e97621bab61ad336683e45b52063f2fff1715
3
+ metadata.gz: 5de2915b0828a1c82327dd301b41388cc649b2b922ca18f98cde7e8607753b28
4
+ data.tar.gz: da86f22a9ed5a834467ae80d9596c9efb0be1e645546c5b32a8f5d5b1dcec294
5
5
  SHA512:
6
- metadata.gz: 33491d78f0a847f90ed27792ae3edd90388d78fb4098cd6eae00b85ea13c5353523f252f1cf83e01918bce502b3ad5735825e5f642122b0a15f6d301df12f5f1
7
- data.tar.gz: a18017f9c1bc2559fbd6c723ce1fccc99c7041f6952e535dba31e14a5029abf43c215c6abcd0aaf514d4d670614882255e2b356c3c214a83b77265a826fe16e0
6
+ metadata.gz: 1f3a60c00b200f9e474ad0471e8e59541786f6e035df4c4d93d553eb93456fc99f0743970d3154fa8d3878a4e67b03d8d2ae2c16b71336b8d277f886dd4821e4
7
+ data.tar.gz: 1b52f00d36d568dce68b14caa0cbfb0e1ec793a7eec9adeb5bbca3c042b8bd224cec5f74488c4f0b34de0b302ec98392584a07e21bd02f106a370f3341ef3a35
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.0.28] - 2024-03-21
4
+ ### Added
5
+ - Logging: added `acq_id` to every log message;
6
+ - Logging: updated documentation;
7
+
3
8
  ## [0.0.27] - 2024-03-21
4
9
  ### Changed
5
10
  - Better acquier position accuracy: acquier position in lock queue
data/README.md CHANGED
@@ -139,15 +139,18 @@ clinet = RedisQueuedLocks::Client.new(redis_client) do |config|
139
139
  # - the logger object;
140
140
  # - should implement `debug(progname = nil, &block)` (minimal requirement) or be an instance of Ruby's `::Logger` class/subclass;
141
141
  # - at this moment the only debug logs are realised in 3 cases:
142
- # - start of lock obtaining: "[redis_queud_locks.start_lock_obtaining] lock_key => 'rql:lock:your_lock'"
143
- # - finish of the lock obtaining: "[redis_queued_locks.lock_obtained] lock_key => 'rql:lock:your_lock' acq_time => 123.456 (ms)"
144
- # - start of the lock expiration after `yield`: "[redis_queud_locks.expire_lock] lock_key => 'rql:lock:your_lock'"
142
+ # - start of lock obtaining: "[redis_queud_locks.start_lock_obtaining] lock_key => 'rql:lock:your_lock' acq_id => 'rql:acq:54307/3620/3640/3540/c1799ede93'"
143
+ # - finish of the lock obtaining: "[redis_queued_locks.lock_obtained] lock_key => 'rql:lock:your_lock' acq_id => 'rql:acq:54307/3620/3640/3540/c1799ede93' acq_time => 123.456 (ms)"
144
+ # - start of the lock expiration after `yield`: "[redis_queud_locks.expire_lock] lock_key => 'rql:lock:your_lock' acq_id => 'rql:acq:54307/3620/3640/3540/c1799ede93'"
145
145
  # - by default uses VoidLogger that does nothing;
146
146
  config.logger = RedisQueuedLocks::Logging::VoidLogger
147
147
 
148
148
  # (default: false)
149
- # - should be logged the each try of lock acquiring (a lot of logs can be generated depending on your retry configurations);
150
- # - if logger is not cofnigured this option does not lead to any effect;
149
+ # - should be logged the each internal try-retry lock acquire (a lot of logs can be generated depending on your retry configurations);
150
+ # - it adds 2 cases to the log in addition to the existing 3:
151
+ # - start of a try: "[redis_queud_locks.try_lock_start] lock_key => 'rql:lock:your_lock' acq_id => 'rql:acq:54307/3620/3640/3540/c1799ede93'"
152
+ # - redis connection is feteched from the pool after "start of a try": "[redis_queued_locks.try_lock_rconn_fetched] lock_key => 'rql:lock:your_lock' acq_id => 'rql:acq:54307/3620/3640/3540/c1799ede93'"
153
+ # - if logger is not configured this option does not lead to any effect;
151
154
  config.log_lock_try = false
152
155
  end
153
156
  ```
@@ -63,7 +63,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::TryToLock
63
63
  rconn.multi(watch: [lock_key]) do |transact|
64
64
  # Fast-Step X0: fail-fast check
65
65
  if fail_fast && rconn.call('HGET', lock_key, 'acq_id')
66
- # Fast-Step X1: is lock already obtained. fail fast - no try.
66
+ # Fast-Step X1: is lock already obtained. fail fast leads to "no try".
67
67
  inter_result = :fail_fast_no_try
68
68
  else
69
69
  # Step 1: add an acquier to the lock acquirement queue
@@ -9,6 +9,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::YieldWithExpire
9
9
  # @param redis [RedisClient] Redis connection manager.
10
10
  # @param logger [::Logger,#debug] Logger object.
11
11
  # @param lock_key [String] Lock key to be expired.
12
+ # @param acquier_id [String] Acquier identifier.
12
13
  # @param timed [Boolean] Should the lock be wrapped by Tiemlout with with lock's ttl
13
14
  # @param ttl_shift [Float] Lock's TTL shifting. Should affect block's ttl. In millisecodns.
14
15
  # @param ttl [Integer,NilClass] Lock's time to live (in ms). Nil means "without timeout".
@@ -17,7 +18,7 @@ module RedisQueuedLocks::Acquier::AcquireLock::YieldWithExpire
17
18
  #
18
19
  # @api private
19
20
  # @since 0.1.0
20
- def yield_with_expire(redis, logger, lock_key, timed, ttl_shift, ttl, &block)
21
+ def yield_with_expire(redis, logger, lock_key, acquier_id, timed, ttl_shift, ttl, &block)
21
22
  if block_given?
22
23
  if timed && ttl != nil
23
24
  timeout = ((ttl - ttl_shift) / 1000.0).yield_self { |time| (time < 0) ? 0.0 : time }
@@ -28,7 +29,11 @@ module RedisQueuedLocks::Acquier::AcquireLock::YieldWithExpire
28
29
  end
29
30
  ensure
30
31
  run_non_critical do
31
- logger.debug("[redis_queued_locks.expire_lock] lock_key => '#{lock_key}'")
32
+ logger.debug(
33
+ "[redis_queued_locks.expire_lock] " \
34
+ "lock_key => '#{lock_key}' " \
35
+ "acq_id => '#{acquier_id}'"
36
+ )
32
37
  end
33
38
  redis.call('EXPIRE', lock_key, '0')
34
39
  end
@@ -176,7 +176,7 @@ module RedisQueuedLocks::Acquier::AcquireLock
176
176
  logger.debug(
177
177
  "[redis_queued_locks.lock_obtained] " \
178
178
  "lock_key => '#{result[:lock_key]}' " \
179
- "acq_id: => '#{acquier_id}' " \
179
+ "acq_id => '#{acquier_id}' " \
180
180
  "acq_time => #{acq_time} (ms)"
181
181
  )
182
182
  end
@@ -255,7 +255,7 @@ module RedisQueuedLocks::Acquier::AcquireLock
255
255
  begin
256
256
  yield_time = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
257
257
  ttl_shift = ((yield_time - acq_process[:acq_end_time]) * 1000).ceil(2)
258
- yield_with_expire(redis, logger, lock_key, timed, ttl_shift, ttl, &block)
258
+ yield_with_expire(redis, logger, lock_key, acquier_id, timed, ttl_shift, ttl, &block)
259
259
  ensure
260
260
  acq_process[:rel_time] = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
261
261
  acq_process[:hold_time] = (
@@ -5,6 +5,6 @@ module RedisQueuedLocks
5
5
  #
6
6
  # @api public
7
7
  # @since 0.0.1
8
- # @version 0.0.27
9
- VERSION = '0.0.27'
8
+ # @version 0.0.28
9
+ VERSION = '0.0.28'
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_queued_locks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.27
4
+ version: 0.0.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Ibragimov