Skip to content

Commit 758b551

Browse files
committed
Set load balance to default value if it is null
1 parent b185422 commit 758b551

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/support/AbstractClusterInvoker.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ public void destroy() {
8888

8989
/**
9090
* Select a invoker using loadbalance policy.</br>
91-
* 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</br>
92-
* 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.
91+
* a)Firstly, select an invoker using loadbalance. If this invoker is in previously selected list, or,
92+
* if this invoker is unavailable, then continue step b (reselect), otherwise return the first selected invoker</br>
93+
* b)Reslection, the validation rule for reselection: selected > available. This rule guarantees that
94+
* the selected invoker has the minimum chance to be one in the previously selected list, and also
95+
* guarantees this invoker is available.
9396
*
9497
* @param loadbalance load balance policy
9598
* @param invocation
@@ -109,22 +112,22 @@ protected Invoker<T> select(LoadBalance loadbalance, Invocation invocation, List
109112
if (stickyInvoker != null && !invokers.contains(stickyInvoker)) {
110113
stickyInvoker = null;
111114
}
112-
//ignore cucurrent problem
115+
//ignore concurrency problem
113116
if (sticky && stickyInvoker != null && (selected == null || !selected.contains(stickyInvoker))) {
114117
if (availablecheck && stickyInvoker.isAvailable()) {
115118
return stickyInvoker;
116119
}
117120
}
118121
}
119-
Invoker<T> invoker = doselect(loadbalance, invocation, invokers, selected);
122+
Invoker<T> invoker = doSelect(loadbalance, invocation, invokers, selected);
120123

121124
if (sticky) {
122125
stickyInvoker = invoker;
123126
}
124127
return invoker;
125128
}
126129

127-
private Invoker<T> doselect(LoadBalance loadbalance, Invocation invocation, List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {
130+
private Invoker<T> doSelect(LoadBalance loadbalance, Invocation invocation, List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {
128131
if (invokers == null || invokers.isEmpty())
129132
return null;
130133
if (invokers.size() == 1)
@@ -133,6 +136,9 @@ private Invoker<T> doselect(LoadBalance loadbalance, Invocation invocation, List
133136
if (invokers.size() == 2 && selected != null && !selected.isEmpty()) {
134137
return selected.get(0) == invokers.get(0) ? invokers.get(1) : invokers.get(0);
135138
}
139+
if (loadbalance == null) {
140+
loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE);
141+
}
136142
Invoker<T> invoker = loadbalance.select(invokers, getUrl(), invocation);
137143

138144
//If the `invoker` is in the `selected` or invoker is unavailable && availablecheck is true, reselect.
@@ -216,17 +222,12 @@ private Invoker<T> reselect(LoadBalance loadbalance, Invocation invocation,
216222
}
217223

218224
public Result invoke(final Invocation invocation) throws RpcException {
219-
220225
checkWhetherDestroyed();
221-
222-
LoadBalance loadbalance;
223-
226+
LoadBalance loadbalance = null;
224227
List<Invoker<T>> invokers = list(invocation);
225228
if (invokers != null && !invokers.isEmpty()) {
226229
loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(invokers.get(0).getUrl()
227230
.getMethodParameter(invocation.getMethodName(), Constants.LOADBALANCE_KEY, Constants.DEFAULT_LOADBALANCE));
228-
} else {
229-
loadbalance = null;
230231
}
231232
RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation);
232233
return doInvoke(invocation, invokers, loadbalance);

0 commit comments

Comments
 (0)