From b7799c4440a69baaa2d24e61c45db5abc2e6a67e Mon Sep 17 00:00:00 2001 From: Gabriel Hollies Date: Tue, 14 May 2024 09:14:38 -0400 Subject: [PATCH] Allow retry of NOREPLICAS error * During a failover event where a new redis master is being promoted there is a period of time before the slaves begin to follow the new master. This can lead to write calls failing with NOREPLICAS. This usually happens when min-slaves-to-write is configured as non 0. * This error could occur for a misconfiguration, and reties wouldnt help, but we have found that in practice we see failed writes on most failovers due to this error, and a treating it as retryable would have prevented those exception cases. Signed-off-by: Gabriel Hollies --- .../client/RedisNoReplicasException.java | 29 +++++++++++++++++++ .../client/handler/CommandDecoder.java | 5 +++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 redisson/src/main/java/org/redisson/client/RedisNoReplicasException.java diff --git a/redisson/src/main/java/org/redisson/client/RedisNoReplicasException.java b/redisson/src/main/java/org/redisson/client/RedisNoReplicasException.java new file mode 100644 index 000000000..935f1e958 --- /dev/null +++ b/redisson/src/main/java/org/redisson/client/RedisNoReplicasException.java @@ -0,0 +1,29 @@ +/** + * Copyright (c) 2013-2024 Nikita Koksharov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.redisson.client; + +/** + * This error occurs when Redis a redis master has insufficient slaves to handle a request. + * * + */ +public class RedisNoReplicasException extends RedisRetryException { + + private static final long serialVersionUID = -5658453331593029252L; + + public RedisNoReplicasException(String message) { + super(message); + } +} diff --git a/redisson/src/main/java/org/redisson/client/handler/CommandDecoder.java b/redisson/src/main/java/org/redisson/client/handler/CommandDecoder.java index ee59c7517..666628f60 100644 --- a/redisson/src/main/java/org/redisson/client/handler/CommandDecoder.java +++ b/redisson/src/main/java/org/redisson/client/handler/CommandDecoder.java @@ -410,7 +410,10 @@ public class CommandDecoder extends ReplayingDecoder { } else if (error.startsWith("READONLY")) { data.tryFailure(new RedisReadonlyException(error + ". channel: " + channel + " data: " + data)); - }else { + } else if (error.startsWith("NOREPLICAS")) { + data.tryFailure(new RedisNoReplicasException(error + + ". channel: " + channel + " data: " + data)); + } else { if (data != null) { data.tryFailure(new RedisException(error + ". channel: " + channel + " command: " + LogHelper.toString(data))); } else {