optimize: ensure that the register message is sent after RM client initialization #2968
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ⅰ. Describe what this PR did
【情况说明】
当资源注册(ResourceManager.registerResource)先于RM初始化(RMClient.init)时会打印错误日志,不过由于RMClient初始化后会有定时连接检测,所以对业务的影响只是在连接检测被触发之前资源不会被注册到TC,连接检测启动延迟目前为1分钟。(AbstractNettyRemotingClient.SCHEDULE_DELAY_MILLS = 60 * 1000L)。
错误日志:
Failed to get available servers: endpoint format should like ip:port
【原因分析】:
由于资源注册时RM还没有初始化,所以此时transactionServiceGroup为空!
【解决方案】:
RmNettyRemotingClient.registerResource 加上transactionServiceGroup是否为空的检查
延迟注册,注册资源时如果RM尚未初始化则先不连接,待RM初始化时检查有已注册的RM则连接后将资源一并注册到TC
Ⅱ. Does this pull request fix one issue?
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
【复现方法】:
1、样例代码 直接将POM中seata版本切换为1.3运行
日志中会找到错误:Failed to get available servers: endpoint format should like ip:port
2、简化代码后发现,只要当资源注册先于RM初始化就会复现问题。可以将样例代码中的RM初始化部分简化为如下形式,可复现问题。同时可见,一分钟后连接检测时会自动修复问题。
3、进一步分析发现,如果初始化先于资源注册,则无此问题。
【验证方式】:
修正后,无论先注册资源还是先初始化RM,都不会报错,且当资源注册先于RM初始化时,会在RM初始化后立即将资源注册到TC
Ⅴ. Special notes for reviews