Skip to content

Commit

Permalink
Naming global config unified use EnvUtils tool (#4376)
Browse files Browse the repository at this point in the history
* Add the function of automatically clearing empty services

* Fix checkstyle issue

* Delete the remove event of the service

* Fix checkstyle issue

* Add some task configurations for cleaning

* Adjust the configuration to the Naming module

* Naming global config unified use EnvUtils tool
  • Loading branch information
paderlol authored Dec 1, 2020
1 parent f9826d3 commit 0462644
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@

import com.alibaba.nacos.core.distributed.distro.DistroConfig;
import com.alibaba.nacos.sys.env.EnvUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

import static com.alibaba.nacos.naming.utils.Constants.DATA_WARMUP;
import static com.alibaba.nacos.naming.utils.Constants.DISTRO_BATCH_SYNC_KEY_COUNT;
import static com.alibaba.nacos.naming.utils.Constants.DISTRO_SYNC_RETRY_DELAY;
import static com.alibaba.nacos.naming.utils.Constants.DISTRO_TASK_DISPATCH_PERIOD;
import static com.alibaba.nacos.naming.utils.Constants.EMPTY_SERVICE_CLEAN_INTERVAL;
import static com.alibaba.nacos.naming.utils.Constants.EMPTY_SERVICE_EXPIRED_TIME;
import static com.alibaba.nacos.naming.utils.Constants.EXPIRED_METADATA_CLEAN_INTERVAL;
import static com.alibaba.nacos.naming.utils.Constants.EXPIRED_METADATA_EXPIRED_TIME;
import static com.alibaba.nacos.naming.utils.Constants.EXPIRE_INSTANCE;
import static com.alibaba.nacos.naming.utils.Constants.LOAD_DATA_RETRY_DELAY_MILLIS;

/**
* Stores some configurations for Distro protocol.
Expand All @@ -39,67 +44,47 @@ public class GlobalConfig {

private final DistroConfig distroConfig;

@Value("${nacos.naming.distro.taskDispatchPeriod:2000}")
private int taskDispatchPeriod = 2000;

@Value("${nacos.naming.distro.batchSyncKeyCount:1000}")
private int batchSyncKeyCount = 1000;

@Value("${nacos.naming.distro.syncRetryDelay:5000}")
private long syncRetryDelay = 5000L;

@Value("${nacos.naming.data.warmup:false}")
private boolean dataWarmup = false;

@Value("${nacos.naming.expireInstance:true}")
private boolean expireInstance = true;

@Value("${nacos.naming.clean.loadDataRetryDelayMillis:60000L}")
private long loadDataRetryDelayMillis = 30000;

public GlobalConfig(DistroConfig distroConfig) {
this.distroConfig = distroConfig;
}

@PostConstruct
public void printGlobalConfig() {
Loggers.SRV_LOG.info(toString());
overrideDistroConfiguration();
}

private void overrideDistroConfiguration() {
distroConfig.setSyncDelayMillis(taskDispatchPeriod);
distroConfig.setSyncRetryDelayMillis(syncRetryDelay);
distroConfig.setLoadDataRetryDelayMillis(loadDataRetryDelayMillis);
distroConfig.setSyncDelayMillis(getTaskDispatchPeriod());
distroConfig.setSyncRetryDelayMillis(getSyncRetryDelay());
distroConfig.setLoadDataRetryDelayMillis(getLoadDataRetryDelayMillis());
}

public int getTaskDispatchPeriod() {
return taskDispatchPeriod;
return EnvUtil.getProperty(DISTRO_TASK_DISPATCH_PERIOD, Integer.class, 2000);
}

public int getBatchSyncKeyCount() {
return batchSyncKeyCount;
return EnvUtil.getProperty(DISTRO_BATCH_SYNC_KEY_COUNT, Integer.class, 1000);
}

public long getSyncRetryDelay() {
return syncRetryDelay;
return EnvUtil.getProperty(DISTRO_SYNC_RETRY_DELAY, Long.class, 5000L);
}

public boolean isDataWarmup() {
return dataWarmup;
return EnvUtil.getProperty(DATA_WARMUP, Boolean.class, false);
}

public boolean isExpireInstance() {
return expireInstance;
return EnvUtil.getProperty(EXPIRE_INSTANCE, Boolean.class, true);
}

public long getLoadDataRetryDelayMillis() {
return loadDataRetryDelayMillis;
return EnvUtil.getProperty(LOAD_DATA_RETRY_DELAY_MILLIS, Long.class, 60000L);
}

public static Long getEmptyServiceCleanInterval() {
return EnvUtil.getProperty(EMPTY_SERVICE_CLEAN_INTERVAL, Long.class, 60000L);

}

public static Long getEmptyServiceExpiredTime() {
Expand All @@ -114,10 +99,4 @@ public static Long getExpiredMetadataExpiredTime() {
return EnvUtil.getProperty(EXPIRED_METADATA_EXPIRED_TIME, Long.class, 60000L);
}

@Override
public String toString() {
return "GlobalConfig{" + "taskDispatchPeriod=" + taskDispatchPeriod + ", batchSyncKeyCount=" + batchSyncKeyCount
+ ", syncRetryDelay=" + syncRetryDelay + ", dataWarmup=" + dataWarmup + ", expireInstance="
+ expireInstance + ", loadDataRetryDelayMillis=" + loadDataRetryDelayMillis + '}';
}
}
30 changes: 30 additions & 0 deletions naming/src/main/java/com/alibaba/nacos/naming/utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,34 @@ public final class Constants {
* Expiration time of expired metadata, unit: millisecond. default: 60000 ms.
*/
public static final String EXPIRED_METADATA_EXPIRED_TIME = "nacos.naming.clean.expired-metadata.expired-time";

/**
* Task time interval between twice processing, unit is millisecond. default: 2000 ms.
*/
public static final String DISTRO_TASK_DISPATCH_PERIOD = "nacos.naming.distro.taskDispatchPeriod";

/**
* The batch size of the key that distro combined delay task for http. default: 1000.
*/
public static final String DISTRO_BATCH_SYNC_KEY_COUNT = "nacos.naming.distro.batchSyncKeyCount";

/**
* Task time interval between twice processing, unit is millisecond. default: 5000ms
*/
public static final String DISTRO_SYNC_RETRY_DELAY = "nacos.naming.distro.syncRetryDelay";

/**
* default: false.
*/
public static final String DATA_WARMUP = "nacos.naming.data.warmup";

/**
* default : true.
*/
public static final String EXPIRE_INSTANCE = "nacos.naming.expireInstance";

/**
* default 60000L.
*/
public static final String LOAD_DATA_RETRY_DELAY_MILLIS = "nacos.naming.clean.loadDataRetryDelayMillis";
}

0 comments on commit 0462644

Please sign in to comment.