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; } }); }