Browse Source

add debug logging for locks, only log ifDebugEnabled

tags/2.0.1
Jonathan Cobb 4 years ago
parent
commit
f12336af96
1 changed files with 6 additions and 6 deletions
  1. +6
    -6
      wizard-server/src/main/java/org/cobbzilla/wizard/cache/redis/RedisService.java

+ 6
- 6
wizard-server/src/main/java/org/cobbzilla/wizard/cache/redis/RedisService.java View File

@@ -73,7 +73,7 @@ public class RedisService {
} }


public void reconnect () { public void reconnect () {
log.debug("marking redis for reconnection...");
if (log.isDebugEnabled()) log.debug("marking redis for reconnection...");
synchronized (redis) { synchronized (redis) {
if (redis.get() != null) { if (redis.get() != null) {
try { redis.get().disconnect(); } catch (Exception e) { try { redis.get().disconnect(); } catch (Exception e) {
@@ -87,7 +87,7 @@ public class RedisService {
private Jedis getRedis () { private Jedis getRedis () {
synchronized (redis) { synchronized (redis) {
if (redis.get() == null) { if (redis.get() == null) {
log.debug("connecting to redis...");
if (log.isDebugEnabled()) log.debug("connecting to redis...");
redis.set(newJedis()); redis.set(newJedis());
} }
} }
@@ -220,21 +220,21 @@ public class RedisService {
} }


public String lock(String key, long lockTimeout, long deadlockTimeout) { public String lock(String key, long lockTimeout, long deadlockTimeout) {
log.debug("lock("+key+") starting");
if (log.isDebugEnabled()) log.debug("lock("+key+") starting");
key = key + LOCK_SUFFIX; key = key + LOCK_SUFFIX;
final String uuid = UUID.randomUUID().toString(); final String uuid = UUID.randomUUID().toString();
String lockVal = get(key); String lockVal = get(key);
final long start = now(); final long start = now();
while ((lockVal == null || !lockVal.equals(uuid)) && (now() - start < lockTimeout)) { while ((lockVal == null || !lockVal.equals(uuid)) && (now() - start < lockTimeout)) {
set(key, uuid, NX, EX, deadlockTimeout/1000); set(key, uuid, NX, EX, deadlockTimeout/1000);
log.debug("lock("+key+") locked with uuid="+uuid);
if (log.isDebugEnabled()) log.debug("lock("+key+") locked with uuid="+uuid);
lockVal = get(key); lockVal = get(key);
log.debug("lock("+key+") after locking with uuid="+uuid+", lockVal="+lockVal);
if (log.isDebugEnabled()) log.debug("lock("+key+") after locking with uuid="+uuid+", lockVal="+lockVal);
} }
if (lockVal == null || !lockVal.equals(uuid)) { if (lockVal == null || !lockVal.equals(uuid)) {
return die("lock: timeout locking "+key); return die("lock: timeout locking "+key);
} }
log.debug("lock: LOCKED "+key+" = "+lockVal);
if (log.isDebugEnabled()) log.debug("lock: LOCKED "+key+" = "+lockVal);
return uuid; return uuid;
} }




Loading…
Cancel
Save