fix issue #642
This commit is contained in:
@@ -130,10 +130,17 @@ public class JedisSentinelPool extends Pool<Jedis> {
|
||||
|
||||
try {
|
||||
Jedis jedis = new Jedis(hap.getHost(), hap.getPort());
|
||||
|
||||
if (master == null) {
|
||||
master = toHostAndPort(jedis
|
||||
.sentinelGetMasterAddrByName(masterName));
|
||||
List<String> masterAddr = jedis
|
||||
.sentinelGetMasterAddrByName(masterName);
|
||||
if (masterAddr == null || masterAddr.size() != 2) {
|
||||
log.warning("Can not get master addr, master name: "
|
||||
+ masterName + ". Sentinel: " + hap + ".");
|
||||
jedis.disconnect();
|
||||
continue;
|
||||
}
|
||||
|
||||
master = toHostAndPort(masterAddr);
|
||||
log.fine("Found Redis master at " + master);
|
||||
jedis.disconnect();
|
||||
break outer;
|
||||
|
||||
@@ -2,6 +2,7 @@ package redis.clients.jedis.tests;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import org.junit.Before;
|
||||
@@ -35,6 +36,29 @@ public class JedisSentinelPoolTest extends JedisTestBase {
|
||||
sentinelJedis1 = new Jedis(sentinel1.getHost(), sentinel1.getPort());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void errorMasterNameNotThrowException() throws InterruptedException {
|
||||
final String wrongMasterName = "wrongMasterName";
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(3);
|
||||
sentinelJedis1.sentinelMonitor(wrongMasterName,
|
||||
"127.0.0.1", master.getPort(), 2);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}).start();
|
||||
|
||||
JedisSentinelPool pool = new JedisSentinelPool(wrongMasterName,
|
||||
sentinels);
|
||||
pool.destroy();
|
||||
sentinelJedis1.sentinelRemove(wrongMasterName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ensureSafeTwiceFailover() throws InterruptedException {
|
||||
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels,
|
||||
|
||||
Reference in New Issue
Block a user