invoke stopThreads method on any error during Replicated or Sentinel connection start

pull/970/head
Nikita 8 years ago
parent d444adab9a
commit 629f1ec503

@ -84,6 +84,7 @@ public class ReplicatedConnectionManager extends MasterSlaveConnectionManager {
Role role = Role.valueOf(connection.sync(RedisCommands.INFO_REPLICATION).get(ROLE_KEY)); Role role = Role.valueOf(connection.sync(RedisCommands.INFO_REPLICATION).get(ROLE_KEY));
if (Role.master.equals(role)) { if (Role.master.equals(role)) {
if (currentMaster.get() != null) { if (currentMaster.get() != null) {
stopThreads();
throw new RedisException("Multiple masters detected"); throw new RedisException("Multiple masters detected");
} }
currentMaster.set(addr); currentMaster.set(addr);
@ -96,6 +97,7 @@ public class ReplicatedConnectionManager extends MasterSlaveConnectionManager {
} }
if (currentMaster.get() == null) { if (currentMaster.get() == null) {
stopThreads();
throw new RedisConnectionException("Can't connect to servers!"); throw new RedisConnectionException("Can't connect to servers!");
} }

@ -71,6 +71,10 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
this.config = create(cfg); this.config = create(cfg);
initTimer(this.config); initTimer(this.config);
if (cfg.getMasterName() == null) {
throw new IllegalArgumentException("masterName parameter is not defined!");
}
for (URI addr : cfg.getSentinelAddresses()) { for (URI addr : cfg.getSentinelAddresses()) {
RedisClient client = createClient(NodeType.SENTINEL, addr, this.config.getConnectTimeout(), this.config.getRetryInterval() * this.config.getRetryAttempts()); RedisClient client = createClient(NodeType.SENTINEL, addr, this.config.getConnectTimeout(), this.config.getRetryInterval() * this.config.getRetryAttempts());
try { try {
@ -119,6 +123,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
} }
if (currentMaster.get() == null) { if (currentMaster.get() == null) {
stopThreads();
throw new RedisConnectionException("Can't connect to servers!"); throw new RedisConnectionException("Can't connect to servers!");
} }
init(this.config); init(this.config);

Loading…
Cancel
Save