Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some task configurations for cleaning #4369

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.alibaba.nacos.naming.core.v2.pojo.Service;
import com.alibaba.nacos.naming.misc.GlobalExecutor;
import com.alibaba.nacos.naming.misc.Loggers;
import com.alibaba.nacos.sys.env.EnvUtil;

import java.util.Collection;
import java.util.Set;
Expand All @@ -42,9 +43,8 @@ public class EmptyServiceAutoCleanerV2 extends AbstractNamingCleaner {

public EmptyServiceAutoCleanerV2(ClientServiceIndexesManager clientServiceIndexesManager) {
this.clientServiceIndexesManager = clientServiceIndexesManager;
// TODO get internal from config
GlobalExecutor.scheduleExpiredClientCleaner(this, TimeUnit.SECONDS.toMillis(30), TimeUnit.SECONDS.toMillis(20),
TimeUnit.MILLISECONDS);
GlobalExecutor.scheduleExpiredClientCleaner(this, TimeUnit.SECONDS.toMillis(30),
EnvUtil.getEmptyServiceCleanInterval(), TimeUnit.MILLISECONDS);

}

Expand Down Expand Up @@ -79,7 +79,6 @@ private void cleanEmptyService(Service service) {

private boolean isTimeExpired(Service service) {
long currentTimeMillis = System.currentTimeMillis();
// TODO get expired time from config
return currentTimeMillis - service.getLastUpdatedTime() >= TimeUnit.MINUTES.toMillis(1);
return currentTimeMillis - service.getLastUpdatedTime() >= EnvUtil.getEmptyServiceExpiredTime();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService;
import com.alibaba.nacos.naming.misc.GlobalExecutor;
import com.alibaba.nacos.naming.misc.Loggers;
import com.alibaba.nacos.sys.env.EnvUtil;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;
Expand All @@ -43,8 +44,8 @@ public ExpiredMetadataCleaner(NamingMetadataManager metadataManager,
NamingMetadataOperateService metadataOperateService) {
this.metadataManager = metadataManager;
this.metadataOperateService = metadataOperateService;
// TODO get internal from config
GlobalExecutor.scheduleExpiredClientCleaner(this, 5000, 5000, TimeUnit.MILLISECONDS);
GlobalExecutor.scheduleExpiredClientCleaner(this, 5000, EnvUtil.getExpiredMetadataCleanInterval(),
TimeUnit.MILLISECONDS);
}

@Override
Expand All @@ -56,8 +57,7 @@ public String getType() {
public void doClean() {
long currentTime = System.currentTimeMillis();
for (ExpiredMetadataInfo each : metadataManager.getExpiredMetadataInfos()) {
// TODO get expired time from config
if (currentTime - each.getCreateTime() > TimeUnit.MINUTES.toMillis(1)) {
if (currentTime - each.getCreateTime() > EnvUtil.getExpiredMetadataExpiredTime()) {
removeExpiredMetadata(each);
}
}
Expand Down
16 changes: 16 additions & 0 deletions sys/src/main/java/com/alibaba/nacos/sys/env/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,23 @@ public interface Constants {
* the root context path.
*/
String ROOT_WEB_CONTEXT_PATH = "/";
/**
* Time interval to clear empty services, unit: millisecond. default: 60000 ms.
*/
String EMPTY_SERVICE_CLEAN_INTERVAL = "empty.service.clean.interval";

/**
* Expiration time of empty service, unit: millisecond. default: 60000 ms.
*/
String EMPTY_SERVICE_EXPIRED_TIME = "empty.service.expired.time";
/**
* Time interval to clear expired metadata, unit: millisecond. default: 5000 ms.
*/
String EXPIRED_METADATA_CLEAN_INTERVAL = "expired.metadata.clean.interval";
/**
* Expiration time of expired metadata, unit: millisecond. default: 60000 ms.
*/
String EXPIRED_METADATA_EXPIRED_TIME = "expired.metadata.expired.time";
String NACOS_SERVER_IP = "nacos.server.ip";

String USE_ONLY_SITE_INTERFACES = "nacos.inetutils.use-only-site-local-interfaces";
Expand Down
41 changes: 41 additions & 0 deletions sys/src/main/java/com/alibaba/nacos/sys/env/EnvUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
import java.util.List;
import java.util.Map;

import static com.alibaba.nacos.sys.env.Constants.EMPTY_SERVICE_CLEAN_INTERVAL;
import static com.alibaba.nacos.sys.env.Constants.EMPTY_SERVICE_EXPIRED_TIME;
import static com.alibaba.nacos.sys.env.Constants.EXPIRED_METADATA_CLEAN_INTERVAL;
import static com.alibaba.nacos.sys.env.Constants.EXPIRED_METADATA_EXPIRED_TIME;

/**
* Its own configuration information manipulation tool class.
*
Expand Down Expand Up @@ -72,6 +77,14 @@ public class EnvUtil {

private static String contextPath = null;

private static Long emptyServiceCleanInterval;

private static Long emptyServiceExpiredTime;

private static Long expiredMetadataCleanInterval;

private static Long expiredMetadataExpiredTime;

@JustForTest
private static String confPath = "";

Expand Down Expand Up @@ -123,6 +136,34 @@ public static String resolveRequiredPlaceholders(String text) throws IllegalArgu
return environment.resolveRequiredPlaceholders(text);
}

public static Long getEmptyServiceCleanInterval() {
chuntaojun marked this conversation as resolved.
Show resolved Hide resolved
if (Objects.isNull(emptyServiceCleanInterval)) {
emptyServiceCleanInterval = getProperty(EMPTY_SERVICE_CLEAN_INTERVAL, Long.class, 60000L);
}
return emptyServiceCleanInterval;
}

public static Long getEmptyServiceExpiredTime() {
if (Objects.isNull(emptyServiceExpiredTime)) {
emptyServiceExpiredTime = getProperty(EMPTY_SERVICE_EXPIRED_TIME, Long.class, 60000L);
}
return emptyServiceExpiredTime;
}

public static Long getExpiredMetadataCleanInterval() {
if (Objects.isNull(expiredMetadataCleanInterval)) {
expiredMetadataCleanInterval = getProperty(EXPIRED_METADATA_CLEAN_INTERVAL, Long.class, 5000L);
}
return expiredMetadataCleanInterval;
}

public static Long getExpiredMetadataExpiredTime() {
if (Objects.isNull(expiredMetadataExpiredTime)) {
expiredMetadataExpiredTime = getProperty(EXPIRED_METADATA_EXPIRED_TIME, Long.class, 60000L);
}
return expiredMetadataExpiredTime;
}

public static List<String> getPropertyList(String key) {
List<String> valueList = new ArrayList<>();

Expand Down