-
Notifications
You must be signed in to change notification settings - Fork 26.4k
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
[Dubbo-5871][Dubbo-5885][Dubbo-5899] Fix nacos registry not work bug since 2.7.6 #5902
[Dubbo-5871][Dubbo-5885][Dubbo-5899] Fix nacos registry not work bug since 2.7.6 #5902
Conversation
Sync with official master branch
@@ -169,12 +170,33 @@ private void doSubscribe(final URL url, final NotifyListener listener, final Set | |||
execute(namingService -> { | |||
for (String serviceName : serviceNames) { | |||
List<Instance> instances = namingService.getAllInstances(serviceName); | |||
|
|||
//TO FIX bug with https://github.com/apache/dubbo/issues/5885 | |||
if (CollectionUtils.isEmpty(instances) && isServiceNamesWithCompatibleMode(url)) { |
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.
这里有个问题,目前你的更改应该只能解决instances为空的问题,但是没解决不为空的情况下,其中一个serviceName触发实例变动导致的覆盖问题。
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.
是的,现在的解决方案存在这个问题。这两个serviceName表示同一个接口,只是因为版本问题产生的两个不同的名字,两个serviceName的instances应该放在一起考虑。我来改下代码
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.
我增加一个实例管理工具类,实现了相关serviceName的实例一起考虑,避免了覆盖问题,同时对instances为空的情况依然能正常处理,测试功能正常,之前的bug已经解决。
/** | ||
* serviceName -> corresponding serviceName list | ||
*/ | ||
private static final Map<String, Set<String>> correspondingServiceNamesMap = Maps.newHashMap(); |
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.
这里是不是应该考虑并发问题,用ConcurrentHashMap比较合适?
/** | ||
* serviceName -> refreshed instance list | ||
*/ | ||
private static final Map<String, List<Instance>> serviceInstanceListMap = Maps.newHashMap(); |
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.
同下
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.
已更新
有个冲突顺便解决下 |
已经解决 |
Codecov Report
@@ Coverage Diff @@
## master #5902 +/- ##
============================================
- Coverage 61.31% 61.23% -0.08%
- Complexity 498 499 +1
============================================
Files 981 982 +1
Lines 39106 39147 +41
Branches 5620 5628 +8
============================================
- Hits 23976 23971 -5
- Misses 12515 12561 +46
Partials 2615 2615
Continue to review full report at Codecov.
|
LGTM |
@htynkn Please help me to merge this PR |
...gistry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
Show resolved
Hide resolved
…since 2.7.6 (apache#5902) * apache#5902 * TO FIX bug with apache#5885 * Avoid instances overwriting problem with different service name * Avoid duplicated service name which will lead duplicated subscribe * Use ConcurrentHashMap instead of HashMap * Format codes (cherry picked from commit cb12928)
* @return | ||
*/ | ||
private boolean isServiceNamesWithCompatibleMode(final URL url) { | ||
if (!isAdminProtocol(url) && createServiceName(url).isConcrete()) { |
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.
你好,最近看这块代码觉得有点困惑。为什么判断服务是否需要兼容的时候,要通过createServiceName(url).isConcrete()
去判断呢?
What is the purpose of the change
Fix nacos registry not work bug mentioned with #5871
, #5885 and #5899
Brief changelog
Verifying this change
Official Demo works out.
Follow this checklist to help us incorporate your contribution quickly and easily:
[Dubbo-XXX] Fix UnknownException when host config not exist #XXX
. Each commit in the pull request should have a meaningful subject line and body.mvn clean install -DskipTests=false
&mvn clean test-compile failsafe:integration-test
to make sure unit-test and integration-test pass.