diff --git a/README.md b/README.md index 75e6ce966..097c6a8f5 100644 --- a/README.md +++ b/README.md @@ -97,9 +97,9 @@ Contributors are welcomed to join Nacos project. Please check [CONTRIBUTING](./C * users-nacos@googlegroups.com: Nacos usage general discussion. * dev-nacos@googlegroups.com: Nacos developer discussion (APIs, feature design, etc). * commits-nacos@googlegroups.com: Commits notice, very high frequency. -* Join us from wechat. Welcome words: Nacos. +* Join us from DingDing. -![cwex](http://acm-public.oss-cn-hangzhou.aliyuncs.com/xuc.png) +![cwex](https://img.alicdn.com/tfs/TB1bpBlQmrqK1RjSZK9XXXyypXa-830-972.png_288x480q80.jpg) ## Who is using diff --git a/console/src/main/resources/META-INF/nacos-default.properties b/console/src/main/resources/META-INF/nacos-default.properties index c55907564..950d6e006 100644 --- a/console/src/main/resources/META-INF/nacos-default.properties +++ b/console/src/main/resources/META-INF/nacos-default.properties @@ -65,7 +65,7 @@ server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D # default current work dir server.tomcat.basedir= -nacos.naming.distro.taskDispatchThreadCount=10 +nacos.naming.distro.taskDispatchThreadCount=1 nacos.naming.distro.taskDispatchPeriod=200 nacos.naming.distro.batchSyncKeyCount=1000 nacos.naming.distro.initDataRatio=0.9 diff --git a/distribution/bin/startup.sh b/distribution/bin/startup.sh index e73b67a2a..18536e3e2 100644 --- a/distribution/bin/startup.sh +++ b/distribution/bin/startup.sh @@ -101,7 +101,6 @@ else JAVA_OPT="${JAVA_OPT} -Xloggc:${BASE_DIR}/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M" fi -JAVA_OPT="${JAVA_OPT} -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000" JAVA_OPT="${JAVA_OPT} -Dnacos.home=${BASE_DIR}" JAVA_OPT="${JAVA_OPT} -jar ${BASE_DIR}/target/nacos-server.jar" JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}" diff --git a/distribution/conf/application.properties b/distribution/conf/application.properties index c95c3b5ca..f9e64f7c2 100644 --- a/distribution/conf/application.properties +++ b/distribution/conf/application.properties @@ -39,7 +39,7 @@ 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=10 +nacos.naming.distro.taskDispatchThreadCount=1 nacos.naming.distro.taskDispatchPeriod=200 nacos.naming.distro.batchSyncKeyCount=1000 nacos.naming.distro.initDataRatio=0.9 diff --git a/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/DistroConsistencyServiceImpl.java b/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/DistroConsistencyServiceImpl.java index dd6084706..bc21a482c 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/DistroConsistencyServiceImpl.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/DistroConsistencyServiceImpl.java @@ -187,6 +187,8 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService return; } + listeners.remove(key); + notifier.addTask(key, ApplyAction.DELETE); } 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 b317954f5..a8d77e212 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 @@ -48,6 +48,13 @@ public class TaskDispatcher { @PostConstruct public void init() { + + if (partitionConfig.getTaskDispatchThreadCount() > Runtime.getRuntime().availableProcessors()) { + Loggers.EPHEMERAL.error("should not larger than {}, current is: {}", + Runtime.getRuntime().availableProcessors(), partitionConfig.getTaskDispatchThreadCount()); + throw new RuntimeException("task dispatch thread count is too large!"); + } + for (int i = 0; i < partitionConfig.getTaskDispatchThreadCount(); i++) { TaskScheduler taskScheduler = new TaskScheduler(i); taskSchedulerList.add(taskScheduler); diff --git a/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/raft/RaftConsistencyServiceImpl.java b/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/raft/RaftConsistencyServiceImpl.java index 5326dcba4..0a3fbf610 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/raft/RaftConsistencyServiceImpl.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/consistency/persistent/raft/RaftConsistencyServiceImpl.java @@ -62,9 +62,11 @@ public class RaftConsistencyServiceImpl implements PersistentConsistencyService Datum datum = new Datum(); datum.key = key; raftCore.onDelete(datum.key, peers.getLeader()); + raftCore.unlistenAll(key); return; } raftCore.signalDelete(key); + raftCore.unlistenAll(key); } catch (Exception e) { Loggers.RAFT.error("Raft remove failed.", e); throw new NacosException(NacosException.SERVER_ERROR, "Raft remove failed, key:" + key); 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 5d9fbfad0..6e773a39c 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 @@ -809,6 +809,10 @@ public class RaftCore { } } + public void unlistenAll(String key) { + listeners.remove(key); + } + public void setTerm(long term) { peers.setTerm(term); } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/ClusterController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/ClusterController.java index 2b0df4128..9f83ae4d3 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/ClusterController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/ClusterController.java @@ -69,6 +69,7 @@ public class ClusterController { Loggers.SRV_LOG.warn("[UPDATE-CLUSTER] cluster not exist, will create it: {}, service: {}", clusterName, serviceName); cluster = new Cluster(); cluster.setName(clusterName); + cluster.setService(service); } cluster.setDefCkport(NumberUtils.toInt(checkPort)); diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java index 8e3db54af..6452ad95d 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/InstanceController.java @@ -112,6 +112,7 @@ public class InstanceController { Service service = serviceManager.getService(namespaceId, serviceName); if (service == null) { + Loggers.SRV_LOG.warn("remove instance from non-exist service: {}", serviceName); return "ok"; } @@ -120,6 +121,7 @@ public class InstanceController { return "ok"; } + @CanDistro @RequestMapping(value = "", method = RequestMethod.PUT) public String update(HttpServletRequest request) throws Exception { String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME); @@ -332,10 +334,12 @@ public class InstanceController { String ip = WebUtils.required(request, "ip"); String port = WebUtils.required(request, "port"); String weight = WebUtils.optional(request, "weight", "1"); - String cluster = WebUtils.optional(request, CommonParams.CLUSTER_NAME, UtilsAndCommons.DEFAULT_CLUSTER_NAME); + String cluster = WebUtils.optional(request, CommonParams.CLUSTER_NAME, StringUtils.EMPTY); + if (StringUtils.isBlank(cluster)) { + cluster = WebUtils.optional(request, "cluster", UtilsAndCommons.DEFAULT_CLUSTER_NAME); + } boolean healthy = BooleanUtils.toBoolean(WebUtils.optional(request, "healthy", "true")); boolean enabled = BooleanUtils.toBoolean(WebUtils.optional(request, "enable", "true")); - // If server running in CP mode, we set this flag to false: boolean ephemeral = BooleanUtils.toBoolean(WebUtils.optional(request, "ephemeral", String.valueOf(switchDomain.isDefaultInstanceEphemeral()))); diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/Cluster.java b/naming/src/main/java/com/alibaba/nacos/naming/core/Cluster.java index c4bf49927..1001983fe 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/Cluster.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/Cluster.java @@ -99,7 +99,9 @@ public class Cluster extends com.alibaba.nacos.api.naming.pojo.Cluster implement } public void destroy() { - checkTask.setCancelled(true); + if (checkTask != null) { + checkTask.setCancelled(true); + } } public HealthCheckTask getHealthCheckTask() { diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/Instances.java b/naming/src/main/java/com/alibaba/nacos/naming/core/Instances.java index 933a7ea88..ef4e560e3 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/Instances.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/Instances.java @@ -20,6 +20,7 @@ import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.nacos.naming.misc.Loggers; import com.alibaba.nacos.naming.pojo.Record; import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.StringUtils; import java.math.BigInteger; import java.nio.charset.Charset; @@ -28,6 +29,7 @@ import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; /** * Package of instance list @@ -72,7 +74,7 @@ public class Instances implements Record { Collections.sort(instanceList); for (Instance ip : instanceList) { String string = ip.getIp() + ":" + ip.getPort() + "_" + ip.getWeight() + "_" - + ip.isHealthy() + "_" + ip.getClusterName(); + + ip.isHealthy() + "_" + ip.isEnabled() + "_" + ip.getClusterName() + "_" + convertMap2String(ip.getMetadata()); sb.append(string); sb.append(","); } @@ -87,4 +89,22 @@ public class Instances implements Record { } lastCalculateTime = System.currentTimeMillis(); } + + public String convertMap2String(Map map) { + + if (map == null || map.isEmpty()) { + return StringUtils.EMPTY; + } + + StringBuilder sb = new StringBuilder(); + List keys = new ArrayList<>(map.keySet()); + Collections.sort(keys); + for (String key : keys) { + sb.append(key); + sb.append(":"); + sb.append(map.get(key)); + sb.append(","); + } + return sb.toString(); + } } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/Service.java b/naming/src/main/java/com/alibaba/nacos/naming/core/Service.java index 170a8ded7..71d99ffc4 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/Service.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/Service.java @@ -217,6 +217,7 @@ public class Service extends com.alibaba.nacos.api.naming.pojo.Service implement instance.getClusterName(), instance.toJSON()); Cluster cluster = new Cluster(instance.getClusterName()); cluster.setService(this); + cluster.init(); getClusterMap().put(instance.getClusterName(), cluster); } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java b/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java index 466008473..c36a44a7f 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/ServiceManager.java @@ -168,7 +168,9 @@ public class ServiceManager implements RecordListener { if (service != null) { service.destroy(); consistencyService.remove(KeyBuilder.buildInstanceListKey(namespace, name, true)); + consistencyService.remove(KeyBuilder.buildInstanceListKey(namespace, name, false)); + consistencyService.unlisten(KeyBuilder.buildServiceMetaKey(namespace, name), service); Loggers.SRV_LOG.info("[DEAD-SERVICE] {}", service.toJSON()); } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/HealthCheckTask.java b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/HealthCheckTask.java index 47a303702..342e58abd 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/HealthCheckTask.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/HealthCheckTask.java @@ -72,7 +72,9 @@ public class HealthCheckTask implements Runnable { if (distroMapper.responsible(cluster.getService().getName()) && switchDomain.isHealthCheckEnabled(cluster.getService().getName())) { healthCheckProcessor.process(this); - Loggers.EVT_LOG.debug("[HEALTH-CHECK] schedule health check task: {}", cluster.getService().getName()); + if (Loggers.EVT_LOG.isDebugEnabled()) { + Loggers.EVT_LOG.debug("[HEALTH-CHECK] schedule health check task: {}", cluster.getService().getName()); + } } } catch (Throwable e) { Loggers.SRV_LOG.error("[HEALTH-CHECK] error while process health check for {}:{}", diff --git a/naming/src/main/java/com/alibaba/nacos/naming/misc/HttpClient.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/HttpClient.java index bad71625f..1a356661d 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/misc/HttpClient.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/misc/HttpClient.java @@ -482,6 +482,15 @@ public class HttpClient { return sb.toString(); } + public static Map translateParameterMap(Map parameterMap) { + + Map map = new HashMap<>(16); + for (String key : parameterMap.keySet()) { + map.put(key, parameterMap.get(key)[0]); + } + return map; + } + public static class HttpResult { final public int code; final public String content; diff --git a/naming/src/main/java/com/alibaba/nacos/naming/misc/NamingProxy.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/NamingProxy.java index bf3220f7e..e98795854 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/misc/NamingProxy.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/misc/NamingProxy.java @@ -236,4 +236,12 @@ public class NamingProxy { return sb.toString(); } } + + public static void main(String[] args) throws Exception { + + String key = "com.alibaba.nacos.naming.iplist.ephemeral.public##DEFAULT_GROUP@@test.10"; + List keys = new ArrayList<>(); + keys.add(key); + getData(keys, "11.239.112.161:8848"); + } } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/web/DistroFilter.java b/naming/src/main/java/com/alibaba/nacos/naming/web/DistroFilter.java index bc650dd27..67b32405c 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/web/DistroFilter.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/web/DistroFilter.java @@ -32,7 +32,10 @@ import java.io.IOException; import java.lang.reflect.Method; import java.net.URI; import java.security.AccessControlException; -import java.util.*; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; /** * @author nacos @@ -61,7 +64,11 @@ public class DistroFilter implements Filter { HttpServletRequest req = (HttpServletRequest) servletRequest; HttpServletResponse resp = (HttpServletResponse) servletResponse; - String urlString = req.getRequestURI() + "?" + req.getQueryString(); + String urlString = req.getRequestURI(); + + if (StringUtils.isNotBlank(req.getQueryString())) { + urlString += "?" + req.getQueryString(); + } try { String path = new URI(req.getRequestURI()).getPath(); @@ -98,7 +105,8 @@ public class DistroFilter implements Filter { headerList.add(req.getHeader(headerName)); } HttpClient.HttpResult result = - HttpClient.request("http://" + distroMapper.mapSrv(groupedServiceName) + urlString, headerList, new HashMap<>(2) + HttpClient.request("http://" + distroMapper.mapSrv(groupedServiceName) + urlString, headerList, + StringUtils.isBlank(req.getQueryString()) ? HttpClient.translateParameterMap(req.getParameterMap()) : new HashMap<>(2) , PROXY_CONNECT_TIMEOUT, PROXY_READ_TIMEOUT, "UTF-8", req.getMethod()); try { diff --git a/naming/src/main/resources/application.properties b/naming/src/main/resources/application.properties index 3dcc16718..437f17b5e 100644 --- a/naming/src/main/resources/application.properties +++ b/naming/src/main/resources/application.properties @@ -26,7 +26,7 @@ server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D # default current work dir server.tomcat.basedir= -nacos.naming.distro.taskDispatchThreadCount=10 +nacos.naming.distro.taskDispatchThreadCount=1 nacos.naming.distro.taskDispatchPeriod=200 nacos.naming.distro.batchSyncKeyCount=1000 nacos.naming.distro.initDataRatio=0.9 diff --git a/test/src/test/resources/application.properties b/test/src/test/resources/application.properties index b88b84cb4..13b314b3a 100644 --- a/test/src/test/resources/application.properties +++ b/test/src/test/resources/application.properties @@ -19,7 +19,7 @@ server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D # default current work dir server.tomcat.basedir= -nacos.naming.distro.taskDispatchThreadCount=10 +nacos.naming.distro.taskDispatchThreadCount=1 nacos.naming.distro.taskDispatchPeriod=200 nacos.naming.distro.batchSyncKeyCount=1000 nacos.naming.distro.initDataRatio=0.9