Fixed - master can't be changed anymore if new master wasn't added the first time. #1839

pull/1871/head
Nikita Koksharov 6 years ago
parent f4d5cfba35
commit 96ef05671e

@ -23,6 +23,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import org.redisson.api.RFuture;
import org.redisson.client.RedisClient;
import org.redisson.client.RedisConnection;
import org.redisson.client.RedisConnectionException;
import org.redisson.client.RedisException;
@ -165,7 +166,16 @@ public class ReplicatedConnectionManager extends MasterSlaveConnectionManager {
if (master.equals(addr)) {
log.debug("Current master {} unchanged", master);
} else if (currentMaster.compareAndSet(master, addr)) {
changeMaster(singleSlotRange.getStartSlot(), addr);
RFuture<RedisClient> changeFuture = changeMaster(singleSlotRange.getStartSlot(), addr);
changeFuture.addListener(new FutureListener<RedisClient>() {
@Override
public void operationComplete(Future<RedisClient> future)
throws Exception {
if (!future.isSuccess()) {
currentMaster.compareAndSet(addr, master);
}
}
});
}
} else if (!config.checkSkipSlavesInit()) {
slaveUp(addr);

@ -320,11 +320,19 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
List<String> master = future.getNow();
String current = currentMaster.get();
String newMaster = createAddress(master.get(0), master.get(1));
final String current = currentMaster.get();
final String newMaster = createAddress(master.get(0), master.get(1));
if (!newMaster.equals(current)
&& currentMaster.compareAndSet(current, newMaster)) {
changeMaster(singleSlotRange.getStartSlot(), URIBuilder.create(newMaster));
RFuture<RedisClient> changeFuture = changeMaster(singleSlotRange.getStartSlot(), URIBuilder.create(newMaster));
changeFuture.addListener(new FutureListener<RedisClient>() {
@Override
public void operationComplete(Future<RedisClient> future) throws Exception {
if (!future.isSuccess()) {
currentMaster.compareAndSet(newMaster, current);
}
}
});
}
}
});

Loading…
Cancel
Save