Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
PeppaO committed Nov 2, 2023
1 parent 9933244 commit 043fa11
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ public static JedisPoolAbstract getJedisPoolInstance(JedisPoolAbstract... jedisP
Set<String> sentinels = new HashSet<>(SENTINEL_HOST_NUMBER);
String[] sentinelHosts = CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_SENTINEL_HOST).split(",");
Arrays.asList(sentinelHosts).forEach(sentinelHost -> sentinels.add(sentinelHost));
String sentinelPassword = CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_SENTINEL_PASSWORD);
if (StringUtils.isBlank(password)) {
sentinelPassword = null;
}
tempJedisPool = new JedisSentinelPool(masterName, sentinels, poolConfig, 60000, 60000, password, CONFIGURATION.getInt(ConfigurationKeys.STORE_REDIS_DATABASE, DATABASE),
null, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_SENTINEL_PASSWORD), null);
null, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, sentinelPassword, null);
} else if (mode.equals(ConfigurationKeys.REDIS_SINGLE_MODE)) {
String host = CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_SINGLE_HOST);
host = StringUtils.isBlank(host) ? CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_HOST, HOST) : host;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -49,7 +50,7 @@ public class LuaParser {

private static final String ANNOTATION_LUA = "--";

private static String ACQUIRE_LUA_FILE;
private static Map<String, String> LUA_FILE_MAP = new HashMap<>();

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

Expand Down Expand Up @@ -129,6 +130,7 @@ public static Map<String, String> getEvalShaMapFromFile(String fileName) throws
} catch (IOException e) {
throw new IOException(e);
}
LUA_FILE_MAP.put(fileName, luaByFile.toString());
Map<String, String> resultMap = new ConcurrentHashMap<>(1);
try (Jedis jedis = JedisPooledFactory.getJedisInstance()) {
resultMap.put(fileName, jedis.scriptLoad(luaByFile.toString()));
Expand Down Expand Up @@ -156,13 +158,13 @@ public static <T> List<T> getListFromJson(String json, Class<T> classz) {
}
}

public static String jedisEvalSha(Jedis jedis, String luaSHA, String luaFileName, List<String> keys, List<String> args){
public static Object jedisEvalSha(Jedis jedis, String luaSHA, String luaFileName, List<String> keys, List<String> args){
try {
return (String)jedis.evalsha(luaSHA, keys, args);
return jedis.evalsha(luaSHA, keys, args);
}catch (JedisNoScriptException e) {
LOGGER.warn("jedis ex:" + e.getMessage());
jedis.scriptLoad(luaFileName);
return (String)jedis.evalsha(luaSHA, keys, args);
LOGGER.warn("jedis ex: " + e.getMessage());
jedis.scriptLoad(LUA_FILE_MAP.get(luaFileName));
return jedis.evalsha(luaSHA, keys, args);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public boolean acquireLock(List<RowLock> rowLocks, boolean autoCommit, boolean s
// reset args index 2
args.set(1, String.valueOf(args.size()));

String result = LuaParser.jedisEvalSha(jedis, luaSHA, ACQUIRE_LOCK_LUA_FILE_NAME, keys, args);
String result = (String)LuaParser.jedisEvalSha(jedis, luaSHA, ACQUIRE_LOCK_LUA_FILE_NAME, keys, args);

LuaParser.LuaResult luaResult = LuaParser.getObjectFromJson(result, LuaParser.LuaResult.class);

Expand Down Expand Up @@ -208,7 +208,7 @@ public boolean isLockable(List<RowLock> rowLocks) {
keys.addAll(lockKeys);
List<String> args = new ArrayList<>();
args.add(xid);
String res = LuaParser.jedisEvalSha(jedis, luaSHA, LOCKABLE_LUA_FILE_NAME, keys, args);
String res = (String)LuaParser.jedisEvalSha(jedis, luaSHA, LOCKABLE_LUA_FILE_NAME, keys, args);
return "true".equals(res);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ protected boolean updateBranchTransactionDO(BranchTransactionDO branchTransactio
add(applicationData);
}
};
String result = LuaParser.jedisEvalSha(jedis, luaSHA, UPDATE_BRANCH_TRANSACTION_DO_LUA_FILE_NAME, keys, args);
String result = (String)LuaParser.jedisEvalSha(jedis, luaSHA, UPDATE_BRANCH_TRANSACTION_DO_LUA_FILE_NAME, keys, args);
LuaParser.LuaResult luaResult = LuaParser.getObjectFromJson(result, LuaParser.LuaResult.class);
if (!luaResult.getSuccess()) {
throw new StoreException("Branch transaction is not exist, update branch transaction failed.");
Expand Down Expand Up @@ -323,7 +323,7 @@ protected boolean updateGlobalTransactionDO(GlobalTransactionDO globalTransactio
add(xid);
}
};
String result = LuaParser.jedisEvalSha(jedis, luaSHA, UPDATE_GLOBAL_TRANSACTION_DO_LUA_FILE_NAME, keys, args);
String result = (String)LuaParser.jedisEvalSha(jedis, luaSHA, UPDATE_GLOBAL_TRANSACTION_DO_LUA_FILE_NAME, keys, args);
LuaParser.LuaResult luaResult = LuaParser.getObjectFromJson(result, LuaParser.LuaResult.class);
// fail
if (!luaResult.getSuccess()) {
Expand Down

0 comments on commit 043fa11

Please sign in to comment.