From 1d8278ac0652f24cf699ff3f3905604ca9a45765 Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Tue, 9 Apr 2024 09:30:24 +0300 Subject: [PATCH] Fixed - MASTER nodes isn't used in readMode = MASTER_SLAVE. #5723 --- .../cluster/ClusterConnectionManager.java | 4 ++-- .../redisson/connection/MasterSlaveEntry.java | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java b/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java index deaaf05b9..46800ca64 100644 --- a/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java +++ b/redisson/src/main/java/org/redisson/cluster/ClusterConnectionManager.java @@ -531,7 +531,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { if (v) { log.info("slave: {} is up for slot ranges: {}", uri, currentPart.getSlotRanges()); currentPart.removeFailedSlaveAddress(uri); - return entry.excludeMasterFromSlaves(uri); + entry.excludeMasterFromSlaves(uri); } return v; }); @@ -578,7 +578,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager { if (v) { currentPart.addSlaveAddress(uri); log.info("slave: {} added for slot ranges: {}", uri, currentPart.getSlotRanges()); - return entry.excludeMasterFromSlaves(uri); + entry.excludeMasterFromSlaves(uri); } return v; }); diff --git a/redisson/src/main/java/org/redisson/connection/MasterSlaveEntry.java b/redisson/src/main/java/org/redisson/connection/MasterSlaveEntry.java index 6d9d894e2..64f0bd28d 100644 --- a/redisson/src/main/java/org/redisson/connection/MasterSlaveEntry.java +++ b/redisson/src/main/java/org/redisson/connection/MasterSlaveEntry.java @@ -106,7 +106,8 @@ public class MasterSlaveEntry { } private void useMasterAsSlave() { - if (hasNoSlaves()) { + if (hasNoSlaves() + || config.getReadMode() == ReadMode.MASTER_SLAVE) { addSlaveEntry(masterEntry); } else { removeSlaveEntry(masterEntry); @@ -434,7 +435,8 @@ public class MasterSlaveEntry { CompletableFuture f = unfreezeAsync(entry, freezeReason); return f.thenApply(r -> { if (r) { - return excludeMasterFromSlaves(entry.getClient().getAddr()); + excludeMasterFromSlaves(entry.getClient().getAddr()); + return r; } return r; }); @@ -445,7 +447,8 @@ public class MasterSlaveEntry { CompletableFuture f = unfreezeAsync(address, freezeReason); return f.thenApply(r -> { if (r) { - return excludeMasterFromSlaves(address); + excludeMasterFromSlaves(address); + return r; } return r; }); @@ -453,7 +456,8 @@ public class MasterSlaveEntry { public boolean excludeMasterFromSlaves(RedisURI address) { InetSocketAddress addr = masterEntry.getClient().getAddr(); - if (address.equals(addr)) { + if (address.equals(addr) + || config.getReadMode() == ReadMode.MASTER_SLAVE) { return false; } @@ -464,7 +468,8 @@ public class MasterSlaveEntry { public boolean excludeMasterFromSlaves(InetSocketAddress address) { InetSocketAddress addr = masterEntry.getClient().getAddr(); - if (config.isSlaveNotUsed() || addr.equals(address)) { + if (config.isSlaveNotUsed() || addr.equals(address) + || config.getReadMode() == ReadMode.MASTER_SLAVE) { return false; } @@ -488,7 +493,8 @@ public class MasterSlaveEntry { CompletableFuture f = unfreezeAsync(address, freezeReason); return f.thenApply(r -> { if (r) { - return excludeMasterFromSlaves(address); + excludeMasterFromSlaves(address); + return r; } return r; });