From b3a778b89a442d4cd00b3ca39aa8db72b30b64cc Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Mon, 6 Jul 2020 17:50:54 -0400 Subject: [PATCH] Temporarily catch and log all script execution exceptions to avoid opening the breaker. --- .../textsecuregcm/redis/ClusterLuaScript.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/redis/ClusterLuaScript.java b/service/src/main/java/org/whispersystems/textsecuregcm/redis/ClusterLuaScript.java index c6361ffb5..9e540fa57 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/redis/ClusterLuaScript.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/redis/ClusterLuaScript.java @@ -7,6 +7,8 @@ import io.lettuce.core.api.sync.RedisCommands; import io.lettuce.core.cluster.SlotHash; import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands; import io.lettuce.core.cluster.models.partitions.RedisClusterNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -22,6 +24,8 @@ public class ClusterLuaScript { private static final String[] STRING_ARRAY = new String[0]; + private static final Logger log = LoggerFactory.getLogger(ClusterLuaScript.class); + public static ClusterLuaScript fromResource(final FaultTolerantRedisCluster redisCluster, final String resource, final ScriptOutputType scriptOutputType) throws IOException { try (final InputStream inputStream = LuaScript.class.getClassLoader().getResourceAsStream(resource); final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { @@ -47,13 +51,18 @@ public class ClusterLuaScript { public Object execute(final List keys, final List args) { return redisCluster.withWriteCluster(connection -> { - final RedisAdvancedClusterCommands clusterCommands = connection.sync(); - try { - return clusterCommands.evalsha(sha, scriptOutputType, keys.toArray(STRING_ARRAY), args.toArray(STRING_ARRAY)); - } catch (final RedisNoScriptException e) { - clusterCommands.scriptLoad(script); - return clusterCommands.evalsha(sha, scriptOutputType, keys.toArray(STRING_ARRAY), args.toArray(STRING_ARRAY)); + final RedisAdvancedClusterCommands clusterCommands = connection.sync(); + + try { + return clusterCommands.evalsha(sha, scriptOutputType, keys.toArray(STRING_ARRAY), args.toArray(STRING_ARRAY)); + } catch (final RedisNoScriptException e) { + clusterCommands.scriptLoad(script); + return clusterCommands.evalsha(sha, scriptOutputType, keys.toArray(STRING_ARRAY), args.toArray(STRING_ARRAY)); + } + } catch (final Exception e) { + log.warn("Failed to execute script", e); + return null; } }); }