dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

feature required: dubbo should consider empty protection.

Open slolitor opened this issue 8 years ago • 14 comments

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 invokerUrls) ; in registrydirectory is not so fault tolerance.the method code is :

` private void refreshInvoker(List invokerUrls) {

    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.

slolitor avatar Mar 26 '18 04:03 slolitor

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.

beiwei30 avatar Apr 08 '18 02:04 beiwei30

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.

slolitor avatar Apr 08 '18 03:04 slolitor

with which registry center did you experience the problem? we may need to discuss this further.

beiwei30 avatar Apr 08 '18 03:04 beiwei30

`

              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

slolitor avatar Apr 08 '18 03:04 slolitor

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:

  1. When we want to clear invokers, send a signal explicitly.
  2. 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?

chickenlj avatar Apr 11 '18 09:04 chickenlj

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.

slolitor avatar Apr 11 '18 10:04 slolitor

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.

chickenlj avatar Apr 13 '18 01:04 chickenlj

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

slolitor avatar Apr 13 '18 02:04 slolitor

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.

beiwei30 avatar Feb 19 '19 07:02 beiwei30

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

CrazyHZM avatar Sep 25 '21 05:09 CrazyHZM

@chickenlj If there is no objection to this, I will change this mechanism in the next version.

CrazyHZM avatar Sep 25 '21 05:09 CrazyHZM

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 avatar Sep 27 '21 11:09 AlbumenJ

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

CrazyHZM avatar Sep 28 '21 08:09 CrazyHZM

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

zrlw avatar Apr 19 '22 11:04 zrlw