From b52ba3ed91d5a54752ee7b99d3a32f3fdb77c158 Mon Sep 17 00:00:00 2001 From: nkorange Date: Wed, 19 Jun 2019 17:57:26 +0800 Subject: [PATCH] Fix #1397 --- .../cmdb/controllers/OperationController.java | 27 ------------------- .../nacos/cmdb/core/SwitchAndOptions.java | 24 +++-------------- .../META-INF/nacos-default.properties | 8 +----- distribution/conf/application.properties | 2 -- .../consistency/persistent/raft/RaftCore.java | 2 +- .../persistent/raft/RaftStore.java | 6 ++--- .../nacos/naming/misc/GlobalConfig.java | 17 ++++-------- .../src/main/resources/application.properties | 9 ------- .../src/test/resources/application.properties | 8 ------ 9 files changed, 13 insertions(+), 90 deletions(-) diff --git a/cmdb/src/main/java/com/alibaba/nacos/cmdb/controllers/OperationController.java b/cmdb/src/main/java/com/alibaba/nacos/cmdb/controllers/OperationController.java index cf7fe3eb5..3763a7126 100644 --- a/cmdb/src/main/java/com/alibaba/nacos/cmdb/controllers/OperationController.java +++ b/cmdb/src/main/java/com/alibaba/nacos/cmdb/controllers/OperationController.java @@ -34,36 +34,9 @@ import javax.servlet.http.HttpServletRequest; @RequestMapping(UtilsAndCommons.NACOS_CMDB_CONTEXT + "/ops") public class OperationController { - @Autowired - private SwitchAndOptions switches; - @Autowired private CmdbProvider cmdbProvider; - @RequestMapping(value = "/switch", method = RequestMethod.PUT) - public String updateSwitch(HttpServletRequest request) throws Exception { - - String entry = WebUtils.required(request, "entry"); - String value = WebUtils.required(request, "value"); - - switch (entry) { - case "dumpTaskInterval": - switches.setDumpTaskInterval(Integer.parseInt(value)); - break; - case "eventTaskInterval": - switches.setEventTaskInterval(Integer.parseInt(value)); - break; - case "loadDataAtStart": - switches.setLoadDataAtStart(Boolean.parseBoolean(value)); - break; - case "labelTaskInterval": - switches.setLabelTaskInterval(Integer.parseInt(value)); - default: - break; - } - return "ok"; - } - @RequestMapping(value = "/label", method = RequestMethod.GET) public String queryLabel(HttpServletRequest request) throws Exception { String entry = WebUtils.required(request, "entry"); diff --git a/cmdb/src/main/java/com/alibaba/nacos/cmdb/core/SwitchAndOptions.java b/cmdb/src/main/java/com/alibaba/nacos/cmdb/core/SwitchAndOptions.java index d6fce2d29..fc18c8403 100644 --- a/cmdb/src/main/java/com/alibaba/nacos/cmdb/core/SwitchAndOptions.java +++ b/cmdb/src/main/java/com/alibaba/nacos/cmdb/core/SwitchAndOptions.java @@ -25,47 +25,31 @@ import org.springframework.stereotype.Component; @Component public class SwitchAndOptions { - @Value("${nacos.cmdb.dumpTaskInterval}") + @Value("${nacos.cmdb.dumpTaskInterval:3600}") private int dumpTaskInterval; - @Value("${nacos.cmdb.eventTaskInterval}") + @Value("${nacos.cmdb.eventTaskInterval:10}") private int eventTaskInterval; - @Value("${nacos.cmdb.labelTaskInterval}") + @Value("${nacos.cmdb.labelTaskInterval:300}") private int labelTaskInterval; - @Value("${nacos.cmdb.loadDataAtStart}") + @Value("${nacos.cmdb.loadDataAtStart:false}") private boolean loadDataAtStart; public int getDumpTaskInterval() { return dumpTaskInterval; } - public void setDumpTaskInterval(int dumpTaskInterval) { - this.dumpTaskInterval = dumpTaskInterval; - } - public int getEventTaskInterval() { return eventTaskInterval; } - public void setEventTaskInterval(int eventTaskInterval) { - this.eventTaskInterval = eventTaskInterval; - } - public int getLabelTaskInterval() { return labelTaskInterval; } - public void setLabelTaskInterval(int labelTaskInterval) { - this.labelTaskInterval = labelTaskInterval; - } - public boolean isLoadDataAtStart() { return loadDataAtStart; } - - public void setLoadDataAtStart(boolean loadDataAtStart) { - this.loadDataAtStart = loadDataAtStart; - } } diff --git a/console/src/main/resources/META-INF/nacos-default.properties b/console/src/main/resources/META-INF/nacos-default.properties index 950d6e006..b86d3b48b 100644 --- a/console/src/main/resources/META-INF/nacos-default.properties +++ b/console/src/main/resources/META-INF/nacos-default.properties @@ -65,10 +65,4 @@ server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D # default current work dir server.tomcat.basedir= -nacos.naming.distro.taskDispatchThreadCount=1 -nacos.naming.distro.taskDispatchPeriod=200 -nacos.naming.distro.batchSyncKeyCount=1000 -nacos.naming.distro.initDataRatio=0.9 -nacos.naming.distro.syncRetryDelay=5000 -nacos.naming.data.warmup=false -nacos.naming.expireInstance=true + diff --git a/distribution/conf/application.properties b/distribution/conf/application.properties index f9e64f7c2..5739afa8e 100644 --- a/distribution/conf/application.properties +++ b/distribution/conf/application.properties @@ -39,10 +39,8 @@ server.tomcat.basedir= nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/login,/v1/console/health/**,/v1/cs/**,/v1/ns/**,/v1/cmdb/**,/actuator/**,/v1/console/server/** -nacos.naming.distro.taskDispatchThreadCount=1 nacos.naming.distro.taskDispatchPeriod=200 nacos.naming.distro.batchSyncKeyCount=1000 -nacos.naming.distro.initDataRatio=0.9 nacos.naming.distro.syncRetryDelay=5000 nacos.naming.data.warmup=true nacos.naming.expireInstance=true diff --git a/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/raft/RaftCore.java b/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/raft/RaftCore.java index 6e773a39c..51ce407c8 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/raft/RaftCore.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/raft/RaftCore.java @@ -123,7 +123,7 @@ public class RaftCore { long start = System.currentTimeMillis(); - datums = raftStore.loadDatums(notifier); + raftStore.loadDatums(notifier, datums); setTerm(NumberUtils.toLong(raftStore.loadMeta().getProperty("term"), 0L)); diff --git a/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/raft/RaftStore.java b/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/raft/RaftStore.java index cc391e09b..bb549ecde 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/raft/RaftStore.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/raft/RaftStore.java @@ -40,7 +40,7 @@ import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.util.List; import java.util.Properties; -import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; /** * @author nacos @@ -54,9 +54,8 @@ public class RaftStore { private String cacheDir = UtilsAndCommons.DATA_BASE_DIR + File.separator + "data"; - public synchronized ConcurrentHashMap loadDatums(RaftCore.Notifier notifier) throws Exception { + public synchronized void loadDatums(RaftCore.Notifier notifier, ConcurrentMap datums) throws Exception { - ConcurrentHashMap datums = new ConcurrentHashMap<>(32); Datum datum; long start = System.currentTimeMillis(); for (File cache : listCaches()) { @@ -77,7 +76,6 @@ public class RaftStore { } Loggers.RAFT.info("finish loading all datums, size: {} cost {} ms.", datums.size(), (System.currentTimeMillis() - start)); - return datums; } public synchronized Properties loadMeta() throws Exception { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/misc/GlobalConfig.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/GlobalConfig.java index 49281da5f..71daf796d 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/misc/GlobalConfig.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/misc/GlobalConfig.java @@ -27,22 +27,19 @@ import org.springframework.stereotype.Component; @Component public class GlobalConfig { - @Value("${nacos.naming.distro.taskDispatchPeriod}") + @Value("${nacos.naming.distro.taskDispatchPeriod:200}") private int taskDispatchPeriod = 2000; - @Value("${nacos.naming.distro.batchSyncKeyCount}") + @Value("${nacos.naming.distro.batchSyncKeyCount:1000}") private int batchSyncKeyCount = 1000; - @Value("${nacos.naming.distro.syncRetryDelay}") + @Value("${nacos.naming.distro.syncRetryDelay:5000}") private long syncRetryDelay = 5000L; - @Value("${nacos.naming.distro.taskDispatchThreadCount}") - private int taskDispatchThreadCount = Runtime.getRuntime().availableProcessors(); - - @Value("${nacos.naming.data.warmup}") + @Value("${nacos.naming.data.warmup:false}") private boolean dataWarmup = false; - @Value("${nacos.naming.expireInstance}") + @Value("${nacos.naming.expireInstance:true}") private boolean expireInstance = true; public int getTaskDispatchPeriod() { @@ -57,10 +54,6 @@ public class GlobalConfig { return syncRetryDelay; } - public int getTaskDispatchThreadCount() { - return taskDispatchThreadCount; - } - public boolean isDataWarmup() { return dataWarmup; } diff --git a/naming/src/main/resources/application.properties b/naming/src/main/resources/application.properties index 437f17b5e..56b1f3c57 100644 --- a/naming/src/main/resources/application.properties +++ b/naming/src/main/resources/application.properties @@ -25,12 +25,3 @@ server.tomcat.accesslog.enabled=true server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D # default current work dir server.tomcat.basedir= - -nacos.naming.distro.taskDispatchThreadCount=1 -nacos.naming.distro.taskDispatchPeriod=200 -nacos.naming.distro.batchSyncKeyCount=1000 -nacos.naming.distro.initDataRatio=0.9 -nacos.naming.distro.syncRetryDelay=5000 - -nacos.naming.data.warmup=true -nacos.naming.expireInstance=true diff --git a/test/src/test/resources/application.properties b/test/src/test/resources/application.properties index 13b314b3a..b611435ea 100644 --- a/test/src/test/resources/application.properties +++ b/test/src/test/resources/application.properties @@ -18,11 +18,3 @@ server.tomcat.accesslog.enabled=false server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D # default current work dir server.tomcat.basedir= - -nacos.naming.distro.taskDispatchThreadCount=1 -nacos.naming.distro.taskDispatchPeriod=200 -nacos.naming.distro.batchSyncKeyCount=1000 -nacos.naming.distro.initDataRatio=0.9 -nacos.naming.distro.syncRetryDelay=5000 -nacos.naming.data.warmup=false -nacos.naming.expireInstance=true