Skip to content

Commit a025cc1

Browse files
aftersssbeiwei30
aftersss
authored andcommitted
Fix warm up issue when provider's timestamp is bigger than local machine's timestamp. (apache#4870)
* Fix warm up issue when provider's timestamp is bigger than local machine's timestamp. * Remove unused constant: `REMOTE_TIMESTAMP_KEY`.
1 parent 00653c3 commit a025cc1

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Constants.java

-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ public interface Constants {
8989

9090
String RUNTIME_KEY = "runtime";
9191

92-
String REMOTE_TIMESTAMP_KEY = "remote.timestamp";
93-
9492
String WARMUP_KEY = "warmup";
9593

9694
int DEFAULT_WARMUP = 10 * 60 * 1000;

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

+10-4
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
import java.util.List;
2626

27+
import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
2728
import static org.apache.dubbo.rpc.cluster.Constants.DEFAULT_WARMUP;
2829
import static org.apache.dubbo.rpc.cluster.Constants.DEFAULT_WEIGHT;
29-
import static org.apache.dubbo.rpc.cluster.Constants.REMOTE_TIMESTAMP_KEY;
3030
import static org.apache.dubbo.rpc.cluster.Constants.WARMUP_KEY;
3131
import static org.apache.dubbo.rpc.cluster.Constants.WEIGHT_KEY;
3232

@@ -73,12 +73,18 @@ public <T> Invoker<T> select(List<Invoker<T>> invokers, URL url, Invocation invo
7373
int getWeight(Invoker<?> invoker, Invocation invocation) {
7474
int weight = invoker.getUrl().getMethodParameter(invocation.getMethodName(), WEIGHT_KEY, DEFAULT_WEIGHT);
7575
if (weight > 0) {
76-
long timestamp = invoker.getUrl().getParameter(REMOTE_TIMESTAMP_KEY, 0L);
76+
long timestamp = invoker.getUrl().getParameter(TIMESTAMP_KEY, 0L);
7777
if (timestamp > 0L) {
78-
int uptime = (int) (System.currentTimeMillis() - timestamp);
78+
long uptime = System.currentTimeMillis() - timestamp;
79+
if (uptime >= Integer.MAX_VALUE) {
80+
return weight;
81+
}
82+
else if (uptime < 0) {
83+
return 1;
84+
}
7985
int warmup = invoker.getUrl().getParameter(WARMUP_KEY, DEFAULT_WARMUP);
8086
if (uptime > 0 && uptime < warmup) {
81-
weight = calculateWarmupWeight(uptime, warmup, weight);
87+
weight = calculateWarmupWeight((int)uptime, warmup, weight);
8288
}
8389
}
8490
}

0 commit comments

Comments
 (0)