Merge remote-tracking branch 'origin/hotfix-clientbeat-failed' into feature_ServiceMesh
This commit is contained in:
commit
1cf0a5b731
@ -126,4 +126,6 @@ public class Constants {
|
||||
public static final String NAMING_INSTANCE_ID_SPLITTER = "#";
|
||||
public static final int NAMING_INSTANCE_ID_SEG_COUNT = 4;
|
||||
public static final String NAMING_HTTP_HEADER_SPILIER = "\\|";
|
||||
|
||||
public static final String NAMING_DEFAULT_CLUSTER_NAME = "DEFAULT";
|
||||
}
|
||||
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.nacos.api.naming.pojo;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -31,7 +33,7 @@ public class Cluster {
|
||||
/**
|
||||
* Name of cluster
|
||||
*/
|
||||
private String name = "";
|
||||
private String name = Constants.NAMING_DEFAULT_CLUSTER_NAME;
|
||||
|
||||
/**
|
||||
* Health check config of this cluster
|
||||
|
@ -16,6 +16,7 @@
|
||||
package com.alibaba.nacos.client.naming;
|
||||
|
||||
import com.alibaba.nacos.api.PropertyKeyConst;
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.api.naming.NamingService;
|
||||
import com.alibaba.nacos.api.naming.listener.EventListener;
|
||||
@ -132,7 +133,7 @@ public class NacosNamingService implements NamingService {
|
||||
|
||||
@Override
|
||||
public void registerInstance(String serviceName, String ip, int port) throws NacosException {
|
||||
registerInstance(serviceName, ip, port, StringUtils.EMPTY);
|
||||
registerInstance(serviceName, ip, port, Constants.NAMING_DEFAULT_CLUSTER_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -162,7 +163,7 @@ public class NacosNamingService implements NamingService {
|
||||
|
||||
@Override
|
||||
public void deregisterInstance(String serviceName, String ip, int port) throws NacosException {
|
||||
deregisterInstance(serviceName, ip, port, StringUtils.EMPTY);
|
||||
deregisterInstance(serviceName, ip, port, Constants.NAMING_DEFAULT_CLUSTER_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -42,7 +42,7 @@ public class LogUtils {
|
||||
|
||||
// logger init
|
||||
LOG = LoggerFactory.getLogger("com.alibaba.nacos.client.naming");
|
||||
LOG.setLevel(Level.INFO);
|
||||
LOG.setLevel(Level.DEBUG);
|
||||
LOG.setAdditivity(false);
|
||||
LOG.activateAppenderWithSizeRolling("nacos", "naming.log", "UTF-8", JM_LOG_FILE_SIZE, JM_LOG_RETAIN_COUNT);
|
||||
}
|
||||
|
@ -167,6 +167,23 @@
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="naming-tenant"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${nacos.home}/logs/naming-tenant.log</file>
|
||||
<append>true</append>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${nacos.home}/logs/naming-tenant.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
|
||||
<maxFileSize>1GB</maxFileSize>
|
||||
<MaxHistory>15</MaxHistory>
|
||||
<totalSizeCap>3GB</totalSizeCap>
|
||||
<cleanHistoryOnStart>true</cleanHistoryOnStart>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<Pattern>%date %level %msg%n%n</Pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="naming-debug"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${nacos.home}/logs/naming-debug.log</file>
|
||||
@ -435,6 +452,10 @@
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="naming-cache"/>
|
||||
</logger>
|
||||
<logger name="com.alibaba.nacos.naming.tenant" additivity="false">
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="naming-tenant"/>
|
||||
</logger>
|
||||
<logger name="com.alibaba.nacos.naming.debug" additivity="false">
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="naming-debug"/>
|
||||
|
@ -35,6 +35,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@ -58,6 +59,8 @@ public class DomainsManager {
|
||||
|
||||
private final Lock lock = new ReentrantLock();
|
||||
|
||||
private Map<String, Condition> dom2ContionMap = new ConcurrentHashMap<>();
|
||||
|
||||
private Map<String, Lock> dom2LockMap = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
@ -651,18 +654,22 @@ public class DomainsManager {
|
||||
dom2LockMap.put(dom.getName(), new ReentrantLock());
|
||||
}
|
||||
|
||||
Lock lock = dom2LockMap.get(dom.getName());
|
||||
|
||||
|
||||
synchronized (lock) {
|
||||
raftDomMap.put(dom.getName(), dom);
|
||||
dom.init();
|
||||
lock.notifyAll();
|
||||
}
|
||||
raftDomMap.put(dom.getName(), dom);
|
||||
dom.init();
|
||||
|
||||
Loggers.SRV_LOG.info("[NEW-DOM-raft] " + dom.toJSON());
|
||||
}
|
||||
|
||||
Lock lock = dom2LockMap.get(dom.getName());
|
||||
Condition condition = dom2ContionMap.get(dom.getName());
|
||||
|
||||
try {
|
||||
lock.lock();
|
||||
condition.signalAll();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
Loggers.SRV_LOG.error("VIPSRV-DOM", "error while processing dom update", e);
|
||||
}
|
||||
@ -690,6 +697,12 @@ public class DomainsManager {
|
||||
return lock;
|
||||
}
|
||||
|
||||
public Condition addCondtion(String domName) {
|
||||
Condition condition = dom2LockMap.get(domName).newCondition();
|
||||
dom2ContionMap.put(domName, condition);
|
||||
return condition;
|
||||
}
|
||||
|
||||
public Map<String, Domain> getDomMap() {
|
||||
return new HashMap<String, Domain>(domMap);
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ 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;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@ -272,11 +273,18 @@ public class ApiCommands {
|
||||
public JSONObject clientBeat(HttpServletRequest request) throws Exception {
|
||||
String beat = BaseServlet.required(request, "beat");
|
||||
RsInfo clientBeat = JSON.parseObject(beat, RsInfo.class);
|
||||
if (StringUtils.isBlank(clientBeat.getCluster())) {
|
||||
clientBeat.setCluster(UtilsAndCommons.DEFAULT_CLUSTER_NAME);
|
||||
}
|
||||
String dom = BaseServlet.required(request, "dom");
|
||||
String app;
|
||||
app = BaseServlet.optional(request, "app", StringUtils.EMPTY);
|
||||
String clusterName = clientBeat.getCluster();
|
||||
|
||||
if (StringUtils.isBlank(clusterName)) {
|
||||
clusterName = UtilsAndCommons.DEFAULT_CLUSTER_NAME;
|
||||
}
|
||||
|
||||
Loggers.TENANT.debug("client-beat", "beat: " + beat);
|
||||
VirtualClusterDomain virtualClusterDomain = (VirtualClusterDomain) domainsManager.getDomain(dom);
|
||||
|
||||
@ -544,9 +552,13 @@ public class ApiCommands {
|
||||
regDom(request);
|
||||
|
||||
Lock lock = domainsManager.addLock(dom);
|
||||
Condition condition = domainsManager.addCondtion(dom);
|
||||
|
||||
synchronized (lock) {
|
||||
lock.wait(5000L);
|
||||
try {
|
||||
lock.lock();
|
||||
condition.await(5000, TimeUnit.MILLISECONDS);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
virtualClusterDomain = (VirtualClusterDomain) domainsManager.getDomain(dom);
|
||||
|
Loading…
Reference in New Issue
Block a user