This is an automated email from the ASF dual-hosted git repository.
earthchen pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.2 by this push:
new 271d5eff29 Update minimal reconnect period (#12639)
271d5eff29 is described below
commit 271d5eff293ac0820273186a1763a07d65fde5de
Author: Albumen Kevin <[email protected]>
AuthorDate: Mon Jul 3 10:27:56 2023 +0800
Update minimal reconnect period (#12639)
---
.../src/main/java/org/apache/dubbo/remoting/Constants.java | 7 +++++++
.../remoting/exchange/support/header/HeaderExchangeClient.java | 10 +++++++++-
.../dubbo/remoting/transport/netty/ClientReconnectTest.java | 4 +++-
.../dubbo/remoting/transport/netty4/ClientReconnectTest.java | 5 ++++-
4 files changed, 23 insertions(+), 3 deletions(-)
diff --git
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Constants.java
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Constants.java
index e3dfee7da7..ece265989d 100644
---
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Constants.java
+++
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Constants.java
@@ -63,6 +63,13 @@ public interface Constants {
*/
long LEAST_HEARTBEAT_DURATION = 1000;
+ /**
+ * the least reconnect during is 60000 ms.
+ */
+ long LEAST_RECONNECT_DURATION = 60000;
+
+ String LEAST_RECONNECT_DURATION_KEY =
"dubbo.application.least-reconnect-duration";
+
/**
* ticks per wheel.
*/
diff --git
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/header/HeaderExchangeClient.java
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/header/HeaderExchangeClient.java
index f776e9e5d7..0adf656604 100644
---
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/header/HeaderExchangeClient.java
+++
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/header/HeaderExchangeClient.java
@@ -37,6 +37,8 @@ import java.util.concurrent.TimeUnit;
import static org.apache.dubbo.remoting.Constants.HEARTBEAT_CHECK_TICK;
import static org.apache.dubbo.remoting.Constants.LEAST_HEARTBEAT_DURATION;
+import static org.apache.dubbo.remoting.Constants.LEAST_RECONNECT_DURATION;
+import static org.apache.dubbo.remoting.Constants.LEAST_RECONNECT_DURATION_KEY;
import static org.apache.dubbo.remoting.Constants.TICKS_PER_WHEEL;
import static org.apache.dubbo.remoting.utils.UrlUtils.getHeartbeat;
import static org.apache.dubbo.remoting.utils.UrlUtils.getIdleTimeout;
@@ -214,7 +216,8 @@ public class HeaderExchangeClient implements ExchangeClient
{
private void startReconnectTask(URL url) {
if (shouldReconnect(url)) {
long heartbeatTimeoutTick = calculateLeastDuration(idleTimeout);
- reconnectTimerTask = new ReconnectTimerTask(() ->
Collections.singleton(this), IDLE_CHECK_TIMER.get(), heartbeatTimeoutTick,
idleTimeout);
+ reconnectTimerTask = new ReconnectTimerTask(() ->
Collections.singleton(this), IDLE_CHECK_TIMER.get(),
+ calculateReconnectDuration(url, heartbeatTimeoutTick),
idleTimeout);
}
}
@@ -240,6 +243,11 @@ public class HeaderExchangeClient implements
ExchangeClient {
}
}
+ private long calculateReconnectDuration(URL url, long tick) {
+ long leastReconnectDuration =
url.getParameter(LEAST_RECONNECT_DURATION_KEY, LEAST_RECONNECT_DURATION);
+ return Math.max(leastReconnectDuration, tick);
+ }
+
private boolean shouldReconnect(URL url) {
return url.getParameter(Constants.RECONNECT_KEY, true);
}
diff --git
a/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/ClientReconnectTest.java
b/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/ClientReconnectTest.java
index f4229aa56d..37183b94cb 100644
---
a/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/ClientReconnectTest.java
+++
b/dubbo-remoting/dubbo-remoting-netty/src/test/java/org/apache/dubbo/remoting/transport/netty/ClientReconnectTest.java
@@ -29,11 +29,13 @@ import org.apache.dubbo.remoting.exchange.Exchangers;
import org.apache.dubbo.remoting.exchange.support.ExchangeHandlerAdapter;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.FrameworkModel;
+
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static
org.apache.dubbo.common.constants.CommonConstants.EXECUTOR_MANAGEMENT_MODE_DEFAULT;
+import static org.apache.dubbo.remoting.Constants.LEAST_RECONNECT_DURATION_KEY;
/**
* Client reconnect test
@@ -76,7 +78,7 @@ class ClientReconnectTest {
public Client startClient(int port, int heartbeat) throws
RemotingException {
URL url = URL.valueOf("exchange://127.0.0.1:" + port +
"/client.reconnect.test?check=false&codec=exchange&client=netty3&" +
- Constants.HEARTBEAT_KEY + "=" + heartbeat);
+ Constants.HEARTBEAT_KEY + "=" + heartbeat + "&" +
LEAST_RECONNECT_DURATION_KEY + "=0");
ApplicationModel applicationModel = ApplicationModel.defaultModel();
ApplicationConfig applicationConfig = new
ApplicationConfig("provider-app");
applicationConfig.setExecutorManagementMode(EXECUTOR_MANAGEMENT_MODE_DEFAULT);
diff --git
a/dubbo-remoting/dubbo-remoting-netty4/src/test/java/org/apache/dubbo/remoting/transport/netty4/ClientReconnectTest.java
b/dubbo-remoting/dubbo-remoting-netty4/src/test/java/org/apache/dubbo/remoting/transport/netty4/ClientReconnectTest.java
index 369108ea6b..ff15bda516 100644
---
a/dubbo-remoting/dubbo-remoting-netty4/src/test/java/org/apache/dubbo/remoting/transport/netty4/ClientReconnectTest.java
+++
b/dubbo-remoting/dubbo-remoting-netty4/src/test/java/org/apache/dubbo/remoting/transport/netty4/ClientReconnectTest.java
@@ -32,11 +32,13 @@ import
org.apache.dubbo.remoting.exchange.support.ExchangeHandlerAdapter;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.ModuleModel;
+
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static
org.apache.dubbo.common.constants.CommonConstants.EXECUTOR_MANAGEMENT_MODE_DEFAULT;
+import static org.apache.dubbo.remoting.Constants.LEAST_RECONNECT_DURATION_KEY;
/**
* Client reconnect test
@@ -81,7 +83,8 @@ class ClientReconnectTest {
public Client startClient(int port, int heartbeat) throws
RemotingException {
- URL url = URL.valueOf("exchange://127.0.0.1:" + port +
"/client.reconnect.test?client=netty4&check=false&" + Constants.HEARTBEAT_KEY +
"=" + heartbeat);
+ URL url = URL.valueOf("exchange://127.0.0.1:" + port +
"/client.reconnect.test?client=netty4&check=false&" +
+ Constants.HEARTBEAT_KEY + "=" + heartbeat + "&" +
LEAST_RECONNECT_DURATION_KEY + "=0");
FrameworkModel frameworkModel = new FrameworkModel();
ApplicationModel applicationModel = frameworkModel.newApplication();
ApplicationConfig applicationConfig = new
ApplicationConfig("provider-app");