You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by il...@apache.org on 2019/08/19 12:14:40 UTC
[dubbo] branch master updated: Fix warm up issue when provider's
timestamp is bigger than local machine's timestamp. (#4870)
This is an automated email from the ASF dual-hosted git repository.
iluo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new a025cc1 Fix warm up issue when provider's timestamp is bigger than local machine's timestamp. (#4870)
a025cc1 is described below
commit a025cc1446d38e8a195d23c59f81cb3e02f22769
Author: aftersss <hw...@duiba.com.cn>
AuthorDate: Mon Aug 19 20:14:32 2019 +0800
Fix warm up issue when provider's timestamp is bigger than local machine's timestamp. (#4870)
* Fix warm up issue when provider's timestamp is bigger than local machine's timestamp.
* Remove unused constant: `REMOTE_TIMESTAMP_KEY`.
---
.../main/java/org/apache/dubbo/rpc/cluster/Constants.java | 2 --
.../dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java | 14 ++++++++++----
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Constants.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Constants.java
index 9303a9a..6c699ab 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Constants.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/Constants.java
@@ -89,8 +89,6 @@ public interface Constants {
String RUNTIME_KEY = "runtime";
- String REMOTE_TIMESTAMP_KEY = "remote.timestamp";
-
String WARMUP_KEY = "warmup";
int DEFAULT_WARMUP = 10 * 60 * 1000;
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java
index 0446610..3ae6403 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java
@@ -24,9 +24,9 @@ import org.apache.dubbo.rpc.cluster.LoadBalance;
import java.util.List;
+import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.DEFAULT_WARMUP;
import static org.apache.dubbo.rpc.cluster.Constants.DEFAULT_WEIGHT;
-import static org.apache.dubbo.rpc.cluster.Constants.REMOTE_TIMESTAMP_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.WARMUP_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.WEIGHT_KEY;
@@ -73,12 +73,18 @@ public abstract class AbstractLoadBalance implements LoadBalance {
int getWeight(Invoker<?> invoker, Invocation invocation) {
int weight = invoker.getUrl().getMethodParameter(invocation.getMethodName(), WEIGHT_KEY, DEFAULT_WEIGHT);
if (weight > 0) {
- long timestamp = invoker.getUrl().getParameter(REMOTE_TIMESTAMP_KEY, 0L);
+ long timestamp = invoker.getUrl().getParameter(TIMESTAMP_KEY, 0L);
if (timestamp > 0L) {
- int uptime = (int) (System.currentTimeMillis() - timestamp);
+ long uptime = System.currentTimeMillis() - timestamp;
+ if (uptime >= Integer.MAX_VALUE) {
+ return weight;
+ }
+ else if (uptime < 0) {
+ return 1;
+ }
int warmup = invoker.getUrl().getParameter(WARMUP_KEY, DEFAULT_WARMUP);
if (uptime > 0 && uptime < warmup) {
- weight = calculateWarmupWeight(uptime, warmup, weight);
+ weight = calculateWarmupWeight((int)uptime, warmup, weight);
}
}
}