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: fix eureka always refreshCluster error #4235

Merged
merged 14 commits into from
Jan 7, 2022

Conversation

lcmvs
Copy link
Contributor

@lcmvs lcmvs commented Dec 27, 2021

  • I have registered the PR changes.

Ⅰ. Describe what this PR did

new InetSocketAddress的时候,会去检查ip和端口,某些特殊情况,传到eureka上面的端口号可能为-1,开发环境偶尔遇到过,然后会一直refreshCluster失败,实际上可能只是某个服务实例传到eureka上面的端口号不正确,导致全部实例全部都无法刷新了。所以在这里catch一下这个检查参数的异常。

Ⅱ. 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

@codecov-commenter
Copy link

codecov-commenter commented Dec 27, 2021

Codecov Report

Merging #4235 (422477d) into develop (7c9a875) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             develop    #4235   +/-   ##
==========================================
  Coverage      48.84%   48.84%           
  Complexity      3802     3802           
==========================================
  Files            724      724           
  Lines          24238    24238           
  Branches        2972     2971    -1     
==========================================
  Hits           11839    11839           
  Misses         11159    11159           
  Partials        1240     1240           

@funky-eyes
Copy link
Contributor

这个pr并没有修复bug吧?只不过把异常打印出来了,如果port是-1,不应该去解决为什么是-1的问题吗?

@lcmvs
Copy link
Contributor Author

lcmvs commented Dec 28, 2021

这个pr并没有修复bug吧?只不过把异常打印出来了,如果port是-1,不应该去解决为什么是-1的问题吗?

端口号为-1的问题,seata也解决不了啊,这个是从eureka拿到的数据,服务注册到eureka的数据本身就不合法,但是不应该因为一个实例的数据不合法,让所有的实例都不能刷新啊。

catch的好处是,不会因为某一个实例注册的eureka的,ip端口数据不合法,而导致其他没问题的实例refresh也失败。

@funky-eyes
Copy link
Contributor

为何不通过register来防止server注册错误的port,以及在server上寻找为什么是-1的port呢?

@lcmvs
Copy link
Contributor Author

lcmvs commented Dec 28, 2021

为何不通过register来防止server注册错误的port,以及在server上寻找为什么是-1的port呢?

不是很明白你的意思啊。
你的意思是说我们提前检查一下eureka实例信息的ip端口,而不是等它抛异常catch?

@funky-eyes
Copy link
Contributor

为何不通过register来防止server注册错误的port,以及在server上寻找为什么是-1的port呢?

不是很明白你的意思啊。 你的意思是说我们提前检查一下eureka实例信息的ip端口,而不是等它抛异常catch?

在tc也就是seata-server进行registry的时候进行注册,client这个检查可以保留,以防有新老版本server共存的情况
我们要治标,就得在server端的registry时检查为什么port变成了-1

@lcmvs
Copy link
Contributor Author

lcmvs commented Dec 28, 2021

我大概明白你的意思了,你应该是以为tc注册到eureka的ip端口不合法是吧?

List<Application> applications = getEurekaClient(false).getApplications().getRegisteredApplications();

但是她这里实际上不是只拿了tc注册的信息,而是eureka上面全部服务的注册信息。我这里出现ip端口不合法也不是因为某个tc不合法,而是其他注册到eureka上面的业务服务导致的。

其实我也不是很明白为啥注册的eureka上的所有服务信息都要保存起来。按道理不是应该只需要保存一下tc的实例信息吗?

而且每10s更新这一大堆实例信息,也会对客户端性能有点影响吧?

@funky-eyes
Copy link
Contributor

我大概明白你的意思了,你应该是以为tc注册到eureka的ip端口不合法是吧?

List<Application> applications = getEurekaClient(false).getApplications().getRegisteredApplications();

但是她这里实际上不是只拿了tc注册的信息,而是eureka上面全部服务的注册信息。我这里出现ip端口不合法也不是因为某个tc不合法,而是其他注册到eureka上面的业务服务导致的。

其实我也不是很明白为啥注册的eureka上的所有服务信息都要保存起来。按道理不是应该只需要保存一下tc的实例信息吗?

而且每10s更新这一大堆实例信息,也会对客户端性能有点影响吧?

这里做的有点问题,application= clusterName的哪些才需要被遍历,你帮忙一起处理下?

@lcmvs
Copy link
Contributor Author

lcmvs commented Dec 28, 2021

我大概明白你的意思了,你应该是以为tc注册到eureka的ip端口不合法是吧?

List<Application> applications = getEurekaClient(false).getApplications().getRegisteredApplications();

但是她这里实际上不是只拿了tc注册的信息,而是eureka上面全部服务的注册信息。我这里出现ip端口不合法也不是因为某个tc不合法,而是其他注册到eureka上面的业务服务导致的。
其实我也不是很明白为啥注册的eureka上的所有服务信息都要保存起来。按道理不是应该只需要保存一下tc的实例信息吗?
而且每10s更新这一大堆实例信息,也会对客户端性能有点影响吧?

这里做的有点问题,application= clusterName的哪些才需要被遍历,你帮忙一起处理下?

@funky-eyes funky-eyes added this to the 1.5.0 milestone Dec 28, 2021
@funky-eyes funky-eyes added module/discovery discovery module type: bug Category issues or prs related to bug. labels Dec 28, 2021
private void refreshCluster() {
List<Application> applications = getEurekaClient(false).getApplications().getRegisteredApplications();
private void refreshCluster(String clusterName) {
Application application = getEurekaClient(false).getApplications().getRegisteredApplications(clusterName);
Copy link
Contributor

Choose a reason for hiding this comment

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

直接getApplication(clusterName) 是否可以使用? 而不是拿所有的applications里的clustername

Copy link
Contributor Author

@lcmvs lcmvs Dec 29, 2021

Choose a reason for hiding this comment

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

试了一下,也可以,不过好像区别不大。
@OverRide
public Application getApplication(String appName) {
return getApplications().getRegisteredApplications(appName);
}

}

clusterAddressMap = collect;
clusterAddressMap.put(clusterName, list);
Copy link
Contributor

@funky-eyes funky-eyes Jan 1, 2022

Choose a reason for hiding this comment

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

不要put,还是按之前的走,否则在集群切换的时候,之前的集群地址会残留在内存里没法清除

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

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 做一下pr登记

Copy link
Member

@xingfudeshi xingfudeshi left a comment

Choose a reason for hiding this comment

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

LGTM.

@lcmvs lcmvs changed the title bugfix: fix eureka always refreshCluster error optimize: fix eureka always refreshCluster error Jan 7, 2022
@funky-eyes funky-eyes merged commit 6fa8e91 into apache:develop Jan 7, 2022
Copy link
Member

@slievrly slievrly left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/discovery discovery module type: bug Category issues or prs related to bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants