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

jedis-3.2.0 JedisClusterMaxAttemptsException connect to redis-5.0.7 cluster #2130

Closed
DoverDee opened this issue Jan 8, 2020 · 6 comments
Closed

Comments

@DoverDee
Copy link

DoverDee commented Jan 8, 2020

Expected behavior

when kill 7000 master node , the code will appear exception,
wait a moment, the slave instead of 7000 master node, the exception should be disappear.
but still pose exception .

Java code

public static void clusterConnJedis() {
Set clusterNodes = new HashSet();
HostAndPort hp7000 = new HostAndPort("172.16.1.41", 7000);
HostAndPort hp7001 = new HostAndPort("172.16.1.41", 7001);
HostAndPort hp7002 = new HostAndPort("172.16.1.41", 7002);
HostAndPort hp7003 = new HostAndPort("172.16.1.41", 7003);
HostAndPort hp7004 = new HostAndPort("172.16.1.41", 7004);
HostAndPort hp7005 = new HostAndPort("172.16.1.41", 7005);
clusterNodes.add(hp7000);
clusterNodes.add(hp7001);
clusterNodes.add(hp7002);
clusterNodes.add(hp7003);
clusterNodes.add(hp7004);
clusterNodes.add(hp7005);
JedisCluster clusterPool = null;
while (true) {
try {
clusterPool = new JedisCluster(clusterNodes, 5000, new JedisPoolConfig());
int index = new Random().nextInt(100000);
String key = "k-" + index;
String value = "v-" + index;
clusterPool.set(key, value);
System.out.println("key:value=" + key + ":" + clusterPool.get(key));
TimeUnit.MILLISECONDS.sleep(500);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != clusterPool) {
clusterPool.close();
}
}
}
}

Actual behavior and Steps to reproduce:

Redis cluster just installed and runing, run TestClass.clusterConnJedis(); in main method. everything is ok , I find the right pint key:value=k-RandomNum:v-RandomNum per 500 MILLISECONDS in conole.

But when I command ' kill -p ${hp7000_ pid}' , 7000 master node be killed. I find the console print
JedisClusterMaxAttemptsException several normal print intervals.
exception details:
redis.clients.jedis.exceptions.JedisClusterMaxAttemptsException: No more cluster attempts left.
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:86)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:124)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:124)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:124)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:124)
at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:124)
at redis.clients.jedis.JedisClusterCommand.run(JedisClusterCommand.java:25)
at redis.clients.jedis.JedisCluster.set(JedisCluster.java:143)
at Test.clusterConnJedis(Test.java:69)
at Test.main(Test.java:11)
exception picture:
image

Redis / Jedis Configuration

see code clusterConnJedis()

Jedis version:

jedis-3.2.0

Redis version:

redis-5.0.7 cluster

Java version:

jdk1.8.0.211

@yangbodong22011
Copy link
Collaborator

When the Cluster is abnormal, Jedis will provide retries. The default number of retries is 5, see redis.clients.jedis.BinaryJedisCluster#DEFAULT_MAX_ATTEMPTS. You can specify more retries through the following construction method.

public JedisCluster(Set<HostAndPort> nodes, int timeout, int maxAttempts) {
    this(nodes, timeout, maxAttempts, new GenericObjectPoolConfig());
}

// your code:
clusterPool = new JedisCluster(clusterNodes, 5000, maxAttempts);

But I don't recommend that you set maxAttempts too large, otherwise it may cause java.lang.StackOverflowError due to recursion.

@sazzad16
Copy link
Collaborator

@DoverDee What is the output of CLUSTER NODES from redis-cli. I'm guessing node IPs are not with 172.16.1.41.

@sazzad16
Copy link
Collaborator

Closed due to inactivity.

@walles
Copy link
Contributor

walles commented Feb 2, 2021

This PR would provide retries with backoff, giving the cluster a chance to come back: #2358

@choice
Copy link

choice commented Sep 19, 2022

May I ask how this problem was finally dealt with.
'redis.clients.jedis.exceptions.JedisClusterMaxAttemptsException: No more cluster attempts left.'
This problem is giving me a headache

@jbhamilton
Copy link

Running into the same issue in our production env right now and cannot replicate locally. Any guidance would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants