Merge pull request #309 from alibaba/develop

Develop
This commit is contained in:
Fury Zhu 2018-11-19 17:38:40 +08:00 committed by GitHub
commit e773ef26a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 35 deletions

View File

@ -58,7 +58,7 @@ public class DomainsManager {
private final Lock lock = new ReentrantLock();
private Map<String, Condition> dom2ContionMap = new ConcurrentHashMap<>();
private Map<String, Condition> dom2ConditionMap = new ConcurrentHashMap<>();
private Map<String, Lock> dom2LockMap = new ConcurrentHashMap<>();
@ -328,7 +328,9 @@ public class DomainsManager {
for (IpAddress ipAddress : ips) {
if (!dom.getClusterMap().containsKey(ipAddress.getClusterName())) {
dom.getClusterMap().put(ipAddress.getClusterName(), new Cluster(ipAddress.getClusterName()));
Cluster cluster = new Cluster(ipAddress.getClusterName());
cluster.setDom(dom);
dom.getClusterMap().put(ipAddress.getClusterName(), cluster);
Loggers.SRV_LOG.warn("cluster: " + ipAddress.getClusterName() + " not found, ip: " + ipAddress.toJSON()
+ ", will create new cluster with default configuration.");
}
@ -627,7 +629,7 @@ public class DomainsManager {
}
Lock lock = dom2LockMap.get(dom.getName());
Condition condition = dom2ContionMap.get(dom.getName());
Condition condition = dom2ConditionMap.get(dom.getName());
try {
lock.lock();
@ -666,7 +668,7 @@ public class DomainsManager {
public Condition addCondtion(String domName) {
Condition condition = dom2LockMap.get(domName).newCondition();
dom2ContionMap.put(domName, condition);
dom2ConditionMap.put(domName, condition);
return condition;
}

View File

@ -158,7 +158,8 @@ public class VirtualClusterDomain implements Domain, RaftListener {
public void onChange(String key, String value) throws Exception {
if (StringUtils.isEmpty(value)) {
Loggers.SRV_LOG.warn("VIPSRV-DOM", "received empty iplist config for dom: " + name);
Loggers.SRV_LOG.warn("[VIPSRV-DOM] received empty iplist config for dom: " + name);
return;
}
Loggers.RAFT.info("[VIPSRV-RAFT] datum is changed, key: " + key + ", value: " + value);
@ -302,7 +303,7 @@ public class VirtualClusterDomain implements Domain, RaftListener {
for (String cluster : clusters) {
Cluster clusterObj = clusterMap.get(cluster);
if (clusterObj == null) {
throw new IllegalArgumentException("can not find cluster: " + cluster);
throw new IllegalArgumentException("can not find cluster: " + cluster + ", dom:" + getName());
}
allIPs.addAll(clusterObj.allIPs());

View File

@ -47,13 +47,11 @@ public class HealthCheckReactor {
public static ScheduledFuture<?> scheduleCheck(HealthCheckTask task) {
task.setStartTime(System.currentTimeMillis());
return EXECUTOR.schedule(task, task.getCheckRTNormalized(), TimeUnit.MILLISECONDS);
}
public static void scheduleCheck(ClientBeatCheckTask task) {
futureMap.putIfAbsent(task.taskKey(), EXECUTOR.scheduleWithFixedDelay(task, 5000, 5000, TimeUnit.MILLISECONDS));
// return EXECUTOR.schedule(task, 5000, TimeUnit.MILLISECONDS);
}
public static void cancelCheck(ClientBeatCheckTask task) {

View File

@ -17,7 +17,6 @@ package com.alibaba.nacos.naming.misc;
import com.alibaba.nacos.common.util.SystemUtils;
import com.alibaba.nacos.naming.boot.RunningConfig;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@ -30,9 +29,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import static com.alibaba.nacos.common.util.SystemUtils.CLUSTER_CONF_FILE_PATH;
import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
import static com.alibaba.nacos.common.util.SystemUtils.readClusterConf;
import static com.alibaba.nacos.common.util.SystemUtils.*;
/**
* @author nacos
@ -99,10 +96,6 @@ public class NamingProxy {
}
public static void refreshSrvIfNeed() {
refreshSrvIfNeed(StringUtils.EMPTY);
}
public static void refreshSrvIfNeed(String env) {
try {
if (System.currentTimeMillis() - lastSrvRefTime < VIP_SRV_REF_INTER_MILLIS) {
return;
@ -116,24 +109,12 @@ public class NamingProxy {
List<String> serverlist = refreshServerListFromDisk();
List<String> list = new ArrayList<String>();
if (!CollectionUtils.isEmpty(serverlist)) {
serverlistFromConfig = serverlist;
if (list.isEmpty()) {
Loggers.SRV_LOG.warn("Can not acquire server list");
}
}
if (!StringUtils.isEmpty(env)) {
serverListMap.put(env, list);
} else {
if (!CollectionUtils.isEqualCollection(serverlistFromConfig, list) && CollectionUtils.isNotEmpty(serverlistFromConfig)) {
Loggers.SRV_LOG.info("[SERVER-LIST] server list is not the same between AS and config file, use config file.");
if (!CollectionUtils.isEqualCollection(serverlistFromConfig, servers) && CollectionUtils.isNotEmpty(serverlistFromConfig)) {
servers = serverlistFromConfig;
} else {
servers = list;
}
}
if (RunningConfig.getServerPort() > 0) {

View File

@ -20,8 +20,6 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker;
import com.alibaba.nacos.api.naming.pojo.Service;
import com.alibaba.nacos.common.util.IoUtils;
import com.alibaba.nacos.common.util.Md5Utils;
import com.alibaba.nacos.common.util.SystemUtils;
import com.alibaba.nacos.naming.boot.RunningConfig;
@ -55,7 +53,10 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.InetSocketAddress;
@ -63,7 +64,6 @@ import java.security.AccessControlException;
import java.security.InvalidParameterException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
@ -563,7 +563,16 @@ public class ApiCommands {
Lock lock = domainsManager.addLock(dom);
Condition condition = domainsManager.addCondtion(dom);
UtilsAndCommons.RAFT_PUBLISH_EXECUTOR.execute(new Runnable() {
@Override
public void run() {
try {
regDom(request);
} catch (Exception e) {
Loggers.SRV_LOG.error("REG-SERIVCE", "register service failed, service:" + dom, e);
}
}
});
try {
lock.lock();
condition.await(5000, TimeUnit.MILLISECONDS);