Skip to content

Commit ddcec73

Browse files
committed
- remove failback candidate
- fix failing tests
1 parent ca3378d commit ddcec73

File tree

2 files changed

+20
-41
lines changed

2 files changed

+20
-41
lines changed

src/main/java/redis/clients/jedis/providers/MultiClusterPooledConnectionProvider.java

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ private void handleStatusChange(HealthStatusChangeEvent eventArgs) {
280280
clusterWithHealthChange.setHealthStatus(newStatus);
281281

282282
if (newStatus.isHealthy()) {
283-
if (clusterWithHealthChange.isFailbackSupported() && clusterWithHealthChange.isFailbackCandidate()
284-
&& activeCluster != clusterWithHealthChange) {
283+
if (clusterWithHealthChange.isFailbackSupported() && activeCluster != clusterWithHealthChange) {
285284
// lets check if weighted switching is possible
286285
Map.Entry<Endpoint, Cluster> failbackCluster = findWeightedHealthyClusterToIterate();
287286
if (failbackCluster == clusterWithHealthChange
@@ -307,9 +306,6 @@ public Endpoint iterateActiveCluster() {
307306
Cluster cluster = clusterToIterate.getValue();
308307
boolean changed = setActiveCluster(cluster, false);
309308
if (!changed) return null;
310-
if (cluster.isFailbackSupported()) {
311-
cluster.setFailbackCandidate(false);
312-
}
313309
return clusterToIterate.getKey();
314310
}
315311

@@ -471,9 +467,7 @@ public static class Cluster {
471467
// it starts its life with the assumption of being healthy
472468
private HealthStatus healthStatus = HealthStatus.HEALTHY;
473469
private MultiClusterClientConfig multiClusterClientConfig;
474-
// it starts its life as a failback candidate,
475-
// this changes under the condition that cluster failover to another and failback is not supported by client
476-
private boolean failbackCandidate = true;
470+
private boolean disabled = false;
477471

478472
public Cluster(ConnectionPool connectionPool, Retry retry, CircuitBreaker circuitBreaker, float weight,
479473
MultiClusterClientConfig multiClusterClientConfig) {
@@ -520,26 +514,19 @@ public boolean isCBForcedOpen() {
520514
}
521515

522516
public boolean isHealthy() {
523-
return healthStatus.isHealthy() && !isCBForcedOpen();
517+
return healthStatus.isHealthy() && !isCBForcedOpen() && !disabled;
524518
}
525519

526-
/**
527-
* Whether this cluster is a failback candidate Cluster starts its life as a failback candidate, this changes
528-
* under the condition that cluster failover to another and failback is not supported by client
529-
*/
530-
public boolean isFailbackCandidate() {
531-
return failbackCandidate;
520+
public boolean retryOnFailover() {
521+
return multiClusterClientConfig.isRetryOnFailover();
532522
}
533523

534-
/**
535-
* Sets this cluster as a failback candidate
536-
*/
537-
public void setFailbackCandidate(boolean failbackCandidate) {
538-
this.failbackCandidate = failbackCandidate;
524+
public boolean isDisabled() {
525+
return disabled;
539526
}
540527

541-
public boolean retryOnFailover() {
542-
return multiClusterClientConfig.isRetryOnFailover();
528+
public void setDisabled(boolean disabled) {
529+
this.disabled = disabled;
543530
}
544531

545532
/**
@@ -553,8 +540,7 @@ public boolean isFailbackSupported() {
553540
public String toString() {
554541
return circuitBreaker.getName() + "{" + "connectionPool=" + connectionPool + ", retry=" + retry
555542
+ ", circuitBreaker=" + circuitBreaker + ", weight=" + weight + ", healthStatus=" + healthStatus
556-
+ ", multiClusterClientConfig=" + multiClusterClientConfig + ", failbackCandidate=" + failbackCandidate
557-
+ '}';
543+
+ ", multiClusterClientConfig=" + multiClusterClientConfig + '}';
558544
}
559545
}
560546

src/test/java/redis/clients/jedis/providers/MultiClusterPooledConnectionProviderTest.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import redis.clients.jedis.exceptions.JedisValidationException;
1010
import redis.clients.jedis.mcf.Endpoint;
1111

12-
1312
import java.util.concurrent.atomic.AtomicBoolean;
1413

1514
import static org.junit.jupiter.api.Assertions.*;
@@ -36,7 +35,7 @@ public void setUp() {
3635
.weight(0.3f).build();
3736

3837
provider = new MultiClusterPooledConnectionProvider(
39-
new MultiClusterClientConfig.Builder(clusterConfigs).failbackSupported(false).build());
38+
new MultiClusterClientConfig.Builder(clusterConfigs).build());
4039
}
4140

4241
@Test
@@ -56,37 +55,31 @@ public void testCircuitBreakerForcedTransitions() {
5655
}
5756

5857
@Test
59-
public void testIncrementActiveMultiClusterIndex() {
58+
public void testIterateActiveCluster() {
6059
Endpoint e2 = provider.iterateActiveCluster();
6160
assertEquals(endpointStandalone1.getHostAndPort(), e2);
6261
}
6362

6463
@Test
65-
public void testIncrementActiveMultiClusterIndexOutOfRange() {
64+
public void testIterateActiveClusterOutOfRange() {
6665
provider.setActiveCluster(endpointStandalone0.getHostAndPort());
66+
provider.getCluster().setDisabled(true);
6767

6868
Endpoint e2 = provider.iterateActiveCluster();
69+
provider.getCluster().setDisabled(true);
70+
6971
assertEquals(endpointStandalone1.getHostAndPort(), e2);
7072

7173
assertThrows(JedisConnectionException.class, () -> provider.iterateActiveCluster()); // Should throw an
7274
// exception
7375
}
7476

7577
@Test
76-
public void testIsLastClusterCircuitBreakerForcedOpen() {
78+
public void testCanIterateOnceMore() {
7779
provider.setActiveCluster(endpointStandalone0.getHostAndPort());
78-
79-
try {
80-
provider.iterateActiveCluster();
81-
} catch (Exception e) {
82-
}
83-
84-
// This should set the isLastClusterCircuitBreakerForcedOpen to true
85-
try {
86-
provider.iterateActiveCluster();
87-
} catch (Exception e) {
88-
}
89-
80+
provider.getCluster().setDisabled(true);
81+
provider.iterateActiveCluster();
82+
9083
assertFalse(provider.canIterateOnceMore());
9184
}
9285

0 commit comments

Comments
 (0)