-
Notifications
You must be signed in to change notification settings - Fork 26.5k
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-4793]make RegistryDirectory can refresh the invokers when providers number become 0 when using nacos registry #4802
Changes from all commits
954b0f3
45d5572
e78ec79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
package org.apache.dubbo.registry.nacos; | ||
|
||
import org.apache.dubbo.common.URL; | ||
import org.apache.dubbo.common.URLBuilder; | ||
import org.apache.dubbo.common.logger.Logger; | ||
import org.apache.dubbo.common.logger.LoggerFactory; | ||
import org.apache.dubbo.common.utils.UrlUtils; | ||
|
@@ -35,7 +36,6 @@ | |
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.LinkedHashSet; | ||
import java.util.LinkedList; | ||
|
@@ -59,6 +59,7 @@ | |
import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY; | ||
import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMERS_CATEGORY; | ||
import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_CATEGORY; | ||
import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL; | ||
import static org.apache.dubbo.common.constants.RegistryConstants.PROVIDERS_CATEGORY; | ||
import static org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGORY; | ||
import static org.apache.dubbo.registry.Constants.ADMIN_PROTOCOL; | ||
|
@@ -369,15 +370,26 @@ private List<String> doGetServiceNames(URL url) { | |
return serviceNames; | ||
} | ||
|
||
private List<URL> buildURLs(URL consumerURL, Collection<Instance> instances) { | ||
if (instances.isEmpty()) { | ||
return Collections.emptyList(); | ||
private List<URL> toUrlWithEmpty(URL consumerURL, Collection<Instance> instances) { | ||
List<URL> urls = buildURLs(consumerURL, instances); | ||
if (urls.size() == 0) { | ||
URL empty = URLBuilder.from(consumerURL) | ||
.setProtocol(EMPTY_PROTOCOL) | ||
.addParameter(CATEGORY_KEY, DEFAULT_CATEGORY) | ||
.build(); | ||
urls.add(empty); | ||
} | ||
return urls; | ||
} | ||
|
||
private List<URL> buildURLs(URL consumerURL, Collection<Instance> instances) { | ||
List<URL> urls = new LinkedList<>(); | ||
for (Instance instance : instances) { | ||
URL url = buildURL(instance); | ||
if (UrlUtils.isMatch(consumerURL, url)) { | ||
urls.add(url); | ||
if (instances != null && !instances.isEmpty()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we don't need to check whether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For String or Collection, I think not only null, but also size check are needed because the for each will create useless iterator object. |
||
for (Instance instance : instances) { | ||
URL url = buildURL(instance); | ||
if (UrlUtils.isMatch(consumerURL, url)) { | ||
urls.add(url); | ||
} | ||
} | ||
} | ||
return urls; | ||
|
@@ -406,9 +418,11 @@ private void subscribeEventListener(String serviceName, final URL url, final Not | |
*/ | ||
private void notifySubscriber(URL url, NotifyListener listener, Collection<Instance> instances) { | ||
List<Instance> healthyInstances = new LinkedList<>(instances); | ||
// Healthy Instances | ||
filterHealthyInstances(healthyInstances); | ||
List<URL> urls = buildURLs(url, healthyInstances); | ||
if (healthyInstances.size() > 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If healthyInstances is empty, this still works? Not sure, could u pls check it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. I think it's a fail-fast term. |
||
// Healthy Instances | ||
filterHealthyInstances(healthyInstances); | ||
} | ||
List<URL> urls = toUrlWithEmpty(url, healthyInstances); | ||
NacosRegistry.this.notify(url, listener, urls); | ||
} | ||
|
||
|
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.
Last nitpick, what about changing
toUrlWithEmpty
totoUrlsWhenEmpty
? (justone suggestion, there should be another better method name to make it clear)
I know we use
toUrlWithEmpty
in zookeeperRegistry.class, but I found the name may bring us a little confusion :)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.
The name tells that the protocol will be set "empty"