Merge pull request #1398 from nkorange/hotfix_notify_task_called_before_data_loaded

Fix #1397
This commit is contained in:
Fury Zhu 2019-06-20 10:31:32 +08:00 committed by GitHub
commit 409838fe1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 13 additions and 90 deletions

View File

@ -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");

View File

@ -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;
}
}

View File

@ -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

View File

@ -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

View File

@ -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));

View File

@ -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<String, Datum> loadDatums(RaftCore.Notifier notifier) throws Exception {
public synchronized void loadDatums(RaftCore.Notifier notifier, ConcurrentMap<String, Datum> datums) throws Exception {
ConcurrentHashMap<String, Datum> 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 {

View File

@ -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;
}

View File

@ -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

View File

@ -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