15
15
import redis .clients .jedis .ConnectionPool ;
16
16
import redis .clients .jedis .JedisClusterInfoCache ;
17
17
import redis .clients .jedis .exceptions .JedisClusterOperationException ;
18
- import redis .clients .jedis .exceptions .JedisConnectionException ;
19
18
import redis .clients .jedis .exceptions .JedisException ;
20
19
21
20
public class ClusterConnectionProvider implements ConnectionProvider {
@@ -34,19 +33,30 @@ public ClusterConnectionProvider(Set<HostAndPort> clusterNodes, JedisClientConfi
34
33
}
35
34
36
35
private void initializeSlotsCache (Set <HostAndPort > startNodes , JedisClientConfig clientConfig ) {
36
+ if (startNodes .isEmpty ()) {
37
+ throw new JedisClusterOperationException ("No nodes to initialize cluster slots cache." );
38
+ }
39
+
37
40
ArrayList <HostAndPort > startNodeList = new ArrayList <>(startNodes );
38
41
Collections .shuffle (startNodeList );
39
42
43
+ JedisException firstException = null ;
40
44
for (HostAndPort hostAndPort : startNodeList ) {
41
45
try (Connection jedis = new Connection (hostAndPort , clientConfig )) {
42
46
cache .discoverClusterNodesAndSlots (jedis );
43
47
return ;
44
48
} catch (JedisException e ) {
49
+ if (firstException == null ) {
50
+ firstException = e ;
51
+ }
45
52
// try next nodes
46
53
}
47
54
}
48
55
49
- throw new JedisClusterOperationException ("Could not initialize cluster slots cache." );
56
+ JedisClusterOperationException uninitializedException
57
+ = new JedisClusterOperationException ("Could not initialize cluster slots cache." );
58
+ uninitializedException .addSuppressed (firstException );
59
+ throw uninitializedException ;
50
60
}
51
61
52
62
@ Override
0 commit comments