Skip to content

Commit ae0b967

Browse files
committed
optimize typo
1 parent 65e2358 commit ae0b967

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/LeastActiveLoadBalance.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation
3737
int leastActive = -1; // The least active value of all invokers
3838
int leastCount = 0; // The number of invokers having the same least active value (leastActive)
3939
int[] leastIndexs = new int[length]; // The index of invokers having the same least active value (leastActive)
40-
int taotalWeightWithWarmUp = 0; // The sum of with warmup weights
41-
int firstWeightWithWarmUp = 0; // Initial value, used for comparision
40+
int totalWeight = 0; // The sum of with warmup weights
41+
int firstWeight = 0; // Initial value, used for comparision
4242
boolean sameWeight = true; // Every invoker has the same weight value?
4343
for (int i = 0; i < length; i++) {
4444
Invoker<T> invoker = invokers.get(i);
@@ -48,15 +48,15 @@ protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation
4848
leastActive = active; // Record the current least active value
4949
leastCount = 1; // Reset leastCount, count again based on current leastCount
5050
leastIndexs[0] = i; // Reset
51-
taotalWeightWithWarmUp = afterWarmup; // Reset
52-
firstWeightWithWarmUp = afterWarmup; // Record the weight the first invoker
51+
totalWeight = afterWarmup; // Reset
52+
firstWeight = afterWarmup; // Record the weight the first invoker
5353
sameWeight = true; // Reset, every invoker has the same weight value?
5454
} else if (active == leastActive) { // If current invoker's active value equals with leaseActive, then accumulating.
5555
leastIndexs[leastCount++] = i; // Record index number of this invoker
56-
taotalWeightWithWarmUp += afterWarmup; // Add this invoker's with warmup weight to totalWeightWithWarmUp.
56+
totalWeight += afterWarmup; // Add this invoker's with warmup weight to totalWeight.
5757
// If every invoker has the same weight?
5858
if (sameWeight && i > 0
59-
&& afterWarmup != firstWeightWithWarmUp) {
59+
&& afterWarmup != firstWeight) {
6060
sameWeight = false;
6161
}
6262
}
@@ -66,9 +66,9 @@ protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation
6666
// If we got exactly one invoker having the least active value, return this invoker directly.
6767
return invokers.get(leastIndexs[0]);
6868
}
69-
if (!sameWeight && taotalWeightWithWarmUp > 0) {
70-
// If (not every invoker has the same weight & at least one invoker's weight>0), select randomly based on totalWeightWithWarmUp.
71-
int offsetWeight = ThreadLocalRandom.current().nextInt(taotalWeightWithWarmUp) + 1;
69+
if (!sameWeight && totalWeight > 0) {
70+
// If (not every invoker has the same weight & at least one invoker's weight>0), select randomly based on totalWeight.
71+
int offsetWeight = ThreadLocalRandom.current().nextInt(totalWeight) + 1;
7272
// Return a invoker based on the random value.
7373
for (int i = 0; i < leastCount; i++) {
7474
int leastIndex = leastIndexs[i];
@@ -77,7 +77,7 @@ protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation
7777
return invokers.get(leastIndex);
7878
}
7979
}
80-
// If all invokers have the same weight value or totalWeightWithWarmUp=0, return evenly.
80+
// If all invokers have the same weight value or totalWeight=0, return evenly.
8181
return invokers.get(leastIndexs[ThreadLocalRandom.current().nextInt(leastCount)]);
8282
}
8383
}

0 commit comments

Comments
 (0)