Fixed - "READONLY You can't write against a read only replica.." is thrown after failover in sentinel mode. #4822

pull/4931/head
Nikita Koksharov 2 years ago
parent 4b2830fab5
commit 1375c39fe7

@ -351,7 +351,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
private void updateState(SentinelServersConfig cfg, RedisConnection connection, Iterator<RedisClient> iterator) {
List<CompletableFuture<?>> futures = new ArrayList<>();
CompletionStage<RedisURI> masterFuture = checkMasterChange(cfg, connection);
CompletionStage<RedisClient> masterFuture = checkMasterChange(cfg, connection);
futures.add(masterFuture.toCompletableFuture());
if (!config.checkSkipSlavesInit()) {
@ -491,24 +491,22 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
});
}
private CompletionStage<RedisURI> checkMasterChange(SentinelServersConfig cfg, RedisConnection connection) {
private CompletionStage<RedisClient> checkMasterChange(SentinelServersConfig cfg, RedisConnection connection) {
RFuture<RedisURI> masterFuture = connection.async(StringCodec.INSTANCE, masterHostCommand, cfg.getMasterName());
return masterFuture.thenCompose(u -> serviceManager.resolveIP(scheme, u))
.whenComplete((newMaster, e) -> {
if (e != null) {
return;
}
RedisURI current = currentMaster.get();
if (!newMaster.equals(current)
&& currentMaster.compareAndSet(current, newMaster)) {
CompletableFuture<RedisClient> changeFuture = changeMaster(singleSlotRange.getStartSlot(), newMaster);
changeFuture.exceptionally(ex -> {
currentMaster.compareAndSet(newMaster, current);
return null;
return masterFuture
.thenCompose(u -> serviceManager.resolveIP(scheme, u))
.thenCompose(newMaster -> {
RedisURI current = currentMaster.get();
if (!newMaster.equals(current)
&& currentMaster.compareAndSet(current, newMaster)) {
CompletableFuture<RedisClient> changeFuture = changeMaster(singleSlotRange.getStartSlot(), newMaster);
return changeFuture.exceptionally(ex -> {
currentMaster.compareAndSet(newMaster, current);
return null;
});
}
return CompletableFuture.completedFuture(null);
});
}
});
}
private void updateSentinels(Collection<RedisURI> newUris) {

Loading…
Cancel
Save