摘要:客户端报异常很困扰不知道是什么问题请看以下文章,为你一一解答。解决方案暂没发现比较好的解决方案。环境场景问题现象请求间歇性穿透缓存。与该错误关系不大。
jedis客户端报Too many Cluster redirections异常?很困扰?不知道是什么问题?请看以下文章,为你一一解答。
1.解决方案暂没发现比较好的解决方案。
2.环境Redis 3.x Cluster
Jedis 2.8
Jdk1.8
3.场景 4.问题现象请求间歇性穿透缓存。
错误信息redis.clients.jedis.exceptions.JedisClusterMaxRedirectionsException: Too many Cluster redirections? at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:34) at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:85) at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:68) at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:85) at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:68) at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:85) at redis.clients.jedis.JedisClusterCommand.runWithRetries(JedisClusterCommand.java:68) at redis.clients.jedis.JedisClusterCommand.run(JedisClusterCommand.java:29) at redis.clients.jedis.JedisCluster.set(JedisCluster.java:75)5.问题原因
通过分析以下代码得知错误原因:
private T runWithRetries(byte[] key, int redirections, boolean tryRandomNode, boolean asking) { if (redirections <= 0) { throw new JedisClusterMaxRedirectionsException("Too many Cluster redirections?"); } Jedis connection = null; try { if (asking) { // TODO: Pipeline asking with the original command to make it // faster.... connection = askConnection.get(); connection.asking(); // if asking success, reset asking flag asking = false; } else { if (tryRandomNode) { connection = connectionHandler.getConnection(); } else { connection = connectionHandler.getConnectionFromSlot(JedisClusterCRC16.getSlot(key)); } } return execute(connection); } catch (JedisConnectionException jce) { if (tryRandomNode) { // maybe all connection is down throw jce; } // release current connection before recursion releaseConnection(connection); connection = null; // retry with random connection return runWithRetries(key, redirections - 1, true, asking); } catch (JedisRedirectionException jre) { // if MOVED redirection occurred, if (jre instanceof JedisMovedDataException) { // it rebuilds cluster"s slot cache // recommended by Redis cluster specification this.connectionHandler.renewSlotCache(connection); } // release current connection before recursion or renewing releaseConnection(connection); connection = null; if (jre instanceof JedisAskDataException) { asking = true; askConnection.set(this.connectionHandler.getConnectionFromNode(jre.getTargetNode())); } else if (jre instanceof JedisMovedDataException) { } else { throw new JedisClusterException(jre); } return runWithRetries(key, redirections - 1, false, asking); } finally { releaseConnection(connection); } }
当发生JedisConnectionException或者JedisRedirectionException时,会重新调用当前方法。
JedisConnectionException与该错误关系不大。
因为该错误是:连接Redis错误,如果连接第一个节点失败,尝试第二个节点也失败,会直接推断成全部节点down掉抛出错误,中断处理。
JedisRedirectionException和该错误关系很大。
对该错误处理时,并处理了以下两个异常:
JedisMovedDataException:节点重置/迁移后,会抛出该异常
JedisAskDataException: 数据迁移,发生asking问题, 获取asking的Jedis
从此推断,发生该问题的原因为:
节点主从切换/迁移后,客户端与redis的slot不一致导致一直重试
asking 一直失败,当槽点数值分布在两个节点上时,容易引起该错误
因此,导致该错误的原因可为:
节点主从切换/迁移后,网络等各种原因导致更新slot信息失败
asking时一直指向同一个节点,导致asking一直失败(该几率较少?)
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/77194.html
摘要:集群时发生的错误搭建集群发生的错误在搭建完集群,重启了,抛出了。具体解决方法参考 1、集群时发生的错误 1.1、搭建集群发生的错误 在搭建完redis集群,重启了redis,抛出了127.0.0.1:6379 is not empty 。 解决方法:删除对应的redis下面的 dump.rdb 和aof 已经nodes.conf文件(如果没修改redis中的cluster-confi...
阅读 3807·2021-09-23 11:32
阅读 2474·2021-09-06 15:01
阅读 1633·2021-08-18 10:24
阅读 3472·2019-12-27 11:44
阅读 3617·2019-08-30 15:52
阅读 2525·2019-08-30 11:11
阅读 702·2019-08-29 17:27
阅读 612·2019-08-29 16:22