Skip to content
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

Do not instantiate load balance if there is no invokers (#1297) #1376

Merged
merged 2 commits into from
Feb 24, 2018

Conversation

liketic
Copy link
Contributor

@liketic liketic commented Feb 20, 2018

Currently, we'll instantiate the load balance with a default instance if no invokers found. However, we don't need to use it.

Closes #1297

@codecov-io
Copy link

codecov-io commented Feb 20, 2018

Codecov Report

Merging #1376 into master will decrease coverage by 0.17%.
The diff coverage is 40%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1376      +/-   ##
==========================================
- Coverage   32.58%   32.41%   -0.18%     
==========================================
  Files         691      691              
  Lines       34537    34539       +2     
  Branches     6812     6813       +1     
==========================================
- Hits        11255    11196      -59     
- Misses      21356    21410      +54     
- Partials     1926     1933       +7
Impacted Files Coverage Δ
...bo/rpc/cluster/support/AbstractClusterInvoker.java 67.3% <40%> (-1.32%) ⬇️
...bo/rpc/cluster/support/FailbackClusterInvoker.java 71.79% <0%> (-12.83%) ⬇️
...ba/dubbo/remoting/transport/netty/NettyClient.java 72.58% <0%> (-11.3%) ⬇️
...mon/serialize/support/dubbo/GenericDataOutput.java 67.71% <0%> (-7.72%) ⬇️
...om/alibaba/dubbo/rpc/filter/ActiveLimitFilter.java 83.33% <0%> (-5.56%) ⬇️
...a/dubbo/remoting/transport/netty/NettyChannel.java 61.25% <0%> (-5%) ⬇️
...mmon/serialize/support/dubbo/GenericDataInput.java 59.45% <0%> (-4.25%) ⬇️
...rpc/protocol/dubbo/telnet/InvokeTelnetHandler.java 51.89% <0%> (-3.8%) ⬇️
.../com/alibaba/dubbo/monitor/dubbo/DubboMonitor.java 73.14% <0%> (-2.78%) ⬇️
...main/java/com/alibaba/dubbo/rpc/RpcInvocation.java 15.11% <0%> (-2.33%) ⬇️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2c20d99...758b551. Read the comment docs.

@@ -226,7 +226,7 @@ public Result invoke(final Invocation invocation) throws RpcException {
loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(invokers.get(0).getUrl()
.getMethodParameter(invocation.getMethodName(), Constants.LOADBALANCE_KEY, Constants.DEFAULT_LOADBALANCE));
} else {
loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE);
loadbalance = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

How about remove this else statement and move loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE); to doSelect()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean something like:

    private Invoker<T> doselect(LoadBalance loadbalance, Invocation invocation, List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {
        if (invokers == null || invokers.isEmpty())
            return null;
        if (invokers.size() == 1)
            return invokers.get(0);
        // If we only have two invokers, use round-robin instead.
        if (invokers.size() == 2 && selected != null && !selected.isEmpty()) {
            return selected.get(0) == invokers.get(0) ? invokers.get(1) : invokers.get(0);
        }
        if (loadbalance == null) {
            loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE);
        }
        Invoker<T> invoker = loadbalance.select(invokers, getUrl(), invocation);

        //If the `invoker` is in the  `selected` or invoker is unavailable && availablecheck is true, reselect.
        if ((selected != null && selected.contains(invoker))
                || (!invoker.isAvailable() && getUrl() != null && availablecheck)) {
            try {
                Invoker<T> rinvoker = reselect(loadbalance, invocation, invokers, selected, availablecheck);
                if (rinvoker != null) {
                    invoker = rinvoker;
                } else {
                    //Check the index of current selected invoker, if it's not the last one, choose the one at index+1.
                    int index = invokers.indexOf(invoker);
                    try {
                        //Avoid collision
                        invoker = index < invokers.size() - 1 ? invokers.get(index + 1) : invoker;
                    } catch (Exception e) {
                        logger.warn(e.getMessage() + " may because invokers list dynamic change, ignore.", e);
                    }
                }
            } catch (Throwable t) {
                logger.error("cluster reselect fail reason is :" + t.getMessage() + " if can not solve, you can set cluster.availablecheck=false in url", t);
            }
        }
        return invoker;
    }
    public Result invoke(final Invocation invocation) throws RpcException {

        checkWhetherDestroyed();

        LoadBalance loadbalance = null;
        List<Invoker<T>> invokers = list(invocation);
        if (invokers != null && !invokers.isEmpty()) {
            loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(invokers.get(0).getUrl()
                    .getMethodParameter(invocation.getMethodName(), Constants.LOADBALANCE_KEY, Constants.DEFAULT_LOADBALANCE));
        }
        RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation);
        return doInvoke(invocation, invokers, loadbalance);
    }

If that, I'm not sure why we need to expose loadbalance to doInvoke and select, unless we allow subclass to pass a custom loadbalance to select. Thank you so much!

Copy link
Contributor

Choose a reason for hiding this comment

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

checkInvokers(copyinvokers, invocation); should always be called every time before we actually invoke.

But what if developers extending AbstractClusterInvoker don't do this check? The loadbalance will be null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I pushed 758b551

@chickenlj chickenlj added the status/waiting-for-feedback Need reporters to triage label Feb 22, 2018
@chickenlj chickenlj merged commit c7197b0 into apache:master Feb 24, 2018
@liketic liketic deleted the fix-issues/1297 branch February 24, 2018 07:02
zonghaishang pushed a commit to zonghaishang/dubbo that referenced this pull request Feb 26, 2018
* @reference support annotate on annotation type

* Fixes apache#1303 TimeUnit conversion error

* Fixes apache#1289, use bind_port as mapping key

* Fixes apache#1313, remove destroy check in Registry.

* checkout .travis.yml from origin/master

* Fix hessian2 serialized short, byte is converted to int bug (apache#1232)

* Fix hessian2 serialized short, byte is converted to int bug

* Fix hessian2 serialized short, byte is converted to int bug

* adapt jdk1.5+

* fixed travis-ci failed because of test cases. (apache#1370)

* Merge pull request apache#1377, remove redundant arguments for StatItem.isAllowable()

* Merge pull request apache#1378, replace StringBuider with simple string concatenation in log.

* Merge pull request apache#1375, remove unnecessary boxing.

Fixes apache#1245

* Merge pull request apache#1331, add optional parameter to support hessian protocol method overload and request protocol version.

* Merge pull request apache#1376, do not instantiate load balance if there is no invokers

Fixes apache#1297

* Merge pull request apache#1384, fix build string bug.

* Merge pull request apache#1040, refactor: replace some deprecated methods related with jedis.

* Merge pull request apache#1242, remove redundant null check.

fixes apache#1231
zonghaishang pushed a commit to zonghaishang/dubbo that referenced this pull request Feb 26, 2018
* @reference support annotate on annotation type

* Fixes apache#1303 TimeUnit conversion error

* Fixes apache#1289, use bind_port as mapping key

* Fixes apache#1313, remove destroy check in Registry.

* checkout .travis.yml from origin/master

* Fix hessian2 serialized short, byte is converted to int bug (apache#1232)

* Fix hessian2 serialized short, byte is converted to int bug

* Fix hessian2 serialized short, byte is converted to int bug

* adapt jdk1.5+

* fixed travis-ci failed because of test cases. (apache#1370)

* Merge pull request apache#1377, remove redundant arguments for StatItem.isAllowable()

* Merge pull request apache#1378, replace StringBuider with simple string concatenation in log.

* Merge pull request apache#1375, remove unnecessary boxing.

Fixes apache#1245

* Merge pull request apache#1331, add optional parameter to support hessian protocol method overload and request protocol version.

* Merge pull request apache#1376, do not instantiate load balance if there is no invokers

Fixes apache#1297

* Merge pull request apache#1384, fix build string bug.

* Merge pull request apache#1040, refactor: replace some deprecated methods related with jedis.

* Merge pull request apache#1242, remove redundant null check.

fixes apache#1231

* Change Mailing list address

* Fixed apache#1398, revert bugs introduced from apache#1375

* Fix time unit problem in UT

* Fix time unit problem related with FutureAdapter in UT
zonghaishang pushed a commit to zonghaishang/dubbo that referenced this pull request Mar 2, 2018
* @reference support annotate on annotation type

* Fixes apache#1303 TimeUnit conversion error

* Fixes apache#1289, use bind_port as mapping key

* Fixes apache#1313, remove destroy check in Registry.

* checkout .travis.yml from origin/master

* Fix hessian2 serialized short, byte is converted to int bug (apache#1232)

* Fix hessian2 serialized short, byte is converted to int bug

* Fix hessian2 serialized short, byte is converted to int bug

* adapt jdk1.5+

* fixed travis-ci failed because of test cases. (apache#1370)

* Merge pull request apache#1377, remove redundant arguments for StatItem.isAllowable()

* Merge pull request apache#1378, replace StringBuider with simple string concatenation in log.

* Merge pull request apache#1375, remove unnecessary boxing.

Fixes apache#1245

* Merge pull request apache#1331, add optional parameter to support hessian protocol method overload and request protocol version.

* Merge pull request apache#1376, do not instantiate load balance if there is no invokers

Fixes apache#1297

* Merge pull request apache#1384, fix build string bug.

* Merge pull request apache#1040, refactor: replace some deprecated methods related with jedis.

* Merge pull request apache#1242, remove redundant null check.

fixes apache#1231

* Change Mailing list address

* Fixed apache#1398, revert bugs introduced from apache#1375

* Fix time unit problem in UT

* Fix time unit problem related with FutureAdapter in UT

* Fix time unit problem related with FutureAdapter in UT

* Merge pull request apache#1391, fix typo of method name in qos module.

* fix hessian lite test case fail bug (apache#1394)

* fix hessian lite test case fail bug

* update test

* remove ignore

* Fix time unit problem related with FutureAdapter in UT

* revert file

* fix number type is lost in yaml config file (apache#1401)

* apache#1399 fi

* update test

* update readme to add some details (apache#1403)

* update readme to add some details

update readme to add some details

* delete duplicated words

delete duplicated words

* update README format

*     apache#1411: Locale deserialize 'zh-hant_CN'
xpylq pushed a commit to xpylq/dubbo that referenced this pull request Mar 5, 2018
* remotes/upstream/master: (226 commits)
  clean up imports for CacheTest
  [Dubbo-apache#1362] cache provider always lru cache (apache#1396)
  Remove author info and add apache license
  Fix "promoteTransitiveDependencies=false" of maven-shade-plugin
  apache#1411: Locale deserialize 'zh-hant_CN'
  update README format
  update readme to add some details (apache#1403)
  fix number type is lost in yaml config file (apache#1401)
  fix hessian lite test case fail bug (apache#1394)
  Merge pull request apache#1391, fix typo of method name in qos module.
  Fix time unit problem related with FutureAdapter in UT
  Fix time unit problem related with FutureAdapter in UT
  Fix time unit problem in UT
  Fixed apache#1398, revert bugs introduced from apache#1375
  Change Mailing list address
  Merge pull request apache#1242, remove redundant null check.
  Merge pull request apache#1040, refactor: replace some deprecated methods related with jedis.
  Merge pull request apache#1384, fix build string bug.
  Merge pull request apache#1376, do not instantiate load balance if there is no invokers
  Merge pull request apache#1331, add optional parameter to support hessian protocol method overload and request protocol version.
  ...
rolandhe pushed a commit to rolandhe/dubbo that referenced this pull request Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/waiting-for-feedback Need reporters to triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants