From 47f8c59e4a71f5725bea9386e3485c62dad7dbf9 Mon Sep 17 00:00:00 2001 From: Jens Green Olander Date: Fri, 22 Jan 2021 15:12:36 +0100 Subject: [PATCH] Add logging for cluster retries logic --- src/main/java/redis/clients/jedis/JedisClusterCommand.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/redis/clients/jedis/JedisClusterCommand.java b/src/main/java/redis/clients/jedis/JedisClusterCommand.java index 0aa1055df4..6226d0588c 100644 --- a/src/main/java/redis/clients/jedis/JedisClusterCommand.java +++ b/src/main/java/redis/clients/jedis/JedisClusterCommand.java @@ -1,5 +1,7 @@ package redis.clients.jedis; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import redis.clients.jedis.exceptions.JedisAskDataException; import redis.clients.jedis.exceptions.JedisClusterMaxAttemptsException; import redis.clients.jedis.exceptions.JedisClusterOperationException; @@ -11,6 +13,8 @@ public abstract class JedisClusterCommand { + private static final Logger log = LoggerFactory.getLogger(JedisClusterCommand.class); + private final JedisClusterConnectionHandler connectionHandler; private final int maxAttempts; @@ -95,6 +99,7 @@ private T runWithRetries(final int slot, int attempts, boolean tryRandomNode, Je } } else { if (tryRandomNode) { + log.debug("Trying to connect to random node"); connection = connectionHandler.getConnection(); } else { connection = connectionHandler.getConnectionFromSlot(slot); @@ -106,6 +111,7 @@ private T runWithRetries(final int slot, int attempts, boolean tryRandomNode, Je } catch (JedisNoReachableClusterNodeException jnrcne) { throw jnrcne; } catch (JedisConnectionException jce) { + log.warn("Got retryable connection exception ({} attempts left)", attempts, jce); // release current connection before recursion releaseConnection(connection); connection = null; @@ -121,6 +127,7 @@ private T runWithRetries(final int slot, int attempts, boolean tryRandomNode, Je return runWithRetries(slot, attempts - 1, tryRandomNode, redirect); } catch (JedisRedirectionException jre) { + log.debug("Redirected by server to {}", jre.getTargetNode()); // if MOVED redirection occurred, if (jre instanceof JedisMovedDataException) { // it rebuilds cluster's slot cache recommended by Redis cluster specification