Skip to content

Commit

Permalink
Added doc and renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 committed Dec 31, 2023
1 parent 2669834 commit 1b65cf3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 29 deletions.
16 changes: 12 additions & 4 deletions docs/failover.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ Jedis uses the following retry settings:
| Max retry attempts | 3 | Maximum number of retry attempts (including the initial call) |
| Retry wait duration | 500 ms | Number of milliseconds to wait between retry attempts |
| Wait duration backoff multiplier | 2 | Exponential backoff factor multiplied against wait duration between retries. For example, with a wait duration of 1 second and a multiplier of 2, the retries would occur after 1s, 2s, 4s, 8s, 16s, and so on. |
| Retry included exception list | `JedisConnectionException` | A list of `Throwable` classes that count as failures and should be retried. |
| Retry ignored exception list | Empty list | A list of `Throwable` classes to explicitly ignore for the purposes of retry. |
| Retry included exception list | [JedisConnectionException] | A list of Throwable classes that count as failures and should be retried. |
| Retry ignored exception list | null | A list of Throwable classes to explicitly ignore for the purposes of retry. |

To disable retry, set `maxRetryAttempts` to 1.

Expand All @@ -116,8 +116,16 @@ Jedis uses the following circuit breaker settings:
| Failure rate threshold | `50.0f` | Percentage of calls within the sliding window that must fail before the circuit breaker transitions to the `OPEN` state. |
| Slow call duration threshold | 60000 ms | Duration threshold above which calls are classified as slow and added to the sliding window. |
| Slow call rate threshold | `100.0f` | Percentage of calls within the sliding window that exceed the slow call duration threshold before circuit breaker transitions to the `OPEN` state. |
| Circuit breaker included exception list | `JedisConnectionException` | A list of `Throwable` classes that count as failures and add to the failure rate. |
| Circuit breaker ignored exception list | Empty list | A list of `Throwable` classes to explicitly ignore for failure rate calculations. | |
| Circuit breaker included exception list | [JedisConnectionException] | A list of Throwable classes that count as failures and add to the failure rate. |
| Circuit breaker ignored exception list | null | A list of Throwable classes to explicitly ignore for failure rate calculations. | |

### Fallback configuration

Jedis uses the following fallback settings:

| Setting | Default value | Description |
|-------------------------|-------------------------------------------------------|----------------------------------------------------|
| Fallback exception list | [CallNotPermittedException, JedisConnectionException] | A list of Throwable classes that trigger fallback. |

### Failover callbacks

Expand Down
25 changes: 13 additions & 12 deletions src/main/java/redis/clients/jedis/MultiClusterClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import io.github.resilience4j.circuitbreaker.CallNotPermittedException;
import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig.SlidingWindowType;
import redis.clients.jedis.exceptions.JedisConnectionException;
import redis.clients.jedis.exceptions.JedisValidationException;

import java.time.Duration;
import java.util.Arrays;
import java.util.List;

import redis.clients.jedis.exceptions.JedisConnectionException;
import redis.clients.jedis.exceptions.JedisValidationException;


/**
* @author Allen Terleto (aterleto)
Expand Down Expand Up @@ -39,7 +40,7 @@ public final class MultiClusterClientConfig {
private static final float CIRCUIT_BREAKER_SLOW_CALL_RATE_THRESHOLD_DEFAULT = 100.0f; // measured as percentage
private static final List<Class> CIRCUIT_BREAKER_INCLUDED_EXCEPTIONS_DEFAULT = Arrays.asList(JedisConnectionException.class);

private static final List<Class<? extends Throwable>> CIRCUIT_BREAKER_FALLBACK_EXCEPTIONS_DEFAULT =
private static final List<Class<? extends Throwable>> FALLBACK_EXCEPTIONS_DEFAULT =
Arrays.asList(CallNotPermittedException.class, JedisConnectionException.class);

private final ClusterConfig[] clusterConfigs;
Expand Down Expand Up @@ -104,7 +105,7 @@ public final class MultiClusterClientConfig {
* failure nor success, even if the exceptions is part of recordExceptions */
private List<Class> circuitBreakerIgnoreExceptionList;

private List<Class<? extends Throwable>> circuitBreakerFallbackExceptionList;
private List<Class<? extends Throwable>> fallbackExceptionList;

public MultiClusterClientConfig(ClusterConfig[] clusterConfigs) {
this.clusterConfigs = clusterConfigs;
Expand Down Expand Up @@ -166,8 +167,8 @@ public SlidingWindowType getCircuitBreakerSlidingWindowType() {
return circuitBreakerSlidingWindowType;
}

public List<Class<? extends Throwable>> getCircuitBreakerFallbackExceptionList() {
return circuitBreakerFallbackExceptionList;
public List<Class<? extends Throwable>> getFallbackExceptionList() {
return fallbackExceptionList;
}

public static class ClusterConfig {
Expand Down Expand Up @@ -216,7 +217,7 @@ public static class Builder {
private float circuitBreakerSlowCallRateThreshold = CIRCUIT_BREAKER_SLOW_CALL_RATE_THRESHOLD_DEFAULT;
private List<Class> circuitBreakerIncludedExceptionList = CIRCUIT_BREAKER_INCLUDED_EXCEPTIONS_DEFAULT;
private List<Class> circuitBreakerIgnoreExceptionList = null;
private List<Class<? extends Throwable>> circuitBreakerFallbackExceptionList = CIRCUIT_BREAKER_FALLBACK_EXCEPTIONS_DEFAULT;
private List<Class<? extends Throwable>> fallbackExceptionList = FALLBACK_EXCEPTIONS_DEFAULT;

public Builder(ClusterConfig[] clusterConfigs) {

Expand Down Expand Up @@ -298,8 +299,8 @@ public Builder circuitBreakerIgnoreExceptionList(List<Class> circuitBreakerIgnor
return this;
}

public Builder circuitBreakerFallbackExceptionList(List<Class<? extends Throwable>> circuitBreakerFallbackExceptionList) {
this.circuitBreakerFallbackExceptionList = circuitBreakerFallbackExceptionList;
public Builder fallbackExceptionList(List<Class<? extends Throwable>> fallbackExceptionList) {
this.fallbackExceptionList = fallbackExceptionList;
return this;
}

Expand Down Expand Up @@ -337,10 +338,10 @@ public MultiClusterClientConfig build() {
config.circuitBreakerIgnoreExceptionList = this.circuitBreakerIgnoreExceptionList;
}

if (this.circuitBreakerFallbackExceptionList != null && !this.circuitBreakerFallbackExceptionList.isEmpty()) {
config.circuitBreakerFallbackExceptionList = this.circuitBreakerFallbackExceptionList;
if (this.fallbackExceptionList != null && !this.fallbackExceptionList.isEmpty()) {
config.fallbackExceptionList = this.fallbackExceptionList;
} else {
config.circuitBreakerFallbackExceptionList = CIRCUIT_BREAKER_FALLBACK_EXCEPTIONS_DEFAULT;
config.fallbackExceptionList = FALLBACK_EXCEPTIONS_DEFAULT;
}

return config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public <T> T executeCommand(CommandObject<T> commandObject) {

supplier.withRetry(cluster.getRetry());
supplier.withCircuitBreaker(cluster.getCircuitBreaker());
supplier.withFallback(provider.getCircuitBreakerFallbackExceptionList(),
e -> this.handleClusterFailover(commandObject, cluster.getCircuitBreaker()));
supplier.withFallback(provider.getFallbackExceptionList(),
e -> this.handleClusterFailover(commandObject, cluster.getCircuitBreaker()));

return supplier.decorate().get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public Connection getConnection() {

supplier.withRetry(cluster.getRetry());
supplier.withCircuitBreaker(cluster.getCircuitBreaker());
supplier.withFallback(provider.getCircuitBreakerFallbackExceptionList(),
e -> this.handleClusterFailover(cluster.getCircuitBreaker()));
supplier.withFallback(provider.getFallbackExceptionList(),
e -> this.handleClusterFailover(cluster.getCircuitBreaker()));

return supplier.decorate().get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@
import io.github.resilience4j.retry.Retry;
import io.github.resilience4j.retry.RetryConfig;
import io.github.resilience4j.retry.RetryRegistry;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import redis.clients.jedis.*;
import redis.clients.jedis.MultiClusterClientConfig.ClusterConfig;
import redis.clients.jedis.exceptions.JedisConnectionException;
import redis.clients.jedis.exceptions.JedisValidationException;
import redis.clients.jedis.util.Pool;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;


/**
* @author Allen Terleto (aterleto)
Expand Down Expand Up @@ -63,7 +66,7 @@ public class MultiClusterPooledConnectionProvider implements ConnectionProvider
*/
private Consumer<String> clusterFailoverPostProcessor;

private List<Class<? extends Throwable>> circuitBreakerFallbackExceptionList;
private List<Class<? extends Throwable>> fallbackExceptionList;

public MultiClusterPooledConnectionProvider(MultiClusterClientConfig multiClusterClientConfig) {

Expand Down Expand Up @@ -132,7 +135,7 @@ public MultiClusterPooledConnectionProvider(MultiClusterClientConfig multiCluste

/// --- ///

this.circuitBreakerFallbackExceptionList = multiClusterClientConfig.getCircuitBreakerFallbackExceptionList();
this.fallbackExceptionList = multiClusterClientConfig.getFallbackExceptionList();
}

/**
Expand Down Expand Up @@ -295,8 +298,8 @@ public void setClusterFailoverPostProcessor(Consumer<String> clusterFailoverPost
this.clusterFailoverPostProcessor = clusterFailoverPostProcessor;
}

public List<Class<? extends Throwable>> getCircuitBreakerFallbackExceptionList() {
return circuitBreakerFallbackExceptionList;
public List<Class<? extends Throwable>> getFallbackExceptionList() {
return fallbackExceptionList;
}

public static class Cluster {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void failoverFromAuthError() {
getClusterConfigs(clientConfig, hostPort_1_2, hostPort_2))
.circuitBreakerSlidingWindowMinCalls(slidingWindowMinCalls)
.circuitBreakerSlidingWindowSize(slidingWindowSize)
.circuitBreakerFallbackExceptionList(Arrays.asList(JedisAccessControlException.class));
.fallbackExceptionList(Arrays.asList(JedisAccessControlException.class));

RedisFailoverReporter failoverReporter = new RedisFailoverReporter();
MultiClusterPooledConnectionProvider cacheProvider = new MultiClusterPooledConnectionProvider(builder.build());
Expand Down

0 comments on commit 1b65cf3

Please sign in to comment.