diff --git a/dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/support/AbstractClusterInvoker.java b/dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/support/AbstractClusterInvoker.java index bf32bc723db..f2cd281ef86 100644 --- a/dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/support/AbstractClusterInvoker.java +++ b/dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/support/AbstractClusterInvoker.java @@ -88,15 +88,18 @@ public void destroy() { /** * Select a invoker using loadbalance policy.
- * a)Firstly, select an invoker using loadbalance. If this invoker is in previously selected list, or, if this invoker is unavailable, then continue step b (reselect), otherwise return the first selected invoker
- * b)Reslection, the validation rule for reselection: selected > available. This rule guarantees that the selected invoker has the minimum chance to be one in the previously selected list, and also guarantees this invoker is available. + * a)Firstly, select an invoker using loadbalance. If this invoker is in previously selected list, or, + * if this invoker is unavailable, then continue step b (reselect), otherwise return the first selected invoker
+ * b)Reslection, the validation rule for reselection: selected > available. This rule guarantees that + * the selected invoker has the minimum chance to be one in the previously selected list, and also + * guarantees this invoker is available. * * @param loadbalance load balance policy * @param invocation * @param invokers invoker candidates * @param selected exclude selected invokers or not * @return - * @throws RpcExceptione + * @throws RpcException */ protected Invoker select(LoadBalance loadbalance, Invocation invocation, List> invokers, List> selected) throws RpcException { if (invokers == null || invokers.isEmpty()) @@ -109,14 +112,14 @@ protected Invoker select(LoadBalance loadbalance, Invocation invocation, List if (stickyInvoker != null && !invokers.contains(stickyInvoker)) { stickyInvoker = null; } - //ignore cucurrent problem + //ignore concurrency problem if (sticky && stickyInvoker != null && (selected == null || !selected.contains(stickyInvoker))) { if (availablecheck && stickyInvoker.isAvailable()) { return stickyInvoker; } } } - Invoker invoker = doselect(loadbalance, invocation, invokers, selected); + Invoker invoker = doSelect(loadbalance, invocation, invokers, selected); if (sticky) { stickyInvoker = invoker; @@ -124,7 +127,7 @@ protected Invoker select(LoadBalance loadbalance, Invocation invocation, List return invoker; } - private Invoker doselect(LoadBalance loadbalance, Invocation invocation, List> invokers, List> selected) throws RpcException { + private Invoker doSelect(LoadBalance loadbalance, Invocation invocation, List> invokers, List> selected) throws RpcException { if (invokers == null || invokers.isEmpty()) return null; if (invokers.size() == 1) @@ -133,6 +136,9 @@ private Invoker doselect(LoadBalance loadbalance, Invocation invocation, List 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 invoker = loadbalance.select(invokers, getUrl(), invocation); //If the `invoker` is in the `selected` or invoker is unavailable && availablecheck is true, reselect. @@ -153,7 +159,7 @@ private Invoker doselect(LoadBalance loadbalance, Invocation invocation, List } } } catch (Throwable t) { - logger.error("clustor relselect fail reason is :" + t.getMessage() + " if can not slove ,you can set cluster.availablecheck=false in url", 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; @@ -216,17 +222,12 @@ private Invoker reselect(LoadBalance loadbalance, Invocation invocation, } public Result invoke(final Invocation invocation) throws RpcException { - checkWhetherDestroyed(); - - LoadBalance loadbalance; - + LoadBalance loadbalance = null; List> 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)); - } else { - loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE); } RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation); return doInvoke(invocation, invokers, loadbalance);