Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refresh connection for pipeline when getting JedisMovedDataException #3699

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/redis/clients/jedis/ClusterPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ protected Connection getConnection(HostAndPort nodeKey) {
return provider.getConnection(nodeKey);
}

@Override
protected void refreshConnection() {
provider.renewSlotCache();
}

public Response<Long> spublish(String channel, String message) {
return appendCommand(commandObjects.spublish(channel, message));
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/redis/clients/jedis/MultiNodePipelineBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.slf4j.LoggerFactory;

import redis.clients.jedis.exceptions.JedisConnectionException;
import redis.clients.jedis.exceptions.JedisMovedDataException;
import redis.clients.jedis.graph.GraphCommandObjects;
import redis.clients.jedis.providers.ConnectionProvider;
import redis.clients.jedis.util.IOUtils;
Expand Down Expand Up @@ -53,6 +54,8 @@ protected final void prepareGraphCommands(ConnectionProvider connectionProvider)

protected abstract Connection getConnection(HostAndPort nodeKey);

protected abstract void refreshConnection();

@Override
protected final <T> Response<T> appendCommand(CommandObject<T> commandObject) {
HostAndPort nodeKey = getNodeKey(commandObject.getArguments());
Expand Down Expand Up @@ -111,6 +114,9 @@ public final void sync() {
try {
List<Object> unformatted = connection.getMany(queue.size());
for (Object o : unformatted) {
if (o instanceof JedisMovedDataException) {
refreshConnection();
}
queue.poll().set(o);
}
} catch (JedisConnectionException jce) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/redis/clients/jedis/ShardedPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ protected Connection getConnection(HostAndPort nodeKey) {
return provider.getConnection(nodeKey);
}

@Override
protected void refreshConnection() {
// do nothing
}

/**
* This method must be called after constructor, if graph commands are going to be used.
*/
Expand Down
Loading