Skip to content

Commit

Permalink
[ISSUE #8594] makes distro data load timeout can be configured. (#8595)
Browse files Browse the repository at this point in the history
* makes distro data load timeout can be configured.

* specify nacos.core.protocol.distro.data.load.timeoutMs default 30s
  • Loading branch information
liqipeng authored Jun 24, 2022
1 parent 2a4c281 commit f3d134d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f3d134d

Please sign in to comment.