Skip to content

fix:fix incorrect empty metadata data handling. #74

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

Merged

Conversation

SkyeBeFreeman
Copy link
Member

@SkyeBeFreeman SkyeBeFreeman commented Apr 7, 2025

fix #75

实例更新流程

核心逻辑源码:org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener#doOnEvent

  1. 当dubbo订阅(subscribe)URL的时候,会绑定实例变更监听器(ServiceInstancesChangedListener)。
Clipboard_Screenshot_1744081783
  1. 在polaris-dubbo-java中,将绑定polaris-java定义的变更监听器(InnerServiceListener)与之对应。
Clipboard_Screenshot_1744081819
  1. 实例更新时,会触发实例变更监听器的doOnEvent方法。
Clipboard_Screenshot_1744082765
  1. 实例变更监听器从新的实例列表,解析出revision映射到实例列表的map。
Clipboard_Screenshot_1744083392
  1. 针对每个revision,先从实例中获取service metadata,如果没有,再去远端拉取service metadata。
Clipboard_Screenshot_1744083423
  1. 将获取的service metadata塞回实例内。
Clipboard_Screenshot_1744083578
  1. 最后构造url,并刷新
Clipboard_Screenshot_1744083664

原有逻辑

在上述流程的第5步,获取到service metadata拉取到空值,也会正常更新。例如下方serviceInfos为空map,也正常返回了。
Clipboard_Screenshot_1744084454

解决方案

  1. 可以借助dubbo的metadata异常处理流程来完成service metadata的拉取。也就是serviceInfos为空map时,返回dubbo框架内指定的空值,MetadataInfo.EMPTY

  2. dubbo框架在获取远端service metadata时,如果拿到了MetadataInfo.EMPTY,则会重试2次,且每次重试间隔1000ms。源码:org.apache.dubbo.registry.client.AbstractServiceDiscovery#getRemoteMetadata(java.lang.String, java.util.List<org.apache.dubbo.registry.client.ServiceInstance>)

  3. 如果重试后还是为MetadataInfo.EMPTY,则会走到实例变更监听器重试逻辑。这个重试逻辑会判断是否有实例存在空的service metadata,则会提交一个重试任务,等待10000ms后,重新触发整个url列表的变更。

Clipboard_Screenshot_1744094778
  1. 经过两层重试后,便可正确获取service metadata,即使是北极星AP架构。

Copy link
Member

@andrewshan andrewshan left a comment

Choose a reason for hiding this comment

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

LGTM

@andrewshan andrewshan merged commit 1951fc4 into polarismesh:dubbo-3.2.x Apr 8, 2025
2 checks passed
@SkyeBeFreeman SkyeBeFreeman deleted the 3.2/optimize-contract branch April 8, 2025 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

应用级注册metadata更新问题
4 participants