Skip to content

Commit

Permalink
fix: threadlock logs are debug (#670)
Browse files Browse the repository at this point in the history
Co-authored-by: Aleksandr Chikovani <[email protected]>
  • Loading branch information
justrp and Aleksandr Chikovani committed Feb 4, 2025
1 parent e33e307 commit 2e49373
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public LockService(RedissonClient redis, @Nullable String prefix) {
public Lock lock(String key) {
String id = id(key);
long owner = ThreadLocalRandom.current().nextLong();
log.info("Thread {} acquires a lock to the resource {} with owner {}", Thread.currentThread().getName(), id, owner);
log.debug("Thread {} acquires a lock to the resource {} with owner {}", Thread.currentThread().getName(), id, owner);
long ttl = tryLock(id, owner);
long interval = WAIT_MIN;

Expand Down Expand Up @@ -95,11 +95,11 @@ private long tryLock(String id, long owner) {
local time = redis.call('time')
local now = time[1] * 1000000 + time[2]
local deadline = tonumber(redis.call('hget', KEYS[1], 'deadline'))
if (deadline ~= nil and now < deadline) then
return deadline - now
end
redis.call('hset', KEYS[1], 'owner', ARGV[1], 'deadline', now + ARGV[2])
return 0
""", RScript.ReturnType.INTEGER, List.of(id), String.valueOf(owner), String.valueOf(PERIOD));
Expand All @@ -110,7 +110,7 @@ private void unlock(String id, long owner) {
if (!ok) {
log.error("Lock service failed to unlock: {}", id);
} else {
log.info("Thread {} releases a lock to the resource {} with owner {}", Thread.currentThread().getName(), id, owner);
log.debug("Thread {} releases a lock to the resource {} with owner {}", Thread.currentThread().getName(), id, owner);
}
}

Expand All @@ -119,12 +119,12 @@ private boolean tryUnlock(String id, long owner) {
return script.eval(RScript.Mode.READ_WRITE,
"""
local owner = redis.call('hget', KEYS[1], 'owner')
if (owner == ARGV[1]) then
redis.call('del', KEYS[1])
return true
end
return false
""", RScript.ReturnType.BOOLEAN, List.of(id), String.valueOf(owner));
} catch (Throwable e) {
Expand All @@ -141,4 +141,4 @@ public interface Lock extends AutoCloseable {
@Override
void close();
}
}
}

0 comments on commit 2e49373

Please sign in to comment.