diff --git a/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java b/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java index a781a1f66..b0e0218e3 100644 --- a/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java +++ b/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java @@ -430,7 +430,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { private void checkClusterState(ClusterServersConfig cfg, Iterator iterator, AtomicReference lastException, List allNodes) { if (!iterator.hasNext()) { if (lastException.get() != null) { - log.error("Can't update cluster state using nodes: {}", allNodes, lastException.getAndSet(null)); + log.error("Can't update cluster state using nodes: {}. A new attempt will be made.", allNodes, lastException.getAndSet(null)); } scheduleClusterChangeCheck(cfg); return; @@ -455,11 +455,9 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { private void updateClusterState(ClusterServersConfig cfg, RedisConnection connection, Iterator iterator, RedisURI uri, AtomicReference lastException, List allNodes) { - RFuture> future = connection.async(cfg.getRetryAttempts(), cfg.getRetryInterval(), cfg.getTimeout(), - StringCodec.INSTANCE, clusterNodesCommand); + RFuture> future = connection.async(StringCodec.INSTANCE, clusterNodesCommand); future.whenComplete((nodes, e) -> { if (e != null) { - log.error("Unable to execute {}", clusterNodesCommand, e); if (!lastException.compareAndSet(null, e)) { lastException.get().addSuppressed(e); } diff --git a/redisson/src/main/java/org/redisson/connection/ReplicatedConnectionManager.java b/redisson/src/main/java/org/redisson/connection/ReplicatedConnectionManager.java index 6b1d5e4a0..de6a0ad76 100644 --- a/redisson/src/main/java/org/redisson/connection/ReplicatedConnectionManager.java +++ b/redisson/src/main/java/org/redisson/connection/ReplicatedConnectionManager.java @@ -237,7 +237,7 @@ public class ReplicatedConnectionManager extends MasterSlaveConnectionManager { }) .whenComplete((r, ex) -> { if (ex != null) { - log.error(ex.getMessage(), ex); + log.error("Unable to update node {} status. A new attempt will be made.", uri, ex); } }) .toCompletableFuture(); diff --git a/redisson/src/main/java/org/redisson/connection/SentinelConnectionManager.java b/redisson/src/main/java/org/redisson/connection/SentinelConnectionManager.java index 43300e1fd..1c694be3f 100755 --- a/redisson/src/main/java/org/redisson/connection/SentinelConnectionManager.java +++ b/redisson/src/main/java/org/redisson/connection/SentinelConnectionManager.java @@ -206,7 +206,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager { super.doConnect(uri2hostname::get); - scheduleChangeCheck(cfg, null); + scheduleChangeCheck(cfg, null, null); } private static boolean isHostname(String host) { @@ -310,28 +310,30 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager { return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); } - private void scheduleChangeCheck(SentinelServersConfig cfg, Iterator iterator) { + private void scheduleChangeCheck(SentinelServersConfig cfg, Iterator iterator, AtomicReference lastException) { + AtomicReference exceptionReference = Optional.ofNullable(lastException) + .orElseGet(() -> new AtomicReference<>()); monitorFuture = serviceManager.newTimeout(t -> { - AtomicReference lastException = new AtomicReference(); - Iterator iter = iterator; - if (iter == null) { - // Shuffle the list so all clients don't prefer the same sentinel - List clients = new ArrayList<>(sentinels.values()); - Collections.shuffle(clients); - iter = clients.iterator(); - } - checkState(cfg, iter, lastException); + Iterator iter = Optional.ofNullable(iterator) + .orElseGet(() -> { + // Shuffle the list so all clients don't prefer the same sentinel + List clients = new ArrayList<>(sentinels.values()); + Collections.shuffle(clients); + return clients.iterator(); + }); + + checkState(cfg, iter, exceptionReference); }, cfg.getScanInterval(), TimeUnit.MILLISECONDS); } private void checkState(SentinelServersConfig cfg, Iterator iterator, AtomicReference lastException) { if (!iterator.hasNext()) { if (lastException.get() != null) { - log.error("Can't update cluster state", lastException.get()); + log.error("Can't update cluster state. A new attempt will be made.", lastException.getAndSet(null)); } disconnectedSentinels.clear(); CompletableFuture f = performSentinelDNSCheck(); - f.whenComplete((r, e) -> scheduleChangeCheck(cfg, null)); + f.whenComplete((r, e) -> scheduleChangeCheck(cfg, null, null)); return; } if (serviceManager.isShuttingDown()) { @@ -347,17 +349,20 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager { CompletionStage connectionFuture = connectToNode(NodeType.SENTINEL, cfg, addr, hostname); connectionFuture.whenComplete((connection, e) -> { if (e != null) { - lastException.set(e); + if (!lastException.compareAndSet(null, e)) { + lastException.get().addSuppressed(e); + } checkState(cfg, iterator, lastException); return; } - updateState(cfg, connection, iterator); + updateState(cfg, connection, iterator, lastException); }); } - private void updateState(SentinelServersConfig cfg, RedisConnection connection, Iterator iterator) { + private void updateState(SentinelServersConfig cfg, RedisConnection connection, Iterator iterator, + AtomicReference lastException) { List> futures = new ArrayList<>(); CompletionStage masterFuture = checkMasterChange(cfg, connection); futures.add(masterFuture.toCompletableFuture()); @@ -373,14 +378,14 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager { CompletableFuture future = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); future.whenComplete((r, e) -> { if (e != null) { - log.error("Can't execute SENTINEL commands on {}", connection.getRedisClient().getAddr(), e); + if (!lastException.compareAndSet(null, e)) { + lastException.get().addSuppressed(e); + } + scheduleChangeCheck(cfg, iterator, lastException); + return; } - if (e != null) { - scheduleChangeCheck(cfg, iterator); - } else { - scheduleChangeCheck(cfg, null); - } + scheduleChangeCheck(cfg, null, null); }); }