feature required: dubbo should consider empty protection.
when register center lost all provider instance , it's doesn't mean that the consumers are all disconnected from the providers,so the method refreshInvoker(List
` private void refreshInvoker(List
if (invokerUrls != null && invokerUrls.size() == 1 && invokerUrls.get(0) != null
&& Constants.EMPTY_PROTOCOL.equals(invokerUrls.get(0).getProtocol())) {
this.forbidden = true; // Forbid to access
this.methodInvokerMap = null; // Set the method invoker map to null
destroyAllInvokers(); // Close all invokers
} else {
......
`
here when invokerUrls is empty ,all the invokers are destryed, but in fact,ignore it will be more fault tolerance.
dubbo already considered this scenario:
if (invokerUrls.isEmpty() && this.cachedInvokerUrls != null) {
invokerUrls.addAll(this.cachedInvokerUrls);
} else {
this.cachedInvokerUrls = new HashSet<URL>();
this.cachedInvokerUrls.addAll(invokerUrls);//Cached invoker urls, convenient for comparison
}
if (invokerUrls.isEmpty()) {
return;
}
if the addresses from the register center is empty, then the cached address list cachedInvokerUrls will be used.
feel free to reopen this issue if you do not agree.
when register center is zookeeper, the invokerUrls will not be empty,it has one element and the protocol is Constants.EMPTY_PROTOCOL,so the code may not be right.
with which registry center did you experience the problem? we may need to discuss this further.
`
ChildListener zkListener = listeners.get(listener);
if (zkListener == null) {
listeners.putIfAbsent(listener, new ChildListener() {
public void childChanged(String parentPath, List<String> currentChilds) {
ZookeeperRegistry.this.notify(url, listener, toUrlsWithEmpty(url, parentPath, currentChilds));
}
});
zkListener = listeners.get(listener);
}
zkClient.create(path, false);
List<String> children = zkClient.addChildListener(path, zkListener);
if (children != null) {
urls.addAll(toUrlsWithEmpty(url, path, children));
}`
`
private List<URL> toUrlsWithEmpty(URL consumer, String path, List<String> providers) {
List<URL> urls = toUrlsWithoutEmpty(consumer, providers);
if (urls == null || urls.isEmpty()) {
int i = path.lastIndexOf('/');
String category = i < 0 ? path : path.substring(i + 1);
URL empty = consumer.setProtocol(Constants.EMPTY_PROTOCOL).addParameter(Constants.CATEGORY_KEY, category);
urls.add(empty);
}
return urls;
}`
zookeeper ,sorry to did not say clearly at the beginning
here when invokerUrls is empty ,all the invokers are destryed, but in fact,ignore it will be more fault tolerance.
What if we want to clear all invokers when receive a empty list from the registry center? Do you think we should introduce a new mechanism:
- When we want to clear invokers, send a signal explicitly.
- Without an explicit signal, keep using the invokers from the last notification when the latest list we receive is empty.
If this mechanism is what you want, do you have any suggestions on how to achieve this?
It is better to keep "good data" and "bad data" than to lose all data, I will chose the second choice .but impl it to abstract strategy will be the final solution.
Agree with your "bad data better than to lose all data" theory.
My question is, if we always keep the "bad data", for example, if we don't destroy all invokers when receive an empty url list, when should we clear all invokers, shouldn't there be another signal? In some scenarios, e.g., Graceful Shutdown, Offline, we need to destroy all invokers.
registry just provide infomation about providers ,but don't control the real action that the consumer should take,so just let the consumer to control the lifecycle of the invokers,for examples, use timeout or fuse strategy when it's only has 'bad data' .
I re-examine the code, and I apologize for my mis-interpretation for
if (invokerUrls.isEmpty() && this.cachedInvokerUrls != null) {
invokerUrls.addAll(this.cachedInvokerUrls);
} else {
this.cachedInvokerUrls = new HashSet<URL>();
this.cachedInvokerUrls.addAll(invokerUrls);//Cached invoker urls, convenient for comparison
}
if (invokerUrls.isEmpty()) {
return;
}
Dubbo doesn't have protection mechanism when empty set of addresses is pushed. We should consider it.
Agree with your "bad data better than to lose all data" theory.
My question is, if we always keep the "bad data", for example, if we don't destroy all invokers when receive an empty url list, when should we clear all invokers, shouldn't there be another signal? In some scenarios, e.g., Graceful Shutdown, Offline, we need to destroy all invokers.
I think we can keep bad data, call it in the original way, destroy the caller, in the Provider there is a readonly mechanism to end the caller, or gracefully go offline to end the caller, and the life cycle of the caller should not be over Controlled by the data in the registry
@chickenlj If there is no objection to this, I will change this mechanism in the next version.
If we add null protection, there will be some potential problems. If there is really no address available, there will be many meaningless connections due to null protection. This will take up a lot of threads to wait for the connection to time out, which will affect other normal calls and even cause the entire application to hang up.
@AlbumenJ I agree with your concerns. Indefinite space protection will cause some connections to be unreleased. We can try to assume a scenario where no connection is available: 1、The provider goes offline normally: In this scenario, readonly will be sent to the consumer in theory, and the connection can be released at this time 2、The provider went offline abnormally and did not send readonly: This scenario theoretically requires some keep-alive mechanism on the consumer side to release the connection 3、The exception of the registry leads to the push of empty connections: In this scenario, we should ensure that the existing links can communicate normally, rather than destroying them.
side effect of empty protection: consumer always reconnect destroyed provider (include those providers which URL were already changed) https://github.com/apache/dubbo/issues/9623 https://github.com/apache/dubbo/issues/8752