Skip to content

Commit

Permalink
Merge pull request #12723 from alibaba/develop
Browse files Browse the repository at this point in the history
Upgrade to 2.4.3
  • Loading branch information
KomachiSion authored Oct 12, 2024
2 parents 75e5de6 + f4f8b18 commit f00cfec
Show file tree
Hide file tree
Showing 35 changed files with 355 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: |
mkdir -p ./pr
echo ${{ github.event.number }} > ./pr/NR
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
with:
name: pr
path: pr/
2 changes: 2 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/PropertyKeyConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class PropertyKeyConst {

public static final String CONFIG_RETRY_TIME = "configRetryTime";

public static final String CONFIG_REQUEST_TIMEOUT = "configRequestTimeout";

public static final String CLIENT_WORKER_MAX_THREAD_COUNT = "clientWorkerMaxThreadCount";

public static final String CLIENT_WORKER_THREAD_COUNT = "clientWorkerThreadCount";
Expand Down
1 change: 1 addition & 0 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>**/module-info.class</exclude>
</excludes>
</filter>
<filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public class ClientWorker implements Closeable {

private long timeout;

private long requestTimeout;

private final ConfigRpcTransportClient agent;

private int taskPenaltyTime;
Expand Down Expand Up @@ -405,7 +407,7 @@ public CacheData addCacheDataIfAbsent(String dataId, String group, String tenant
cache.setTaskId(taskId);
// fix issue # 1317
if (enableRemoteSyncConfig) {
ConfigResponse response = getServerConfig(dataId, group, tenant, 3000L, false);
ConfigResponse response = getServerConfig(dataId, group, tenant, requestTimeout, false);
cache.setEncryptedDataKey(response.getEncryptedDataKey());
cache.setContent(response.getContent());
}
Expand Down Expand Up @@ -510,6 +512,8 @@ private int initWorkerThreadCount(NacosClientProperties properties) {

private void init(NacosClientProperties properties) {

requestTimeout = ConvertUtils.toLong(properties.getProperty(PropertyKeyConst.CONFIG_REQUEST_TIMEOUT, "-1"));

timeout = Math.max(ConvertUtils.toInt(properties.getProperty(PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT),
Constants.CONFIG_LONG_POLL_TIMEOUT), Constants.MIN_CONFIG_LONG_POLL_TIMEOUT);

Expand Down Expand Up @@ -927,7 +931,7 @@ private void refreshContentAndCheck(RpcClient rpcClient, CacheData cacheData, bo
try {

ConfigResponse response = this.queryConfigInner(rpcClient, cacheData.dataId, cacheData.group,
cacheData.tenant, 3000L, notify);
cacheData.tenant, requestTimeout, notify);
cacheData.setEncryptedDataKey(response.getEncryptedDataKey());
cacheData.setContent(response.getContent());
if (null != response.getConfigType()) {
Expand Down Expand Up @@ -1198,7 +1202,7 @@ ConfigResponse queryConfigInner(RpcClient rpcClient, String dataId, String group
}

private Response requestProxy(RpcClient rpcClientInner, Request request) throws NacosException {
return requestProxy(rpcClientInner, request, 3000L);
return requestProxy(rpcClientInner, request, requestTimeout);
}

private Response requestProxy(RpcClient rpcClientInner, Request request, long timeoutMills)
Expand All @@ -1217,6 +1221,9 @@ private Response requestProxy(RpcClient rpcClientInner, Request request, long ti
throw new NacosException(NacosException.CLIENT_OVER_THRESHOLD,
"More than client-side current limit threshold");
}
if (timeoutMills < 0) {
return rpcClientInner.request(request);
}
return rpcClientInner.request(request, timeoutMills);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void testPublishConfigSuccess() throws NacosException {
String casMd5 = "1111";

String type = "properties";
Mockito.when(rpcClient.request(any(ConfigPublishRequest.class), anyLong()))
Mockito.when(rpcClient.request(any(ConfigPublishRequest.class)))
.thenReturn(new ConfigPublishResponse());
boolean b = clientWorker.publishConfig(dataId, group, tenant, appName, tag, betaIps, content, null, casMd5,
type);
Expand Down Expand Up @@ -261,7 +261,7 @@ void testPublishConfigFail() throws NacosException {
String casMd5 = "1111";

String type = "properties";
Mockito.when(rpcClient.request(any(ConfigPublishRequest.class), anyLong()))
Mockito.when(rpcClient.request(any(ConfigPublishRequest.class)))
.thenReturn(ConfigPublishResponse.buildFailResponse(503, "over limit"));
boolean b = clientWorker.publishConfig(dataId, group, tenant, appName, tag, betaIps, content, null, casMd5,
type);
Expand Down Expand Up @@ -290,7 +290,7 @@ void testPublishConfigException() throws NacosException {
String casMd5 = "1111";

String type = "properties";
Mockito.when(rpcClient.request(any(ConfigPublishRequest.class), anyLong())).thenThrow(new NacosException());
Mockito.when(rpcClient.request(any(ConfigPublishRequest.class))).thenThrow(new NacosException());
boolean b = clientWorker.publishConfig(dataId, group, tenant, appName, tag, betaIps, content, null, casMd5,
type);
assertFalse(b);
Expand All @@ -313,7 +313,7 @@ void testRemoveConfig() throws NacosException {

String tag = "tag";
try {
Mockito.when(rpcClient.request(any(ConfigRemoveRequest.class), anyLong()))
Mockito.when(rpcClient.request(any(ConfigRemoveRequest.class)))
.thenThrow(new NacosException(503, "overlimit"));

clientWorker.removeConfig(dataId, group, tenant, tag);
Expand Down Expand Up @@ -562,13 +562,13 @@ public void receiveConfigInfo(String configInfo) {
() -> RpcClientFactory.createClient(anyString(), any(ConnectionType.class), any(Map.class),
any(RpcClientTlsConfig.class))).thenReturn(rpcClientInner);
// mock listen and remove listen request
Mockito.when(rpcClientInner.request(any(ConfigBatchListenRequest.class), anyLong()))
Mockito.when(rpcClientInner.request(any(ConfigBatchListenRequest.class)))
.thenReturn(response, response);
// mock query changed config
ConfigQueryResponse configQueryResponse = new ConfigQueryResponse();
configQueryResponse.setContent("content" + System.currentTimeMillis());
configQueryResponse.setContentType(ConfigType.JSON.getType());
Mockito.when(rpcClientInner.request(any(ConfigQueryRequest.class), anyLong())).thenReturn(configQueryResponse);
Mockito.when(rpcClientInner.request(any(ConfigQueryRequest.class))).thenReturn(configQueryResponse);
(clientWorker.getAgent()).executeConfigListen();
//assert
//use local cache.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public ModuleState build() {
moduleState.newState(PropertiesConstant.DEFAULT_MAX_SIZE, PropertyUtil.getDefaultMaxSize());
moduleState.newState(PropertiesConstant.DEFAULT_MAX_AGGR_COUNT, PropertyUtil.getDefaultMaxAggrCount());
moduleState.newState(PropertiesConstant.DEFAULT_MAX_AGGR_SIZE, PropertyUtil.getDefaultMaxAggrSize());

moduleState.newState(Constants.CONFIG_RENTENTION_DAYS_PROPERTY_STATE, PropertyUtil.getConfigRententionDays());

return moduleState;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public class Constants {
public static final String DEFAULT_GROUP = "DEFAULT_GROUP";

public static final String DATASOURCE_PLATFORM_PROPERTY_STATE = "datasource_platform";


public static final String CONFIG_RENTENTION_DAYS_PROPERTY_STATE = "config_retention_days";

/**
* Config file directory in server side.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class PropertiesConstant {
public static final String DUMP_CHANGE_ON = "dumpChangeOn";

public static final String DUMP_CHANGE_WORKER_INTERVAL = "dumpChangeWorkerInterval";



public static final String CONFIG_RENTENTION_DAYS = "nacos.config.retention.days";

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.alibaba.nacos.api.config.remote.request.ClientConfigMetricRequest;
import com.alibaba.nacos.api.config.remote.response.ClientConfigMetricResponse;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.auth.annotation.Secured;
import com.alibaba.nacos.common.http.Callback;
import com.alibaba.nacos.common.http.HttpClientBeanHolder;
Expand All @@ -30,6 +31,7 @@
import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.paramcheck.ConfigDefaultHttpParamExtractor;
import com.alibaba.nacos.config.server.utils.GroupKey2;
import com.alibaba.nacos.config.server.utils.ParamUtils;
import com.alibaba.nacos.core.cluster.Member;
import com.alibaba.nacos.core.cluster.ServerMemberManager;
import com.alibaba.nacos.core.paramcheck.ExtractorManager;
Expand Down Expand Up @@ -86,7 +88,11 @@ public ClientMetricsController(ServerMemberManager serverMemberManager, Connecti
public ResponseEntity metric(@RequestParam("ip") String ip,
@RequestParam(value = "dataId", required = false) String dataId,
@RequestParam(value = "group", required = false) String group,
@RequestParam(value = "tenant", required = false) String tenant) {
@RequestParam(value = "tenant", required = false) String tenant) throws NacosException {

ParamUtils.checkTenant(tenant);
ParamUtils.checkParam(dataId, group, "default", "default");

Loggers.CORE.info("Get cluster config metrics received, ip={},dataId={},group={},tenant={}", ip, dataId, group,
tenant);
Map<String, Object> responseMap = new HashMap<>(3);
Expand Down Expand Up @@ -168,7 +174,11 @@ public void onCancel() {
public Map<String, Object> getClientMetrics(@RequestParam("ip") String ip,
@RequestParam(value = "dataId", required = false) String dataId,
@RequestParam(value = "group", required = false) String group,
@RequestParam(value = "tenant", required = false) String tenant) {
@RequestParam(value = "tenant", required = false) String tenant) throws NacosException {

ParamUtils.checkTenant(tenant);
ParamUtils.checkParam(dataId, group, "default", "default");

Map<String, Object> metrics = new HashMap<>(16);
List<Connection> connectionsByIp = connectionManager.getConnectionByIp(ip);
for (Connection connectionByIp : connectionsByIp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.alibaba.nacos.api.config.remote.request.cluster.ConfigChangeClusterSyncRequest;
import com.alibaba.nacos.api.config.remote.response.cluster.ConfigChangeClusterSyncResponse;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.remote.RemoteConstants;
import com.alibaba.nacos.api.remote.request.RequestMeta;
import com.alibaba.nacos.config.server.service.dump.DumpRequest;
import com.alibaba.nacos.config.server.service.dump.DumpService;
Expand All @@ -27,6 +28,7 @@
import com.alibaba.nacos.core.paramcheck.impl.ConfigRequestParamExtractor;
import com.alibaba.nacos.core.remote.RequestHandler;
import com.alibaba.nacos.core.control.TpsControl;
import com.alibaba.nacos.core.remote.grpc.InvokeSource;
import org.springframework.stereotype.Component;

/**
Expand All @@ -36,6 +38,7 @@
* @version $Id: ConfigChangeClusterSyncRequestHandler.java, v 0.1 2020年08月11日 4:35 PM liuzunfei Exp $
*/
@Component
@InvokeSource(source = {RemoteConstants.LABEL_SOURCE_CLUSTER})
public class ConfigChangeClusterSyncRequestHandler
extends RequestHandler<ConfigChangeClusterSyncRequest, ConfigChangeClusterSyncResponse> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

package com.alibaba.nacos.config.server.service;

import com.alibaba.nacos.config.server.model.capacity.TenantCapacity;
import com.alibaba.nacos.config.server.service.capacity.TenantCapacityPersistService;
import com.alibaba.nacos.config.server.constant.PropertiesConstant;
import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService;
import com.alibaba.nacos.config.server.utils.PropertyUtil;
import com.alibaba.nacos.core.namespace.injector.AbstractNamespaceDetailInjector;
import com.alibaba.nacos.core.namespace.model.Namespace;
import com.alibaba.nacos.sys.env.EnvUtil;
import org.springframework.stereotype.Service;

/**
Expand All @@ -34,23 +33,17 @@ public class NamespaceConfigInfoService extends AbstractNamespaceDetailInjector

private final ConfigInfoPersistService configInfoPersistService;

private final TenantCapacityPersistService tenantCapacityPersistService;

public NamespaceConfigInfoService(ConfigInfoPersistService configInfoPersistService,
TenantCapacityPersistService tenantCapacityPersistService) {
public NamespaceConfigInfoService(ConfigInfoPersistService configInfoPersistService) {
this.configInfoPersistService = configInfoPersistService;
this.tenantCapacityPersistService = tenantCapacityPersistService;
}

@Override
public void injectDetail(Namespace namespace) {
// set tenant quota
TenantCapacity tenantCapacity = tenantCapacityPersistService.getTenantCapacity(namespace.getNamespace());
if (tenantCapacity != null && tenantCapacity.getQuota() != null && tenantCapacity.getQuota() > 0) {
namespace.setQuota(tenantCapacity.getQuota());
} else {
namespace.setQuota(PropertyUtil.getDefaultTenantQuota());

if (EnvUtil.getProperty(PropertiesConstant.DEFAULT_TENANT_QUOTA, Integer.class) != null) {
namespace.setQuota(EnvUtil.getProperty(PropertiesConstant.DEFAULT_TENANT_QUOTA, Integer.class));
}

// set config count.
int configCount = configInfoPersistService.configInfoCount(namespace.getNamespace());
namespace.setConfigCount(configCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package com.alibaba.nacos.config.server.service.dump;

import com.alibaba.nacos.config.server.service.repository.HistoryConfigInfoPersistService;
import com.alibaba.nacos.config.server.utils.PropertyUtil;
import com.alibaba.nacos.config.server.utils.TimeUtils;
import com.alibaba.nacos.sys.env.EnvUtil;
import com.alibaba.nacos.sys.utils.ApplicationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -27,8 +27,6 @@
import java.text.SimpleDateFormat;
import java.util.Calendar;

import static com.alibaba.nacos.config.server.utils.LogUtil.FATAL_LOG;

/**
* The type Default history config cleaner.
*
Expand All @@ -40,8 +38,6 @@ public class DefaultHistoryConfigCleaner implements HistoryConfigCleaner {

private HistoryConfigInfoPersistService historyConfigInfoPersistService;

private int retentionDays = 30;

@Override
public void cleanHistoryConfig() {
Timestamp startTime = getBeforeStamp(TimeUtils.getCurrentTime(), 24 * getRetentionDays());
Expand All @@ -66,22 +62,7 @@ private Timestamp getBeforeStamp(Timestamp date, int step) {
}

private int getRetentionDays() {
String val = EnvUtil.getProperty("nacos.config.retention.days");
if (null == val) {
return retentionDays;
}

int tmp = 0;
try {
tmp = Integer.parseInt(val);
if (tmp > 0) {
retentionDays = tmp;
}
} catch (NumberFormatException nfe) {
FATAL_LOG.error("read nacos.config.retention.days wrong", nfe);
}

return retentionDays;
return PropertyUtil.getConfigRententionDays();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;

import static com.alibaba.nacos.config.server.utils.LogUtil.FATAL_LOG;

/**
* Properties util.
*
Expand Down Expand Up @@ -100,7 +102,12 @@ public class PropertyUtil implements ApplicationContextInitializer<ConfigurableA
private static int correctUsageDelay = 10 * 60;

private static boolean dumpChangeOn = true;


/**
* The number of days to retain the configuration history, the default is 30 days.
*/
private static int configRententionDays = 30;

/**
* dumpChangeWorkerInterval, default 30 seconds.
*/
Expand Down Expand Up @@ -241,7 +248,26 @@ public static int getCorrectUsageDelay() {
public static void setCorrectUsageDelay(int correctUsageDelay) {
PropertyUtil.correctUsageDelay = correctUsageDelay;
}


public static int getConfigRententionDays() {
return configRententionDays;
}

private void setConfigRententionDays() {
String val = getProperty(PropertiesConstant.CONFIG_RENTENTION_DAYS);
if (null != val) {
int tmp = 0;
try {
tmp = Integer.parseInt(val);
if (tmp > 0) {
PropertyUtil.configRententionDays = tmp;
}
} catch (NumberFormatException nfe) {
FATAL_LOG.error("read nacos.config.retention.days wrong", nfe);
}
}
}

public static boolean isStandaloneMode() {
return EnvUtil.getStandaloneMode();
}
Expand Down Expand Up @@ -275,6 +301,7 @@ private void loadSetting() {
setDefaultMaxAggrSize(getInt(PropertiesConstant.DEFAULT_MAX_AGGR_SIZE, defaultMaxAggrSize));
setCorrectUsageDelay(getInt(PropertiesConstant.CORRECT_USAGE_DELAY, correctUsageDelay));
setInitialExpansionPercent(getInt(PropertiesConstant.INITIAL_EXPANSION_PERCENT, initialExpansionPercent));
setConfigRententionDays();
setDumpChangeOn(getBoolean(PropertiesConstant.DUMP_CHANGE_ON, dumpChangeOn));
setDumpChangeWorkerInterval(
getLong(PropertiesConstant.DUMP_CHANGE_WORKER_INTERVAL, dumpChangeWorkerInterval));
Expand Down
Loading

0 comments on commit f00cfec

Please sign in to comment.