-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Description
If a machine is set up with multiple instances using 127.0.0.1 as it's address, then if another machine tries to create a JedisCluster and specifies the first machine address, the lookup of the members of the cluster are incorrectly created. The first machine node is the proper address but the rest of the cluster is 127.0.0.1 which is a local reference on the cluster.
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
public class JDCPBug {
static String redisHost = null;
static Logger log = null;
static {
Logger rootLogger = Logger.getRootLogger();
if (!rootLogger.getAllAppenders().hasMoreElements()) {
rootLogger.setLevel(Level.INFO);
rootLogger.addAppender(new ConsoleAppender(new org.apache.log4j.EnhancedPatternLayout("%d{yyyy-MM-dd HH:mm:ss.SSS} [%t; %C{1}] %-5p -- %m%n")));
}
log = Logger.getLogger(JDCPBug.class);
try {
redisHost = InetAddress.getByName("test2").getHostAddress();
}
catch (Exception e) {
log.fatal("Could not get address for redis host");
System.exit(1);
}
}
public static void main(String[] args) {
Set jedisClusterNodes = new HashSet();
jedisClusterNodes.add(new HostAndPort(redisHost, 17000));
JedisCluster jc = new JedisCluster(jedisClusterNodes);
log.info("Created jedis cluster on host " + redisHost + ", id=" + System.identityHashCode(jc));
log.info("Cluster nodes: " + jc.getClusterNodes().toString());
}
}
2014-08-15 10:28:36.714 [main; JDCPBug] INFO -- Created jedis cluster on host 10.11.14.23, id=1184623795
2014-08-15 10:28:36.717 [main; JDCPBug] INFO -- Cluster nodes: {10.11.14.23:17000=redis.clients.jedis.JedisPool@1cad8848, 127.0.0.1:17002=redis.clients.jedis.JedisPool@44ce3dad, 127.0.0.1:17001=redis.clients.jedis.JedisPool@40334c25, 127.0.0.1:17000=redis.clients.jedis.JedisPool@67cc3210, 127.0.0.1:17005=redis.clients.jedis.JedisPool@eeaedad, 127.0.0.1:17003=redis.clients.jedis.JedisPool@619a0081, 127.0.0.1:17004=redis.clients.jedis.JedisPool@45974736}
If the cluster is rebuilt to use the host IP instead, the addresses are fine:
2014-08-15 12:43:09.388 [main; JDCPBug] INFO -- Created jedis cluster on host 10.11.14.23, id=887408677
2014-08-15 12:43:09.391 [main; JDCPBug] INFO -- Cluster nodes: {10.11.14.23:17000=redis.clients.jedis.JedisPool@6aa9f1d0, 10.11.14.23:17002=redis.clients.jedis.JedisPool@3b42c565, 10.11.14.23:17001=redis.clients.jedis.JedisPool@1cad8848, 10.11.14.23:17005=redis.clients.jedis.JedisPool@44ce3dad, 10.11.14.23:17003=redis.clients.jedis.JedisPool@40334c25, 10.11.14.23:17004=redis.clients.jedis.JedisPool@67cc3210}