-
Notifications
You must be signed in to change notification settings - Fork 992
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cluster connection failover when cluster topology changes #97
- Provide ClusterClientOptions to enable/disable topology refresh - Implement ASK redirection - Prevent connections to other nodes than the partion view provides (exact check) - Polishing
- Loading branch information
Showing
23 changed files
with
958 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
import java.io.Serializable; | ||
|
||
/** | ||
* Client Options to control the behavior of {@link RedisClient} and {@link com.lambdaworks.redis.cluster.RedisClusterClient}. | ||
* Client Options to control the behavior of {@link RedisClient}. | ||
* | ||
* @author <a href="mailto:[email protected]">Mark Paluch</a> | ||
*/ | ||
|
@@ -88,14 +88,14 @@ public ClientOptions build() { | |
} | ||
} | ||
|
||
private ClientOptions(Builder builder) { | ||
protected ClientOptions(Builder builder) { | ||
pingBeforeActivateConnection = builder.pingBeforeActivateConnection; | ||
cancelCommandsOnReconnectFailure = builder.cancelCommandsOnReconnectFailure; | ||
autoReconnect = builder.autoReconnect; | ||
suspendReconnectOnProtocolFailure = builder.suspendReconnectOnProtocolFailure; | ||
} | ||
|
||
private ClientOptions(ClientOptions original) { | ||
protected ClientOptions(ClientOptions original) { | ||
this.pingBeforeActivateConnection = original.pingBeforeActivateConnection; | ||
this.autoReconnect = original.autoReconnect; | ||
this.cancelCommandsOnReconnectFailure = original.cancelCommandsOnReconnectFailure; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
src/main/java/com/lambdaworks/redis/cluster/ClusterClientOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package com.lambdaworks.redis.cluster; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import com.lambdaworks.redis.ClientOptions; | ||
|
||
/** | ||
* Client Options to control the behavior of {@link RedisClusterClient}. | ||
* | ||
* @author <a href="mailto:[email protected]">Mark Paluch</a> | ||
*/ | ||
public class ClusterClientOptions extends ClientOptions { | ||
private final boolean refreshClusterView; | ||
private final long refreshPeriod; | ||
private final TimeUnit refreshPeriodUnit; | ||
|
||
/** | ||
* Create a copy of {@literal options} | ||
* | ||
* @param options the original | ||
* @return A new instance of {@link ClusterClientOptions} containing the values of {@literal options} | ||
*/ | ||
public static ClusterClientOptions copyOf(ClusterClientOptions options) { | ||
return new ClusterClientOptions(options); | ||
} | ||
|
||
/** | ||
* Builder for {@link ClusterClientOptions}. | ||
*/ | ||
public static class Builder extends ClientOptions.Builder { | ||
|
||
private boolean refreshClusterView = false; | ||
private long refreshPeriod = 60; | ||
private TimeUnit refreshPeriodUnit = TimeUnit.SECONDS; | ||
|
||
/** | ||
* Enable regular cluster topology updates. The client starts updating the cluster topology in the intervals of | ||
* {@link Builder#refreshPeriod} /{@link Builder#refreshPeriodUnit}. Defaults to {@literal false}. | ||
* | ||
* @param refreshClusterView {@literal true} enable regular cluster topology updates or {@literal false} to disable | ||
* auto-updating | ||
* @return {@code this} | ||
*/ | ||
public Builder refreshClusterView(boolean refreshClusterView) { | ||
this.refreshClusterView = refreshClusterView; | ||
return this; | ||
} | ||
|
||
/** | ||
* Set the refresh period. Defaults to {@literal 60 SECONDS} | ||
* | ||
* @param refreshPeriod period for triggering topology updates | ||
* @param refreshPeriodUnit unit for {@code refreshPeriod} | ||
* @return {@code this} | ||
*/ | ||
public Builder refreshPeriod(long refreshPeriod, TimeUnit refreshPeriodUnit) { | ||
this.refreshPeriod = refreshPeriod; | ||
this.refreshPeriodUnit = refreshPeriodUnit; | ||
return this; | ||
} | ||
|
||
/** | ||
* Create a new instance of {@link ClusterClientOptions} | ||
* | ||
* @return new instance of {@link ClusterClientOptions} | ||
*/ | ||
public ClusterClientOptions build() { | ||
return new ClusterClientOptions(this); | ||
} | ||
} | ||
|
||
protected ClusterClientOptions(Builder builder) { | ||
super(builder); | ||
this.refreshClusterView = builder.refreshClusterView; | ||
this.refreshPeriod = builder.refreshPeriod; | ||
this.refreshPeriodUnit = builder.refreshPeriodUnit; | ||
} | ||
|
||
protected ClusterClientOptions(ClusterClientOptions original) { | ||
super(original); | ||
this.refreshClusterView = original.refreshClusterView; | ||
this.refreshPeriod = original.refreshPeriod; | ||
this.refreshPeriodUnit = original.refreshPeriodUnit; | ||
} | ||
|
||
protected ClusterClientOptions() { | ||
this.refreshClusterView = false; | ||
this.refreshPeriod = 60; | ||
this.refreshPeriodUnit = TimeUnit.SECONDS; | ||
} | ||
|
||
/** | ||
* Flag, whether regular cluster topology updates are updated. The client starts updating the cluster topology in the | ||
* intervals of {@link #getRefreshPeriod()} /{@link #getRefreshPeriodUnit()}. Defaults to {@literal false} | ||
* | ||
* @return | ||
*/ | ||
public boolean isRefreshClusterView() { | ||
return refreshClusterView; | ||
} | ||
|
||
/** | ||
* | ||
* @return the period between the regular cluster topology updates. | ||
*/ | ||
public long getRefreshPeriod() { | ||
return refreshPeriod; | ||
} | ||
|
||
/** | ||
* | ||
* @return unit for the {@link #getRefreshPeriod()} | ||
*/ | ||
public TimeUnit getRefreshPeriodUnit() { | ||
return refreshPeriodUnit; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.