Merge branch 'master' into develop

# Conflicts:
#	api/pom.xml
#	client/pom.xml
#	cmdb/pom.xml
#	common/pom.xml
#	config/pom.xml
#	console/pom.xml
#	core/pom.xml
#	distribution/pom.xml
#	example/pom.xml
#	naming/pom.xml
#	pom.xml
#	test/pom.xml
This commit is contained in:
nkorange 2019-04-09 16:30:03 +08:00
commit cab10aa914
20 changed files with 86 additions and 15 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -187,6 +187,8 @@ public class DistroConsistencyServiceImpl implements EphemeralConsistencyService
return;
}
listeners.remove(key);
notifier.addTask(key, ApplyAction.DELETE);
}

View File

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

View File

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

View File

@ -809,6 +809,10 @@ public class RaftCore {
}
}
public void unlistenAll(String key) {
listeners.remove(key);
}
public void setTerm(long term) {
peers.setTerm(term);
}

View File

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

View File

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

View File

@ -99,8 +99,10 @@ public class Cluster extends com.alibaba.nacos.api.naming.pojo.Cluster implement
}
public void destroy() {
if (checkTask != null) {
checkTask.setCancelled(true);
}
}
public HealthCheckTask getHealthCheckTask() {
return checkTask;

View File

@ -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<String, String> map) {
if (map == null || map.isEmpty()) {
return StringUtils.EMPTY;
}
StringBuilder sb = new StringBuilder();
List<String> 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();
}
}

View File

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

View File

@ -168,7 +168,9 @@ public class ServiceManager implements RecordListener<Service> {
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());
}

View File

@ -72,8 +72,10 @@ public class HealthCheckTask implements Runnable {
if (distroMapper.responsible(cluster.getService().getName()) &&
switchDomain.isHealthCheckEnabled(cluster.getService().getName())) {
healthCheckProcessor.process(this);
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 {}:{}",
cluster.getService().getName(), cluster.getName(), e);

View File

@ -482,6 +482,15 @@ public class HttpClient {
return sb.toString();
}
public static Map<String, String> translateParameterMap(Map<String, String[]> parameterMap) {
Map<String, String> 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;

View File

@ -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<String> keys = new ArrayList<>();
keys.add(key);
getData(keys, "11.239.112.161:8848");
}
}

View File

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

View File

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

View File

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