From 8d28958cb701117e282a04382d69d9a460cc63e4 Mon Sep 17 00:00:00 2001 From: nkorange Date: Fri, 8 Mar 2019 17:18:01 +0800 Subject: [PATCH] #629 Fix bug --- .../META-INF/nacos-default.properties | 11 ++++++----- distribution/conf/application.properties | 11 ++++++----- .../nacos/naming/boot/RunningConfig.java | 6 ++++++ .../ephemeral/distro/DataSyncer.java | 2 +- .../distro/DistroConsistencyServiceImpl.java | 17 ++++++++++++++--- .../ephemeral/distro/TaskDispatcher.java | 3 ++- .../consistency/persistent/raft/RaftCore.java | 5 ++++- .../naming/controllers/ServiceController.java | 2 +- .../GlobalConfig.java} | 18 +++++++++--------- .../naming/misc/ServerStatusSynchronizer.java | 4 ++-- .../src/main/resources/application.properties | 2 ++ .../test/naming/CPInstancesAPI_ITCase.java | 4 ++-- test/src/test/resources/application.properties | 1 + 13 files changed, 56 insertions(+), 30 deletions(-) rename naming/src/main/java/com/alibaba/nacos/naming/{consistency/ephemeral/distro/PartitionConfig.java => misc/GlobalConfig.java} (86%) diff --git a/console/src/main/resources/META-INF/nacos-default.properties b/console/src/main/resources/META-INF/nacos-default.properties index baf64608d..35b95f507 100644 --- a/console/src/main/resources/META-INF/nacos-default.properties +++ b/console/src/main/resources/META-INF/nacos-default.properties @@ -65,8 +65,9 @@ server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D # default current work dir server.tomcat.basedir= -nacos.naming.partition.taskDispatchThreadCount=10 -nacos.naming.partition.taskDispatchPeriod=200 -nacos.naming.partition.batchSyncKeyCount=1000 -nacos.naming.partition.initDataRatio=0.9 -nacos.naming.partition.syncRetryDelay=5000 +nacos.naming.distro.taskDispatchThreadCount=10 +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 diff --git a/distribution/conf/application.properties b/distribution/conf/application.properties index cd2273f41..9c916225d 100644 --- a/distribution/conf/application.properties +++ b/distribution/conf/application.properties @@ -39,8 +39,9 @@ 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.partition.taskDispatchThreadCount=10 -nacos.naming.partition.taskDispatchPeriod=200 -nacos.naming.partition.batchSyncKeyCount=1000 -nacos.naming.partition.initDataRatio=0.9 -nacos.naming.partition.syncRetryDelay=5000 +nacos.naming.distro.taskDispatchThreadCount=10 +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 diff --git a/naming/src/main/java/com/alibaba/nacos/naming/boot/RunningConfig.java b/naming/src/main/java/com/alibaba/nacos/naming/boot/RunningConfig.java index ce776cc20..b32947b1c 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/boot/RunningConfig.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/boot/RunningConfig.java @@ -16,7 +16,9 @@ package com.alibaba.nacos.naming.boot; import com.alibaba.nacos.naming.misc.Loggers; +import com.alibaba.nacos.naming.misc.UtilsAndCommons; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.context.WebServerInitializedEvent; import org.springframework.context.ApplicationListener; @@ -53,6 +55,10 @@ public class RunningConfig implements ApplicationListener> listeners = new ConcurrentHashMap<>(); @@ -101,7 +104,8 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService initialized = true; return; } - while (serverListManager.getHealthyServers().isEmpty()) { + // size = 1 means only myself in the list, we need at least one another server alive: + while (serverListManager.getHealthyServers().size() <= 1) { Thread.sleep(1000L); Loggers.EPHEMERAL.info("waiting server list init..."); } @@ -110,6 +114,9 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService if (NetUtils.localServer().equals(server.getKey())) { continue; } + if (Loggers.EPHEMERAL.isDebugEnabled()) { + Loggers.EPHEMERAL.debug("sync from " + server); + } // try sync data from remote server: if (syncAllDataFromRemote(server)) { initialized = true; @@ -227,7 +234,7 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService processData(data); return true; } catch (Exception e) { - Loggers.EPHEMERAL.error("sync full data from " + server + " failed!"); + Loggers.EPHEMERAL.error("sync full data from " + server + " failed!", e); return false; } } @@ -301,6 +308,10 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService @Override public boolean isAvailable() { - return initialized || ServerStatus.UP.name().equals(switchDomain.getOverriddenServerStatus()); + return isInitialized() || ServerStatus.UP.name().equals(switchDomain.getOverriddenServerStatus()); + } + + public boolean isInitialized() { + return initialized || !globalConfig.isDataWarmup(); } } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/TaskDispatcher.java b/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/TaskDispatcher.java index f91ec038a..bd47f2865 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/TaskDispatcher.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/TaskDispatcher.java @@ -16,6 +16,7 @@ package com.alibaba.nacos.naming.consistency.ephemeral.distro; import com.alibaba.nacos.naming.cluster.servers.Server; +import com.alibaba.nacos.naming.misc.GlobalConfig; import com.alibaba.nacos.naming.misc.GlobalExecutor; import com.alibaba.nacos.naming.misc.Loggers; import com.alibaba.nacos.naming.misc.NetUtils; @@ -38,7 +39,7 @@ import java.util.concurrent.*; public class TaskDispatcher { @Autowired - private PartitionConfig partitionConfig; + private GlobalConfig partitionConfig; @Autowired private DataSyncer dataSyncer; 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 2b5bab443..ade5ea24e 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 @@ -101,6 +101,9 @@ public class RaftCore { @Autowired private SwitchDomain switchDomain; + @Autowired + private GlobalConfig globalConfig; + @Autowired private RaftProxy raftProxy; @@ -874,7 +877,7 @@ public class RaftCore { } public boolean isInitialized() { - return initialized; + return initialized || !globalConfig.isDataWarmup(); } public class Notifier implements Runnable { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceController.java index d73c4336e..d45f18e1a 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceController.java @@ -223,7 +223,7 @@ public class ServiceController { } for (int i = start; i < end; i++) { - serviceNameList.add(i, serviceNameList.get(i).replace(groupName + Constants.SERVICE_INFO_SPLITER, "")); + serviceNameList.set(i, serviceNameList.get(i).replace(groupName + Constants.SERVICE_INFO_SPLITER, "")); } result.put("doms", serviceNameList.subList(start, end)); diff --git a/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/PartitionConfig.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/GlobalConfig.java similarity index 86% rename from naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/PartitionConfig.java rename to naming/src/main/java/com/alibaba/nacos/naming/misc/GlobalConfig.java index 34c07e655..294910c00 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/PartitionConfig.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/misc/GlobalConfig.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.nacos.naming.consistency.ephemeral.distro; +package com.alibaba.nacos.naming.misc; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -25,7 +25,7 @@ import org.springframework.stereotype.Component; * @since 1.0.0 */ @Component -public class PartitionConfig { +public class GlobalConfig { @Value("${nacos.naming.distro.taskDispatchPeriod}") private int taskDispatchPeriod = 2000; @@ -33,15 +33,15 @@ public class PartitionConfig { @Value("${nacos.naming.distro.batchSyncKeyCount}") private int batchSyncKeyCount = 1000; - @Value("${nacos.naming.distro.initDataRatio}") - private float initDataRatio = 0.9F; - @Value("${nacos.naming.distro.syncRetryDelay}") private long syncRetryDelay = 5000L; @Value("${nacos.naming.distro.taskDispatchThreadCount}") private int taskDispatchThreadCount = Runtime.getRuntime().availableProcessors(); + @Value("${nacos.naming.data.warmup}") + private boolean dataWarmup = false; + public int getTaskDispatchPeriod() { return taskDispatchPeriod; } @@ -50,10 +50,6 @@ public class PartitionConfig { return batchSyncKeyCount; } - public float getInitDataRatio() { - return initDataRatio; - } - public long getSyncRetryDelay() { return syncRetryDelay; } @@ -61,4 +57,8 @@ public class PartitionConfig { public int getTaskDispatchThreadCount() { return taskDispatchThreadCount; } + + public boolean isDataWarmup() { + return dataWarmup; + } } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/misc/ServerStatusSynchronizer.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/ServerStatusSynchronizer.java index 49eb9684b..0f4813687 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/misc/ServerStatusSynchronizer.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/misc/ServerStatusSynchronizer.java @@ -40,11 +40,11 @@ public class ServerStatusSynchronizer implements Synchronizer { params.put("serverStatus", msg.getData()); String url = "http://" + serverIP + ":" + RunningConfig.getServerPort() - + RunningConfig.getContextPath() + UtilsAndCommons.NACOS_NAMING_CONTEXT + "/operator/serverStatus"; + + RunningConfig.getContextPath() + UtilsAndCommons.NACOS_NAMING_CONTEXT + "/operator/server/status"; if (serverIP.contains(UtilsAndCommons.IP_PORT_SPLITER)) { url = "http://" + serverIP + RunningConfig.getContextPath() + UtilsAndCommons.NACOS_NAMING_CONTEXT - + "/operator/serverStatus"; + + "/operator/server/status"; } try { diff --git a/naming/src/main/resources/application.properties b/naming/src/main/resources/application.properties index 06dc0f3ab..96472b51e 100644 --- a/naming/src/main/resources/application.properties +++ b/naming/src/main/resources/application.properties @@ -31,3 +31,5 @@ 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 diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/CPInstancesAPI_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/CPInstancesAPI_ITCase.java index 05e1b3d67..a4983ca1d 100644 --- a/test/src/test/java/com/alibaba/nacos/test/naming/CPInstancesAPI_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/naming/CPInstancesAPI_ITCase.java @@ -151,7 +151,7 @@ public class CPInstancesAPI_ITCase { instance.setPort(80); naming1.registerInstance(serviceName, TEST_GROUP_1, instance); naming1.deregisterInstance(serviceName, TEST_GROUP_1, "11.11.11.11", 80, "c1"); - + namingServiceDelete(serviceName, TEST_NAMESPACE_1, TEST_GROUP_1); } @@ -358,7 +358,7 @@ public class CPInstancesAPI_ITCase { ResponseEntity response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service", Params.newParams() .appendParam("serviceName", serviceName) - .appendParam("protectThreshold", "3") + .appendParam("protectThreshold", "0.3") .appendParam("namespaceId", namespace) .appendParam("groupName", groupName) .done(), diff --git a/test/src/test/resources/application.properties b/test/src/test/resources/application.properties index d370fb84e..370947e95 100644 --- a/test/src/test/resources/application.properties +++ b/test/src/test/resources/application.properties @@ -24,3 +24,4 @@ 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