New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bugfix: fix the issue that the Lua script is not synchronized when the redis sentinel master node is down #5990
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo:之所以把lua脚本外置,而不是在源码中,是为了发现lua脚本执行有bug的时候可以人工介入修正脚本,重新进行scriptload,但是目前看来这是个伪需求,等待真实需求的用户出现后,再进行重新记录sha1编码的行为也不迟.目前来看,这个pr的处理已经足够了,即便存在线程安全的问题,如scriptload可能会执行多次,但是对于执行结果而言没有影响,且master节点宕机概率并不会太高,没有必要做到分布式下的线程安全,可以考虑下单节点是否避免多次scriptload,以lua文件名为粒度做锁
The reason why the lua script external, rather than in the source code, is to find the lua script execution has a bug when you can manually intervene to correct the script, re-scriptload, but at present it seems that this is a pseudo-need to follow up on the real needs of users can wait for the emergence of users, and then re-record the optimization of sha1 encoding is not too late. At present, this pr processing is already enough, even if there are thread-safety issues, such as scriptload may be executed more than once, but for the implementation of the results have no impact, and the probability of downtime of the master node will not be too high, there is no need to do the distributed thread-safety, you can consider whether the next single node to avoid multiple scriptload, to lua file name as the granularity of the lock
|
||
private static final String WHITE_SPACE = " "; | ||
|
||
private static final String ANNOTATION_LUA = "--"; | ||
|
||
private static Map<String, String> LUA_FILE_MAP = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static final
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
try { | ||
return jedis.evalsha(luaSHA, keys, args); | ||
}catch (JedisNoScriptException e) { | ||
LOGGER.warn("jedis ex: " + e.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里日志要提示一下,否则用户会认为异常了,但实际上我们继续了reload script和重新执行了lua脚本
Here the logs should be prompted, otherwise the user will think it's an exception, but in fact we continue the reload script and re-execute the lua script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## 2.x #5990 +/- ##
============================================
- Coverage 49.29% 48.56% -0.73%
+ Complexity 4734 4668 -66
============================================
Files 911 911
Lines 31305 31297 -8
Branches 3772 3768 -4
============================================
- Hits 15432 15200 -232
- Misses 14339 14584 +245
+ Partials 1534 1513 -21
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Ⅰ. Describe what this PR did
redis主从复制,当主节点宕机后,从节点选举为主,当遇到NOSCRIPT异常时,重新script load一遍
Ⅱ. Does this pull request fix one issue?
#5936
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews