From f3d134d2c234a5dab8cc03e92803d52fa4710d71 Mon Sep 17 00:00:00 2001 From: liqipeng Date: Fri, 24 Jun 2022 15:06:47 +0800 Subject: [PATCH] [ISSUE #8594] makes distro data load timeout can be configured. (#8595) * makes distro data load timeout can be configured. * specify nacos.core.protocol.distro.data.load.timeoutMs default 30s --- .../nacos/core/distributed/distro/DistroConfig.java | 12 ++++++++++++ .../core/distributed/distro/DistroConstants.java | 4 ++++ .../distro/task/load/DistroLoadDataTask.java | 8 ++++++++ .../distro/v2/DistroClientTransportAgent.java | 3 ++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/alibaba/nacos/core/distributed/distro/DistroConfig.java b/core/src/main/java/com/alibaba/nacos/core/distributed/distro/DistroConfig.java index 4b90db397a0..09b4145d96b 100644 --- a/core/src/main/java/com/alibaba/nacos/core/distributed/distro/DistroConfig.java +++ b/core/src/main/java/com/alibaba/nacos/core/distributed/distro/DistroConfig.java @@ -42,6 +42,8 @@ public class DistroConfig extends AbstractDynamicConfig { private long loadDataRetryDelayMillis = DistroConstants.DEFAULT_DATA_LOAD_RETRY_DELAY_MILLISECONDS; + private long loadDataTimeoutMillis = DistroConstants.DEFAULT_DATA_LOAD_TIMEOUT_MILLISECONDS; + private DistroConfig() { super(DISTRO); resetConfig(); @@ -61,6 +63,8 @@ protected void getConfigFromEnv() { DistroConstants.DEFAULT_DATA_VERIFY_TIMEOUT_MILLISECONDS); loadDataRetryDelayMillis = EnvUtil.getProperty(DistroConstants.DATA_LOAD_RETRY_DELAY_MILLISECONDS, Long.class, DistroConstants.DEFAULT_DATA_LOAD_RETRY_DELAY_MILLISECONDS); + loadDataTimeoutMillis = EnvUtil.getProperty(DistroConstants.DATA_LOAD_TIMEOUT_MILLISECONDS, Long.class, + DistroConstants.DEFAULT_DATA_LOAD_TIMEOUT_MILLISECONDS); } public static DistroConfig getInstance() { @@ -115,6 +119,14 @@ public void setLoadDataRetryDelayMillis(long loadDataRetryDelayMillis) { this.loadDataRetryDelayMillis = loadDataRetryDelayMillis; } + public long getLoadDataTimeoutMillis() { + return loadDataTimeoutMillis; + } + + public void setLoadDataTimeoutMillis(long loadDataTimeoutMillis) { + this.loadDataTimeoutMillis = loadDataTimeoutMillis; + } + @Override protected String printConfig() { return "DistroConfig{" + "syncDelayMillis=" + syncDelayMillis + ", syncTimeoutMillis=" + syncTimeoutMillis diff --git a/core/src/main/java/com/alibaba/nacos/core/distributed/distro/DistroConstants.java b/core/src/main/java/com/alibaba/nacos/core/distributed/distro/DistroConstants.java index fab551de70c..1a0b3e1bdaa 100644 --- a/core/src/main/java/com/alibaba/nacos/core/distributed/distro/DistroConstants.java +++ b/core/src/main/java/com/alibaba/nacos/core/distributed/distro/DistroConstants.java @@ -47,4 +47,8 @@ public class DistroConstants { public static final long DEFAULT_DATA_LOAD_RETRY_DELAY_MILLISECONDS = 30000L; + public static final String DATA_LOAD_TIMEOUT_MILLISECONDS = "nacos.core.protocol.distro.data.load.timeoutMs"; + + public static final long DEFAULT_DATA_LOAD_TIMEOUT_MILLISECONDS = 30000L; + } diff --git a/core/src/main/java/com/alibaba/nacos/core/distributed/distro/task/load/DistroLoadDataTask.java b/core/src/main/java/com/alibaba/nacos/core/distributed/distro/task/load/DistroLoadDataTask.java index 5cd5523f6e2..29885daf67b 100644 --- a/core/src/main/java/com/alibaba/nacos/core/distributed/distro/task/load/DistroLoadDataTask.java +++ b/core/src/main/java/com/alibaba/nacos/core/distributed/distro/task/load/DistroLoadDataTask.java @@ -98,9 +98,13 @@ private boolean loadAllDataSnapshotFromRemote(String resourceType) { return false; } for (Member each : memberManager.allMembersWithoutSelf()) { + long startTime = System.currentTimeMillis(); try { Loggers.DISTRO.info("[DISTRO-INIT] load snapshot {} from {}", resourceType, each.getAddress()); DistroData distroData = transportAgent.getDatumSnapshot(each.getAddress()); + Loggers.DISTRO.info("[DISTRO-INIT] it took {} ms to load snapshot {} from {} and snapshot size is {}.", + System.currentTimeMillis() - startTime, resourceType, each.getAddress(), + getDistroDataLength(distroData)); boolean result = dataProcessor.processSnapshot(distroData); Loggers.DISTRO .info("[DISTRO-INIT] load snapshot {} from {} result: {}", resourceType, each.getAddress(), @@ -116,6 +120,10 @@ private boolean loadAllDataSnapshotFromRemote(String resourceType) { return false; } + private static int getDistroDataLength(DistroData distroData) { + return distroData != null && distroData.getContent() != null ? distroData.getContent().length : 0; + } + private boolean checkCompleted() { if (distroComponentHolder.getDataStorageTypes().size() != loadCompletedMap.size()) { return false; diff --git a/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/v2/DistroClientTransportAgent.java b/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/v2/DistroClientTransportAgent.java index b25453cc1de..6c20ad2248e 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/v2/DistroClientTransportAgent.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/v2/DistroClientTransportAgent.java @@ -174,7 +174,8 @@ public DistroData getDatumSnapshot(String targetServer) { DistroDataRequest request = new DistroDataRequest(); request.setDataOperation(DataOperation.SNAPSHOT); try { - Response response = clusterRpcClientProxy.sendRequest(member, request); + Response response = clusterRpcClientProxy.sendRequest(member, request, + DistroConfig.getInstance().getLoadDataTimeoutMillis()); if (checkResponse(response)) { return ((DistroDataResponse) response).getDistroData(); } else {