|
22 | 22 | * This configuration enables seamless failover between multiple Redis clusters, databases, or
|
23 | 23 | * endpoints by providing comprehensive settings for retry logic, circuit breaker behavior, health
|
24 | 24 | * checks, and failback mechanisms. It is designed to work with
|
25 |
| - * {@link redis.clients.jedis.providers.MultiClusterPooledConnectionProvider} to provide high |
26 |
| - * availability and disaster recovery capabilities. |
| 25 | + * {@link redis.clients.jedis.mcf.MultiClusterPooledConnectionProvider} to provide high availability |
| 26 | + * and disaster recovery capabilities. |
27 | 27 | * </p>
|
28 | 28 | * <p>
|
29 | 29 | * <strong>Key Features:</strong>
|
|
70 | 70 | * The configuration leverages <a href="https://resilience4j.readme.io/docs">Resilience4j</a> for
|
71 | 71 | * circuit breaker and retry implementations, providing battle-tested fault tolerance patterns.
|
72 | 72 | * </p>
|
73 |
| - * @see redis.clients.jedis.providers.MultiClusterPooledConnectionProvider |
| 73 | + * @see redis.clients.jedis.mcf.MultiClusterPooledConnectionProvider |
74 | 74 | * @see redis.clients.jedis.mcf.HealthCheckStrategy
|
75 | 75 | * @see redis.clients.jedis.mcf.EchoStrategy
|
76 | 76 | * @see redis.clients.jedis.mcf.LagAwareStrategy
|
@@ -161,6 +161,12 @@ public static interface StrategySupplier {
|
161 | 161 | /** Default grace period in milliseconds to keep clusters disabled after they become unhealthy. */
|
162 | 162 | private static final long GRACE_PERIOD_DEFAULT = 10000;
|
163 | 163 |
|
| 164 | + /** Default maximum number of failover attempts. */ |
| 165 | + private static final int MAX_NUM_FAILOVER_ATTEMPTS_DEFAULT = 10; |
| 166 | + |
| 167 | + /** Default delay in milliseconds between failover attempts. */ |
| 168 | + private static final int DELAY_IN_BETWEEN_FAILOVER_ATTEMPTS_DEFAULT = 12000; |
| 169 | + |
164 | 170 | /** Array of cluster configurations defining the available Redis endpoints and their settings. */
|
165 | 171 | private final ClusterConfig[] clusterConfigs;
|
166 | 172 |
|
@@ -485,6 +491,34 @@ public static interface StrategySupplier {
|
485 | 491 | */
|
486 | 492 | private boolean fastFailover;
|
487 | 493 |
|
| 494 | + /** |
| 495 | + * Maximum number of failover attempts. |
| 496 | + * <p> |
| 497 | + * This setting controls how many times the system will attempt to failover to a different cluster |
| 498 | + * before giving up. For example, if set to 3, the system will make 1 initial attempt plus 2 |
| 499 | + * failover attempts for a total of 3 attempts. |
| 500 | + * </p> |
| 501 | + * <p> |
| 502 | + * <strong>Default:</strong> {@value #MAX_NUM_FAILOVER_ATTEMPTS_DEFAULT} |
| 503 | + * </p> |
| 504 | + * @see #getMaxNumFailoverAttempts() |
| 505 | + */ |
| 506 | + private int maxNumFailoverAttempts; |
| 507 | + |
| 508 | + /** |
| 509 | + * Delay in milliseconds between failover attempts. |
| 510 | + * <p> |
| 511 | + * This setting controls how long the system will wait before attempting to failover to a |
| 512 | + * different cluster. For example, if set to 1000, the system will wait 1 second before attempting |
| 513 | + * to failover to a different cluster. |
| 514 | + * </p> |
| 515 | + * <p> |
| 516 | + * <strong>Default:</strong> {@value #DELAY_IN_BETWEEN_FAILOVER_ATTEMPTS_DEFAULT} milliseconds |
| 517 | + * </p> |
| 518 | + * @see #getDelayInBetweenFailoverAttempts() |
| 519 | + */ |
| 520 | + private int delayInBetweenFailoverAttempts; |
| 521 | + |
488 | 522 | /**
|
489 | 523 | * Constructs a new MultiClusterClientConfig with the specified cluster configurations.
|
490 | 524 | * <p>
|
@@ -679,6 +713,25 @@ public long getGracePeriod() {
|
679 | 713 | return gracePeriod;
|
680 | 714 | }
|
681 | 715 |
|
| 716 | + /** |
| 717 | + * Returns the maximum number of failover attempts. |
| 718 | + * @return maximum number of failover attempts |
| 719 | + * @see #maxNumFailoverAttempts |
| 720 | + */ |
| 721 | + public int getMaxNumFailoverAttempts() { |
| 722 | + return maxNumFailoverAttempts; |
| 723 | + |
| 724 | + } |
| 725 | + |
| 726 | + /** |
| 727 | + * Returns the delay in milliseconds between failover attempts. |
| 728 | + * @return delay in milliseconds between failover attempts |
| 729 | + * @see #delayInBetweenFailoverAttempts |
| 730 | + */ |
| 731 | + public int getDelayInBetweenFailoverAttempts() { |
| 732 | + return delayInBetweenFailoverAttempts; |
| 733 | + } |
| 734 | + |
682 | 735 | /**
|
683 | 736 | * Returns whether connections are forcefully terminated during failover.
|
684 | 737 | * @return true if fast failover is enabled, false for graceful failover
|
@@ -1090,6 +1143,12 @@ public static class Builder {
|
1090 | 1143 | /** Whether to forcefully terminate connections during failover. */
|
1091 | 1144 | private boolean fastFailover = false;
|
1092 | 1145 |
|
| 1146 | + /** Maximum number of failover attempts. */ |
| 1147 | + private int maxNumFailoverAttempts = MAX_NUM_FAILOVER_ATTEMPTS_DEFAULT; |
| 1148 | + |
| 1149 | + /** Delay in milliseconds between failover attempts. */ |
| 1150 | + private int delayInBetweenFailoverAttempts = DELAY_IN_BETWEEN_FAILOVER_ATTEMPTS_DEFAULT; |
| 1151 | + |
1093 | 1152 | /**
|
1094 | 1153 | * Constructs a new Builder with the specified cluster configurations.
|
1095 | 1154 | * @param clusterConfigs array of cluster configurations defining available Redis endpoints
|
@@ -1460,7 +1519,7 @@ public Builder retryOnFailover(boolean retryOnFailover) {
|
1460 | 1519 | * <ul>
|
1461 | 1520 | * <li>Health checks must be enabled on cluster configurations</li>
|
1462 | 1521 | * <li>Grace period must elapse after cluster becomes unhealthy</li>
|
1463 |
| - * <li>Higher-priority cluster must pass consecutive health checks</li> |
| 1522 | + * <li>Higher-priority cluster must pass health checks</li> |
1464 | 1523 | * </ul>
|
1465 | 1524 | * @param supported true to enable automatic failback, false for manual failback only
|
1466 | 1525 | * @return this builder instance for method chaining
|
@@ -1539,6 +1598,42 @@ public Builder fastFailover(boolean fastFailover) {
|
1539 | 1598 | return this;
|
1540 | 1599 | }
|
1541 | 1600 |
|
| 1601 | + /** |
| 1602 | + * Sets the maximum number of failover attempts. |
| 1603 | + * <p> |
| 1604 | + * This setting controls how many times the system will attempt to failover to a different |
| 1605 | + * cluster before giving up. For example, if set to 3, the system will make 1 initial attempt |
| 1606 | + * plus 2 failover attempts for a total of 3 attempts. |
| 1607 | + * </p> |
| 1608 | + * <p> |
| 1609 | + * <strong>Default:</strong> {@value #MAX_NUM_FAILOVER_ATTEMPTS_DEFAULT} |
| 1610 | + * </p> |
| 1611 | + * @param maxNumFailoverAttempts maximum number of failover attempts |
| 1612 | + * @return this builder instance for method chaining |
| 1613 | + */ |
| 1614 | + public Builder maxNumFailoverAttempts(int maxNumFailoverAttempts) { |
| 1615 | + this.maxNumFailoverAttempts = maxNumFailoverAttempts; |
| 1616 | + return this; |
| 1617 | + } |
| 1618 | + |
| 1619 | + /** |
| 1620 | + * Sets the delay in milliseconds between failover attempts. |
| 1621 | + * <p> |
| 1622 | + * This setting controls how long the system will wait before attempting to failover to a |
| 1623 | + * different cluster. For example, if set to 1000, the system will wait 1 second before |
| 1624 | + * attempting to failover to a different cluster. |
| 1625 | + * </p> |
| 1626 | + * <p> |
| 1627 | + * <strong>Default:</strong> {@value #DELAY_IN_BETWEEN_FAILOVER_ATTEMPTS_DEFAULT} milliseconds |
| 1628 | + * </p> |
| 1629 | + * @param delayInBetweenFailoverAttempts delay in milliseconds between failover attempts |
| 1630 | + * @return this builder instance for method chaining |
| 1631 | + */ |
| 1632 | + public Builder delayInBetweenFailoverAttempts(int delayInBetweenFailoverAttempts) { |
| 1633 | + this.delayInBetweenFailoverAttempts = delayInBetweenFailoverAttempts; |
| 1634 | + return this; |
| 1635 | + } |
| 1636 | + |
1542 | 1637 | /**
|
1543 | 1638 | * Builds and returns a new MultiClusterClientConfig instance with all configured settings.
|
1544 | 1639 | * <p>
|
@@ -1576,6 +1671,8 @@ public MultiClusterClientConfig build() {
|
1576 | 1671 | config.failbackCheckInterval = this.failbackCheckInterval;
|
1577 | 1672 | config.gracePeriod = this.gracePeriod;
|
1578 | 1673 | config.fastFailover = this.fastFailover;
|
| 1674 | + config.maxNumFailoverAttempts = this.maxNumFailoverAttempts; |
| 1675 | + config.delayInBetweenFailoverAttempts = this.delayInBetweenFailoverAttempts; |
1579 | 1676 |
|
1580 | 1677 | return config;
|
1581 | 1678 | }
|
|
0 commit comments