Skip to content

Commit

Permalink
Align replica wording in Redis Cluster components #845
Browse files Browse the repository at this point in the history
Adapt replica wording by introducing replacement methods and deprecate existing ones. Update javadoc and test method names.
  • Loading branch information
mp911de committed Feb 7, 2019
1 parent 3440628 commit 52ee0dc
Show file tree
Hide file tree
Showing 34 changed files with 269 additions and 134 deletions.
4 changes: 2 additions & 2 deletions src/main/java/io/lettuce/core/cluster/PartitionAccessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ List<RedisClusterNode> getMasters() {
return get(redisClusterNode -> redisClusterNode.is(RedisClusterNode.NodeFlag.MASTER));
}

List<RedisClusterNode> getSlaves() {
List<RedisClusterNode> getReplicas() {
return get(redisClusterNode -> redisClusterNode.is(RedisClusterNode.NodeFlag.SLAVE));

}

List<RedisClusterNode> getSlaves(RedisClusterNode master) {
List<RedisClusterNode> getReplicas(RedisClusterNode master) {
return get(redisClusterNode -> redisClusterNode.is(RedisClusterNode.NodeFlag.SLAVE)
&& master.getNodeId().equals(redisClusterNode.getSlaveOf()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ enum CommandName {
SUNION, TIME, TTL, TYPE, ZCARD, ZCOUNT, ZLEXCOUNT, ZRANGE, //
ZRANGEBYLEX, ZRANGEBYSCORE, ZRANK, ZREVRANGE, ZREVRANGEBYLEX, ZREVRANGEBYSCORE, ZREVRANK, ZSCAN, ZSCORE, //

// Pub/Sub commands are no key-space commands so they are safe to execute on slave nodes
// Pub/Sub commands are no key-space commands so they are safe to execute on replica nodes
PUBLISH, PUBSUB, PSUBSCRIBE, PUNSUBSCRIBE, SUBSCRIBE, UNSUBSCRIBE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public interface NodeSelectionServerAsyncCommands<K, V> {
AsyncExecutions<String> save();

/**
* Make the server a slave of another instance, or promote it as master.
* Make the server a replica of another instance, or promote it as master.
*
* @param host the host type: string
* @param port the port type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
* @author Mark Paluch
* @since 4.0
*/
public interface RedisAdvancedClusterAsyncCommands<K, V>
extends RedisClusterAsyncCommands<K, V> {
public interface RedisAdvancedClusterAsyncCommands<K, V> extends RedisClusterAsyncCommands<K, V> {

/**
* Retrieve a connection to the specified cluster node using the nodeId. Host and port are looked up in the node list.
Expand Down Expand Up @@ -77,23 +76,49 @@ default AsyncNodeSelection<K, V> masters() {
}

/**
* Select all slaves.
* Select all replicas.
*
* @return API with asynchronous executed commands on a selection of slave cluster nodes.
* @return API with asynchronous executed commands on a selection of replica cluster nodes.
* @deprecated since 5.2, use {@link #replicas()}
*/
@Deprecated
default AsyncNodeSelection<K, V> slaves() {
return readonly(redisClusterNode -> redisClusterNode.is(RedisClusterNode.NodeFlag.SLAVE));
}

/**
* Select all slaves.
* Select all replicas.
*
* @param predicate Predicate to filter nodes
* @return API with asynchronous executed commands on a selection of slave cluster nodes.
* @return API with asynchronous executed commands on a selection of replica cluster nodes.
* @deprecated use {@link #replicas(Predicate)}
*/
@Deprecated
default AsyncNodeSelection<K, V> slaves(Predicate<RedisClusterNode> predicate) {
return readonly(
redisClusterNode -> predicate.test(redisClusterNode) && redisClusterNode.is(RedisClusterNode.NodeFlag.SLAVE));
return readonly(redisClusterNode -> predicate.test(redisClusterNode)
&& redisClusterNode.is(RedisClusterNode.NodeFlag.SLAVE));
}

/**
* Select all replicas.
*
* @return API with asynchronous executed commands on a selection of replica cluster nodes.
* @since 5.2
*/
default AsyncNodeSelection<K, V> replicas() {
return readonly(redisClusterNode -> redisClusterNode.is(RedisClusterNode.NodeFlag.REPLICA));
}

/**
* Select all replicas.
*
* @param predicate Predicate to filter nodes
* @return API with asynchronous executed commands on a selection of replica cluster nodes.
* @since 5.2
*/
default AsyncNodeSelection<K, V> replicas(Predicate<RedisClusterNode> predicate) {
return readonly(redisClusterNode -> predicate.test(redisClusterNode)
&& redisClusterNode.is(RedisClusterNode.NodeFlag.REPLICA));
}

/**
Expand All @@ -106,8 +131,8 @@ default AsyncNodeSelection<K, V> all() {
}

/**
* Select slave nodes by a predicate and keeps a static selection. Slave connections operate in {@literal READONLY} mode.
* The set of nodes within the {@link NodeSelectionSupport} does not change when the cluster view changes.
* Select replica nodes by a predicate and keeps a static selection. Replica connections operate in {@literal READONLY}
* mode. The set of nodes within the {@link NodeSelectionSupport} does not change when the cluster view changes.
*
* @param predicate Predicate to filter nodes
* @return API with asynchronous executed commands on a selection of cluster nodes matching {@code predicate}
Expand Down Expand Up @@ -152,7 +177,8 @@ default AsyncNodeSelection<K, V> all() {
RedisFuture<Long> unlink(K... keys);

/**
* Determine how many keys exist with pipelining. Cross-slot keys will result in multiple calls to the particular cluster nodes.
* Determine how many keys exist with pipelining. Cross-slot keys will result in multiple calls to the particular cluster
* nodes.
*
* @param keys the keys
* @return Long integer-reply specifically: Number of existing keys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ public interface RedisClusterAsyncCommands<K, V> extends BaseRedisAsyncCommands<
RedisFuture<String> clusterNodes();

/**
* List slaves for a certain node identified by its {@code nodeId}. Can be parsed using
* List replicas for a certain node identified by its {@code nodeId}. Can be parsed using
* {@link io.lettuce.core.cluster.models.partitions.ClusterPartitionParser#parse}
*
* @param nodeId node id of the master node
* @return List&lt;String&gt; array-reply list of slaves. The command returns data in the same format as
* {@link #clusterNodes()} but one line per slave.
* @return List&lt;String&gt; array-reply list of replicas. The command returns data in the same format as
* {@link #clusterNodes()} but one line per replica.
*/
RedisFuture<List<String>> clusterSlaves(String nodeId);

Expand Down Expand Up @@ -247,15 +247,15 @@ public interface RedisClusterAsyncCommands<K, V> extends BaseRedisAsyncCommands<
RedisFuture<String> asking();

/**
* Turn this node into a slave of the node with the id {@code nodeId}.
* Turn this node into a replica of the node with the id {@code nodeId}.
*
* @param nodeId master node id
* @return String simple-string-reply
*/
RedisFuture<String> clusterReplicate(String nodeId);

/**
* Failover a cluster node. Turns the currently connected node into a master and the master into its slave.
* Failover a cluster node. Turns the currently connected node into a master and the master into its replica.
*
* @param force do not coordinate with master if {@literal true}
* @return String simple-string-reply
Expand All @@ -267,11 +267,11 @@ public interface RedisClusterAsyncCommands<K, V> extends BaseRedisAsyncCommands<
* <ul>
* <li>All other nodes are forgotten</li>
* <li>All the assigned / open slots are released</li>
* <li>If the node is a slave, it turns into a master</li>
* <li>If the node is a replica, it turns into a master</li>
* <li>Only for hard reset: a new Node ID is generated</li>
* <li>Only for hard reset: currentEpoch and configEpoch are set to 0</li>
* <li>The new configuration is saved and the cluster state updated</li>
* <li>If the node was a slave, the whole data set is flushed away</li>
* <li>If the node was a replica, the whole data set is flushed away</li>
* </ul>
*
* @param hard {@literal true} for hard reset. Generates a new nodeId and currentEpoch/configEpoch are set to 0
Expand All @@ -287,7 +287,7 @@ public interface RedisClusterAsyncCommands<K, V> extends BaseRedisAsyncCommands<
RedisFuture<String> clusterFlushslots();

/**
* Tells a Redis cluster slave node that the client is ok reading possibly stale data and is not interested in running write
* Tells a Redis cluster replica node that the client is ok reading possibly stale data and is not interested in running write
* queries.
*
* @return String simple-string-reply
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ public interface RedisClusterReactiveCommands<K, V> extends BaseRedisReactiveCom
Mono<String> clusterNodes();

/**
* List slaves for a certain node identified by its {@code nodeId}. Can be parsed using
* List replicas for a certain node identified by its {@code nodeId}. Can be parsed using
* {@link io.lettuce.core.cluster.models.partitions.ClusterPartitionParser#parse}
*
* @param nodeId node id of the master node
* @return List&lt;String&gt; array-reply list of slaves. The command returns data in the same format as
* {@link #clusterNodes()} but one line per slave.
* @return List&lt;String&gt; array-reply list of replicas. The command returns data in the same format as
* {@link #clusterNodes()} but one line per replica.
*/
Flux<String> clusterSlaves(String nodeId);

Expand Down Expand Up @@ -248,15 +248,15 @@ public interface RedisClusterReactiveCommands<K, V> extends BaseRedisReactiveCom
Mono<String> asking();

/**
* Turn this node into a slave of the node with the id {@code nodeId}.
* Turn this node into a replica of the node with the id {@code nodeId}.
*
* @param nodeId master node id
* @return String simple-string-reply
*/
Mono<String> clusterReplicate(String nodeId);

/**
* Failover a cluster node. Turns the currently connected node into a master and the master into its slave.
* Failover a cluster node. Turns the currently connected node into a master and the master into its replica.
*
* @param force do not coordinate with master if {@literal true}
* @return String simple-string-reply
Expand All @@ -268,11 +268,11 @@ public interface RedisClusterReactiveCommands<K, V> extends BaseRedisReactiveCom
* <ul>
* <li>All other nodes are forgotten</li>
* <li>All the assigned / open slots are released</li>
* <li>If the node is a slave, it turns into a master</li>
* <li>If the node is a replica, it turns into a master</li>
* <li>Only for hard reset: a new Node ID is generated</li>
* <li>Only for hard reset: currentEpoch and configEpoch are set to 0</li>
* <li>The new configuration is saved and the cluster state updated</li>
* <li>If the node was a slave, the whole data set is flushed away</li>
* <li>If the node was a replica, the whole data set is flushed away</li>
* </ul>
*
* @param hard {@literal true} for hard reset. Generates a new nodeId and currentEpoch/configEpoch are set to 0
Expand All @@ -288,7 +288,7 @@ public interface RedisClusterReactiveCommands<K, V> extends BaseRedisReactiveCom
Mono<String> clusterFlushslots();

/**
* Tells a Redis cluster slave node that the client is ok reading possibly stale data and is not interested in running write
* Tells a Redis cluster replica node that the client is ok reading possibly stale data and is not interested in running write
* queries.
*
* @return String simple-string-reply
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public interface NodeSelectionServerCommands<K, V> {
Executions<String> save();

/**
* Make the server a slave of another instance, or promote it as master.
* Make the server a replica of another instance, or promote it as master.
*
* @param host the host type: string
* @param port the port type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,49 @@ default NodeSelection<K, V> masters() {
}

/**
* Select all slaves.
* Select all replicas.
*
* @return API with synchronous executed commands on a selection of slave cluster nodes.
* @return API with synchronous executed commands on a selection of replica cluster nodes.
* @deprecated since 5.2, use {@link #replicas()}
*/
@Deprecated
default NodeSelection<K, V> slaves() {
return readonly(redisClusterNode -> redisClusterNode.is(RedisClusterNode.NodeFlag.SLAVE));
}

/**
* Select all slaves.
* Select all replicas.
*
* @param predicate Predicate to filter nodes
* @return API with synchronous executed commands on a selection of slave cluster nodes.
* @return API with synchronous executed commands on a selection of replica cluster nodes.
* @deprecated since 5.2, use {@link #replicas(Predicate)}
*/
@Deprecated
default NodeSelection<K, V> slaves(Predicate<RedisClusterNode> predicate) {
return readonly(
redisClusterNode -> predicate.test(redisClusterNode) && redisClusterNode.is(RedisClusterNode.NodeFlag.SLAVE));
return readonly(redisClusterNode -> predicate.test(redisClusterNode)
&& redisClusterNode.is(RedisClusterNode.NodeFlag.SLAVE));
}

/**
* Select all replicas.
*
* @return API with synchronous executed commands on a selection of replica cluster nodes.
* @since 5.2
*/
default NodeSelection<K, V> replicas() {
return readonly(redisClusterNode -> redisClusterNode.is(RedisClusterNode.NodeFlag.REPLICA));
}

/**
* Select all replicas.
*
* @param predicate Predicate to filter nodes
* @return API with synchronous executed commands on a selection of replica cluster nodes.
* @since 5.2
*/
default NodeSelection<K, V> replicas(Predicate<RedisClusterNode> predicate) {
return readonly(redisClusterNode -> predicate.test(redisClusterNode)
&& redisClusterNode.is(RedisClusterNode.NodeFlag.REPLICA));
}

/**
Expand All @@ -103,8 +129,8 @@ default NodeSelection<K, V> all() {
}

/**
* Select slave nodes by a predicate and keeps a static selection. Slave connections operate in {@literal READONLY} mode.
* The set of nodes within the {@link NodeSelectionSupport} does not change when the cluster view changes.
* Select replica nodes by a predicate and keeps a static selection. Replica connections operate in {@literal READONLY}
* mode. The set of nodes within the {@link NodeSelectionSupport} does not change when the cluster view changes.
*
* @param predicate Predicate to filter nodes
* @return API with synchronous executed commands on a selection of cluster nodes matching {@code predicate}
Expand Down Expand Up @@ -149,7 +175,8 @@ default NodeSelection<K, V> all() {
Long unlink(K... keys);

/**
* Determine how many keys exist with pipelining. Cross-slot keys will result in multiple calls to the particular cluster nodes.
* Determine how many keys exist with pipelining. Cross-slot keys will result in multiple calls to the particular cluster
* nodes.
*
* @param keys the keys
* @return Long integer-reply specifically: Number of existing keys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ public interface RedisClusterCommands<K, V> extends BaseRedisCommands<K, V>, Red
String clusterNodes();

/**
* List slaves for a certain node identified by its {@code nodeId}. Can be parsed using
* List replicas for a certain node identified by its {@code nodeId}. Can be parsed using
* {@link io.lettuce.core.cluster.models.partitions.ClusterPartitionParser#parse}
*
* @param nodeId node id of the master node
* @return List&lt;String&gt; array-reply list of slaves. The command returns data in the same format as
* {@link #clusterNodes()} but one line per slave.
* @return List&lt;String&gt; array-reply list of replicas. The command returns data in the same format as
* {@link #clusterNodes()} but one line per replica.
*/
List<String> clusterSlaves(String nodeId);

Expand Down Expand Up @@ -244,15 +244,15 @@ public interface RedisClusterCommands<K, V> extends BaseRedisCommands<K, V>, Red
String asking();

/**
* Turn this node into a slave of the node with the id {@code nodeId}.
* Turn this node into a replica of the node with the id {@code nodeId}.
*
* @param nodeId master node id
* @return String simple-string-reply
*/
String clusterReplicate(String nodeId);

/**
* Failover a cluster node. Turns the currently connected node into a master and the master into its slave.
* Failover a cluster node. Turns the currently connected node into a master and the master into its replica.
*
* @param force do not coordinate with master if {@literal true}
* @return String simple-string-reply
Expand All @@ -264,11 +264,11 @@ public interface RedisClusterCommands<K, V> extends BaseRedisCommands<K, V>, Red
* <ul>
* <li>All other nodes are forgotten</li>
* <li>All the assigned / open slots are released</li>
* <li>If the node is a slave, it turns into a master</li>
* <li>If the node is a replica, it turns into a master</li>
* <li>Only for hard reset: a new Node ID is generated</li>
* <li>Only for hard reset: currentEpoch and configEpoch are set to 0</li>
* <li>The new configuration is saved and the cluster state updated</li>
* <li>If the node was a slave, the whole data set is flushed away</li>
* <li>If the node was a replica, the whole data set is flushed away</li>
* </ul>
*
* @param hard {@literal true} for hard reset. Generates a new nodeId and currentEpoch/configEpoch are set to 0
Expand All @@ -284,7 +284,7 @@ public interface RedisClusterCommands<K, V> extends BaseRedisCommands<K, V>, Red
String clusterFlushslots();

/**
* Tells a Redis cluster slave node that the client is ok reading possibly stale data and is not interested in running write
* Tells a Redis cluster replica node that the client is ok reading possibly stale data and is not interested in running write
* queries.
*
* @return String simple-string-reply
Expand Down
Loading

0 comments on commit 52ee0dc

Please sign in to comment.