mirror of
https://github.com/signalapp/Signal-Server
synced 2026-02-27 08:03:19 +00:00
Temporarily catch and log all script execution exceptions to avoid opening the breaker.
This commit is contained in:
committed by
Jon Chambers
parent
dcb11f7606
commit
b3a778b89a
@@ -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<String> keys, final List<String> args) {
|
||||
return redisCluster.withWriteCluster(connection -> {
|
||||
final RedisAdvancedClusterCommands<String, String> 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<String, String> 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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user