Skip to content
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

optimize: redis registry push empty protection optimize #6164

Merged
merged 24 commits into from
Dec 21, 2023

Conversation

laywin
Copy link
Contributor

@laywin laywin commented Dec 16, 2023

  • I have registered the PR changes.

Ⅰ. Describe what this PR did

当收到 redis 注册中心 回调的服务器下线消息时,检查 服务器地址 是否是地址列表中唯一的地址 并且 回调的集群是当前使用的集群,如果是开启 空推 保护,否则 将该服务器地址移除掉.
when receive server offline message from redis registry check the serverAddr is unique in the address list and
the callback cluster is current cluster, then enable push-empty protection
Otherwise, remove it.

Ⅱ. Does this pull request fix one issue?

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

Copy link

codecov bot commented Dec 16, 2023

Codecov Report

Merging #6164 (5749426) into 2.x (501d431) will increase coverage by 0.04%.
Report is 1 commits behind head on 2.x.
The diff coverage is 46.66%.

❗ Current head 5749426 differs from pull request most recent head fca1868. Consider uploading reports for the commit fca1868 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##                2.x    #6164      +/-   ##
============================================
+ Coverage     48.98%   49.03%   +0.04%     
- Complexity     4782     4797      +15     
============================================
  Files           913      915       +2     
  Lines         31697    31861     +164     
  Branches       3823     3842      +19     
============================================
+ Hits          15528    15622      +94     
- Misses        14632    14684      +52     
- Partials       1537     1555      +18     
Files Coverage Δ
...n/java/io/seata/core/rpc/netty/ChannelManager.java 0.00% <ø> (ø)
...va/io/seata/integration/tx/api/util/DubboUtil.java 0.00% <0.00%> (ø)
...overy/registry/redis/RedisRegistryServiceImpl.java 67.28% <50.00%> (ø)

... and 6 files with indirect coverage changes

if (socketAddresses.size() == 1 && socketAddresses.contains(inetSocketAddress)) {
String txServiceGroupName = ConfigurationFactory.getInstance()
.getConfig(ConfigurationKeys.TX_SERVICE_GROUP);
String clusterName = getServiceGroup(txServiceGroupName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check txServiceGroupName if null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

看了一下,当 txServiceGroupName 是null的时候也没问题,真实环境,txServiceGroupName 基本不可能为空吧.
i see no problem for the situation when txServiceGroupName is null, but in real environment, txServiceGroupName almost impossible to be null.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is that if txServiceGroupName is null, you should not use it as a parameter to get the clusterName.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already optimized it.

if (socketAddresses.size() == 1 && socketAddresses.contains(inetSocketAddress)) {
String txServiceGroupName = ConfigurationFactory.getInstance()
.getConfig(ConfigurationKeys.TX_SERVICE_GROUP);
String clusterName = getServiceGroup(txServiceGroupName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经有clustername了,为什么还要通过事务分组再次读取?
I already have clustername, why read it again through transaction grouping?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notifyCluserName 是注册中心回调通知的clusterName, 需要和当前正在使用的clusterName做对比.
notifyCluserName is the clusterName of the registration center callback notification, which needs to be compared with the clusterName currently in use.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clusterName

为什么要跟当前的做对比?而不是直接用他回调的去删除缓存中的? 变化的是回调的那个cluster,如果你不需要改变,为什么不是取消对其的订阅?
Why compare it with the current one? Instead of directly using what he called back to delete the one in the cache? What changes is the cluster that called back. If you don't need to change it, why not unsubscribe to it?


Set<InetSocketAddress> socketAddresses = CLUSTER_ADDRESS_MAP.getOrDefault(notifyCluserName, Collections.emptySet());
InetSocketAddress inetSocketAddress = NetUtil.toInetSocketAddress(serverAddr);
if (socketAddresses.size() == 1 && socketAddresses.contains(inetSocketAddress)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请考虑并发性问题
Please consider concurrency issues

public void accept(RedisMessage redisMessage) {
reentrantLock.lock();
try {
if (redisMessage.getMessageType() == MessageType.SUBSCRIBE) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么messagetype不是add或者remove?而是scan和SUBSCRIBE?我希望是scan那部分找到的列表能跟当前的cluster中的集合做对比,将需要add或者remove的事件发出,而不是在这里面写ifelse,结果还是各玩各的。我希望这里只是一个动作触发,要么是remove,要么是add
Why is messagetype not add or remove? But scan and SUBSCRIBE? I hope that the list found in the scan part can be compared with the collection in the current cluster, and the events that need to be added or removed will be sent out, instead of writing ifelse in it, the result is still different. I hope this is just an action trigger, either remove or add.

@codecov-commenter
Copy link

Welcome to Codecov 🎉

Once merged to your default branch, Codecov will compare your coverage reports and display the results in this comment.

Thanks for integrating Codecov - We've got you covered ☂️

…teIfAbsent, there is a performance problem in jdk8.

2. optimize unit test.
@funky-eyes funky-eyes closed this Dec 21, 2023
@funky-eyes funky-eyes reopened this Dec 21, 2023
@funky-eyes funky-eyes added this to the 2.1.0 milestone Dec 21, 2023
Copy link
Contributor

@funky-eyes funky-eyes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@funky-eyes funky-eyes merged commit ab474eb into apache:2.x Dec 21, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants