Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(10891): Provide a configuration item for the maximum number of p…
Browse files Browse the repository at this point in the history
…ush retries, instead of directly hardcoding it to 50 times in the code.
Bo-Qiu committed Aug 1, 2023
1 parent 74e740c commit bb1b2f0
Showing 6 changed files with 135 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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

import com.alibaba.nacos.common.event.ServerConfigChangeEvent;
import com.alibaba.nacos.common.notify.Event;
import com.alibaba.nacos.common.notify.NotifyCenter;
import com.alibaba.nacos.common.notify.listener.Subscriber;
import com.alibaba.nacos.sys.env.EnvUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
* Nacos config common configs.
*
* @author blake.qiu
*/
@Configuration
public class ConfigCommonConfigs extends Subscriber<ServerConfigChangeEvent> {

private static final Logger LOGGER = LoggerFactory.getLogger(ConfigCommonConfigs.class);

@Value("${nacos.config.push.maxRetryTime:50}")
private int maxPushRetryTimes;

public ConfigCommonConfigs() {
NotifyCenter.registerSubscriber(this);
}

public int getMaxPushRetryTimes() {
return maxPushRetryTimes;
}

public void setMaxPushRetryTimes(int maxPushRetryTimes) {
this.maxPushRetryTimes = maxPushRetryTimes;
}

@Override
public void onEvent(ServerConfigChangeEvent event) {
try {
maxPushRetryTimes = EnvUtil.getProperty("nacos.config.push.maxRetryTime", Integer.class, 50);
} catch (Exception e) {
LOGGER.warn("Upgrade nacos-config common configs from env failed, use old value", e);
}
}

@Override
public Class<? extends Event> subscribeType() {
return ServerConfigChangeEvent.class;
}
}
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@
import com.alibaba.nacos.common.notify.listener.Subscriber;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.config.server.configuration.ConfigCommonConfigs;
import com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent;
import com.alibaba.nacos.config.server.utils.ConfigExecutor;
import com.alibaba.nacos.config.server.utils.GroupKey;
@@ -80,6 +81,9 @@ private void registerTpsPoint() {
@Autowired
private ConnectionManager connectionManager;

@Autowired
private ConfigCommonConfigs configCommonConfigs;

/**
* adaptor to config module ,when server side config change ,invoke this method.
*
@@ -113,7 +117,8 @@ public void configDataChanged(String groupKey, String dataId, String group, Stri

ConfigChangeNotifyRequest notifyRequest = ConfigChangeNotifyRequest.build(dataId, group, tenant);

RpcPushTask rpcPushRetryTask = new RpcPushTask(notifyRequest, 50, client, clientIp, metaInfo.getAppName());
RpcPushTask rpcPushRetryTask = new RpcPushTask(notifyRequest, configCommonConfigs.getMaxPushRetryTimes(),
client, clientIp, metaInfo.getAppName());
push(rpcPushRetryTask);
notifyClientCount++;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 1999-2020 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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

import com.alibaba.nacos.common.event.ServerConfigChangeEvent;
import com.alibaba.nacos.sys.env.EnvUtil;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.springframework.mock.env.MockEnvironment;

import static org.junit.Assert.assertEquals;

/**
* Nacos config common configs test.
*
* @author blake.qiu
*/
public class ConfigCommonConfigsTest {

@InjectMocks
private ConfigCommonConfigs commonConfigs;

private MockEnvironment environment;

@Before
public void setUp() throws Exception {
environment = new MockEnvironment();
EnvUtil.setEnvironment(environment);
commonConfigs = new ConfigCommonConfigs();
}

@Test
public void testUpgradeFromEvent() {
environment.setProperty("nacos.config.push.maxRetryTime", "100");
commonConfigs.onEvent(ServerConfigChangeEvent.newEvent());
assertEquals(100, commonConfigs.getMaxPushRetryTimes());
}
}
3 changes: 3 additions & 0 deletions console/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -42,6 +42,9 @@ server.port=8848
# db.user=nacos
# db.password=nacos

### the maximum retry times for push
nacos.config.push.maxRetryTime=50

#*************** Naming Module Related Configurations ***************#
### Data dispatch task execution period in milliseconds:

3 changes: 3 additions & 0 deletions distribution/conf/application.properties
Original file line number Diff line number Diff line change
@@ -50,6 +50,9 @@ db.pool.config.validationTimeout=10000
db.pool.config.maximumPoolSize=20
db.pool.config.minimumIdle=2

### the maximum retry times for push
nacos.config.push.maxRetryTime=50

#*************** Naming Module Related Configurations ***************#

### If enable data warmup. If set to false, the server would accept request without local data preparation:
3 changes: 3 additions & 0 deletions distribution/conf/application.properties.example
Original file line number Diff line number Diff line change
@@ -50,6 +50,9 @@ db.pool.config.validationTimeout=10000
db.pool.config.maximumPoolSize=20
db.pool.config.minimumIdle=2

### the maximum retry times for push
nacos.config.push.maxRetryTime=50

#*************** Naming Module Related Configurations ***************#
### If enable data warmup. If set to false, the server would accept request without local data preparation:
# nacos.naming.data.warmup=true

0 comments on commit bb1b2f0

Please sign in to comment.