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/incubator-dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new afcb9f2 Limit the times of registry retry. (#2946)
afcb9f2 is described below
commit afcb9f2b8dc3bde308750d8ca832c3d8183b2c42
Author: 时无两丶 <[email protected]>
AuthorDate: Thu Dec 13 17:07:17 2018 +0800
Limit the times of registry retry. (#2946)
The default value is 3.
---
.../java/org/apache/dubbo/common/Constants.java | 10 ++++++++++
.../dubbo/registry/retry/AbstractRetryTask.java | 23 +++++++++++++++++++---
2 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java
index 9265287..c6f8b1f 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java
@@ -488,11 +488,21 @@ public class Constants {
public static final String REGISTRY_RETRY_PERIOD_KEY = "retry.period";
/**
+ * Most retry times
+ */
+ public static final String REGISTRY_RETRY_TIMES_KEY = "retry.times";
+
+ /**
* Default value for the period of retry interval in milliseconds: 5000
*/
public static final int DEFAULT_REGISTRY_RETRY_PERIOD = 5 * 1000;
/**
+ * Default value for the times of retry: 3
+ */
+ public static final int DEFAULT_REGISTRY_RETRY_TIMES = 3;
+
+ /**
* Reconnection period in milliseconds for register center
*/
public static final String REGISTRY_RECONNECT_PERIOD_KEY =
"reconnect.period";
diff --git
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/retry/AbstractRetryTask.java
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/retry/AbstractRetryTask.java
index b299b2f..fcbea5f 100644
---
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/retry/AbstractRetryTask.java
+++
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/retry/AbstractRetryTask.java
@@ -49,12 +49,23 @@ public abstract class AbstractRetryTask implements
TimerTask {
/**
* retry period
*/
- protected final long retryPeriod;
+ final long retryPeriod;
+
+ /**
+ * define the most retry times
+ */
+ private final int retryTimes;
/**
* task name for this task
*/
- protected final String taskName;
+ private final String taskName;
+
+ /**
+ * times of retry.
+ * retry task is execute in single thread so that the times is not need
volatile.
+ */
+ private int times = 1;
private volatile boolean cancel;
@@ -67,6 +78,7 @@ public abstract class AbstractRetryTask implements TimerTask {
this.taskName = taskName;
cancel = false;
this.retryPeriod =
url.getParameter(Constants.REGISTRY_RETRY_PERIOD_KEY,
Constants.DEFAULT_REGISTRY_RETRY_PERIOD);
+ this.retryTimes = url.getParameter(Constants.REGISTRY_RETRY_TIMES_KEY,
Constants.DEFAULT_REGISTRY_RETRY_TIMES);
}
public void cancel() {
@@ -86,7 +98,7 @@ public abstract class AbstractRetryTask implements TimerTask {
if (timer.isStop() || timeout.isCancelled() || isCancel()) {
return;
}
-
+ times++;
timer.newTimeout(timeout.task(), tick, TimeUnit.MILLISECONDS);
}
@@ -96,6 +108,11 @@ public abstract class AbstractRetryTask implements
TimerTask {
// other thread cancel this timeout or stop the timer.
return;
}
+ if (times > retryTimes) {
+ // reach the most times of retry.
+ logger.warn("Final failed to execute task " + taskName + ", url: "
+ url + ", retry " + retryTimes + " times.");
+ return;
+ }
if (logger.isInfoEnabled()) {
logger.info(taskName + " : " + url);
}