Skip to content

Commit

Permalink
[ISSUE #4583] Fix DOMAIN mode retry logic (#4584)
Browse files Browse the repository at this point in the history
* fix namingProxy domain retry logic; add retry param namingRequestDomainMaxRetryCount

* add maxRetry param
  • Loading branch information
lexburner authored Dec 28, 2020
1 parent a2ea808 commit 5236287
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public class PropertyKeyConst {
public static final String NAMING_CLIENT_BEAT_THREAD_COUNT = "namingClientBeatThreadCount";

public static final String NAMING_POLLING_THREAD_COUNT = "namingPollingThreadCount";


public static final String NAMING_REQUEST_DOMAIN_RETRY_COUNT = "namingRequestDomainMaxRetryCount";

/**
* Get the key value of some variable value from the system property.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.alibaba.nacos.common.http.param.Header;
import com.alibaba.nacos.common.http.param.Query;
import com.alibaba.nacos.common.lifecycle.Closeable;
import com.alibaba.nacos.common.utils.ConvertUtils;
import com.alibaba.nacos.common.utils.HttpMethod;
import com.alibaba.nacos.common.utils.IoUtils;
import com.alibaba.nacos.common.utils.IPUtil;
Expand Down Expand Up @@ -107,6 +108,8 @@ public class NamingProxy implements Closeable {
private Properties properties;

private ScheduledExecutorService executorService;

private int maxRetry;

public NamingProxy(String namespaceId, String endpoint, String serverList, Properties properties) {

Expand All @@ -115,6 +118,9 @@ public NamingProxy(String namespaceId, String endpoint, String serverList, Prope
this.setServerPort(DEFAULT_SERVER_PORT);
this.namespaceId = namespaceId;
this.endpoint = endpoint;
this.maxRetry = ConvertUtils.toInt(properties.getProperty(PropertyKeyConst.NAMING_REQUEST_DOMAIN_RETRY_COUNT,
String.valueOf(UtilAndComs.REQUEST_DOMAIN_RETRY_COUNT)));

if (StringUtils.isNotEmpty(serverList)) {
this.serverList = Arrays.asList(serverList.split(","));
if (this.serverList.size() == 1) {
Expand Down Expand Up @@ -513,7 +519,20 @@ public String reqApi(String api, Map<String, String> params, Map<String, String>
}

NacosException exception = new NacosException();


if (StringUtils.isNotBlank(nacosDomain)) {
for (int i = 0; i < maxRetry; i++) {
try {
return callServer(api, params, body, nacosDomain, method);
} catch (NacosException e) {
exception = e;
if (NAMING_LOGGER.isDebugEnabled()) {
NAMING_LOGGER.debug("request {} failed.", nacosDomain, e);
}
}
}
}

if (servers != null && !servers.isEmpty()) {

Random random = new Random(System.currentTimeMillis());
Expand All @@ -533,19 +552,6 @@ public String reqApi(String api, Map<String, String> params, Map<String, String>
}
}

if (StringUtils.isNotBlank(nacosDomain)) {
for (int i = 0; i < UtilAndComs.REQUEST_DOMAIN_RETRY_COUNT; i++) {
try {
return callServer(api, params, body, nacosDomain, method);
} catch (NacosException e) {
exception = e;
if (NAMING_LOGGER.isDebugEnabled()) {
NAMING_LOGGER.debug("request {} failed.", nacosDomain, e);
}
}
}
}

NAMING_LOGGER.error("request: {} failed, servers: {}, code: {}, msg: {}", api, servers, exception.getErrCode(),
exception.getErrMsg());

Expand Down

0 comments on commit 5236287

Please sign in to comment.