fix: fix old version information not available in new version reality issue
This commit is contained in:
parent
6fb2750021
commit
a7556fa776
@ -25,19 +25,22 @@ public class MemberMetaDataConstants {
|
||||
/**
|
||||
* Raft port,This parameter is dropped when GRPC is used as a whole
|
||||
*/
|
||||
public static final String RAFT_PORT = "raft_port";
|
||||
public static final String RAFT_PORT = "raftPort";
|
||||
|
||||
public static final String SITE_KEY = "site";
|
||||
|
||||
public static final String AD_WEIGHT = "adweight";
|
||||
public static final String AD_WEIGHT = "adWeight";
|
||||
|
||||
public static final String WEIGHT = "weight";
|
||||
|
||||
public static final String LAST_REFRESH_TIME = "lastRefreshTime";
|
||||
|
||||
public static final String[] META_KEY_LIST = new String[]{
|
||||
RAFT_PORT,
|
||||
SITE_KEY,
|
||||
AD_WEIGHT,
|
||||
WEIGHT,
|
||||
LAST_REFRESH_TIME,
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -134,9 +134,7 @@ public class MemberUtils {
|
||||
|
||||
@SuppressWarnings("PMD.UndefineMagicConstantRule")
|
||||
public static Collection<Member> kRandom(Collection<Member> members,
|
||||
Predicate<Member> filter) {
|
||||
int k = ApplicationUtils
|
||||
.getProperty("nacos.core.member.report.random-num", Integer.class, 3);
|
||||
Predicate<Member> filter, int k) {
|
||||
|
||||
Set<Member> kMembers = new HashSet<>();
|
||||
|
||||
|
@ -199,11 +199,7 @@ public class ServerMemberManager
|
||||
Loggers.CLUSTER.debug("Node information update : {}", newMember);
|
||||
|
||||
String address = newMember.getAddress();
|
||||
|
||||
if (Objects.equals(newMember, self)) {
|
||||
serverList.put(newMember.getAddress(), newMember);
|
||||
return true;
|
||||
}
|
||||
newMember.setExtendVal(MemberMetaDataConstants.LAST_REFRESH_TIME, System.currentTimeMillis());
|
||||
|
||||
if (!serverList.containsKey(address)) {
|
||||
return false;
|
||||
|
@ -204,7 +204,7 @@ public class JRaftProtocol
|
||||
|
||||
private void injectProtocolMetaData(ProtocolMetaData metaData) {
|
||||
Member member = memberManager.getSelf();
|
||||
member.setExtendVal("raft_meta_data", metaData);
|
||||
member.setExtendVal("raftMetaData", metaData);
|
||||
memberManager.update(member);
|
||||
}
|
||||
|
||||
|
@ -1,2 +0,0 @@
|
||||
/Users/liaochuntao/.sdkman/candidates/java/current/bin/java -DembeddedStorage=true -server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/Volumes/resources/github/nacos/distribution/logs/java_heapdump.hprof -XX:-UseLargePages -Dnacos.member.list=127.0.0.1:8080 -Djava.ext.dirs=/Users/liaochuntao/.sdkman/candidates/java/current/jre/lib/ext:/Users/liaochuntao/.sdkman/candidates/java/current/lib/ext -Xloggc:/Volumes/resources/github/nacos/distribution/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -Dloader.path=/Volumes/resources/github/nacos/distribution/plugins/health,/Volumes/resources/github/nacos/distribution/plugins/cmdb,/Volumes/resources/github/nacos/distribution/plugins/mysql -Dnacos.home=/Volumes/resources/github/nacos/distribution -jar /Volumes/resources/github/nacos/distribution/target/nacos-server.jar --spring.config.location=classpath:/,classpath:/config/,file:./,file:./config/,file:/Volumes/resources/github/nacos/distribution/conf/ --logging.config=/Volumes/resources/github/nacos/distribution/conf/nacos-logback.xml --server.max-http-header-size=524288
|
||||
Error: Unable to access jarfile /Volumes/resources/github/nacos/distribution/target/nacos-server.jar
|
@ -1,229 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.naming.cluster;
|
||||
|
||||
import com.alibaba.nacos.common.utils.JacksonUtils;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
|
||||
/**
|
||||
* Member node of Nacos cluster
|
||||
*
|
||||
* // TODO This object will be deleted sometime after version 1.3.0
|
||||
*
|
||||
* @author nkorange
|
||||
* @since 1.0.0
|
||||
* @deprecated 1.3.0
|
||||
*/
|
||||
public class Server implements Comparable<Server> {
|
||||
|
||||
/**
|
||||
* IP of member
|
||||
*/
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* serving port of member.
|
||||
*/
|
||||
private int servePort;
|
||||
|
||||
private String site = UtilsAndCommons.UNKNOWN_SITE;
|
||||
|
||||
private int weight = 1;
|
||||
|
||||
/**
|
||||
* additional weight, used to adjust manually
|
||||
*/
|
||||
private int adWeight;
|
||||
|
||||
private boolean alive = false;
|
||||
|
||||
private long lastRefTime = 0L;
|
||||
|
||||
private String lastRefTimeStr;
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public int getServePort() {
|
||||
return servePort;
|
||||
}
|
||||
|
||||
public void setServePort(int servePort) {
|
||||
this.servePort = servePort;
|
||||
}
|
||||
|
||||
public String getSite() {
|
||||
return site;
|
||||
}
|
||||
|
||||
public void setSite(String site) {
|
||||
this.site = site;
|
||||
}
|
||||
|
||||
public int getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public void setWeight(int weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public int getAdWeight() {
|
||||
return adWeight;
|
||||
}
|
||||
|
||||
public void setAdWeight(int adWeight) {
|
||||
this.adWeight = adWeight;
|
||||
}
|
||||
|
||||
public boolean isAlive() {
|
||||
return alive;
|
||||
}
|
||||
|
||||
public void setAlive(boolean alive) {
|
||||
this.alive = alive;
|
||||
}
|
||||
|
||||
public long getLastRefTime() {
|
||||
return lastRefTime;
|
||||
}
|
||||
|
||||
public void setLastRefTime(long lastRefTime) {
|
||||
this.lastRefTime = lastRefTime;
|
||||
}
|
||||
|
||||
public String getLastRefTimeStr() {
|
||||
return lastRefTimeStr;
|
||||
}
|
||||
|
||||
public void setLastRefTimeStr(String lastRefTimeStr) {
|
||||
this.lastRefTimeStr = lastRefTimeStr;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return ip + UtilsAndCommons.IP_PORT_SPLITER + servePort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Server server = (Server) o;
|
||||
return servePort == server.servePort && ip.equals(server.ip);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = ip.hashCode();
|
||||
result = 31 * result + servePort;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JacksonUtils.toJson(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Server server) {
|
||||
if (server == null) {
|
||||
return 1;
|
||||
}
|
||||
return this.getKey().compareTo(server.getKey());
|
||||
}
|
||||
|
||||
public static ServerBuilder builder() {
|
||||
return new ServerBuilder();
|
||||
}
|
||||
|
||||
public static final class ServerBuilder {
|
||||
private String ip;
|
||||
private int servePort;
|
||||
private String site = UtilsAndCommons.UNKNOWN_SITE;
|
||||
private int weight = 1;
|
||||
private int adWeight;
|
||||
private boolean alive = false;
|
||||
private long lastRefTime = 0L;
|
||||
private String lastRefTimeStr;
|
||||
|
||||
private ServerBuilder() {
|
||||
}
|
||||
|
||||
public ServerBuilder ip(String ip) {
|
||||
this.ip = ip;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ServerBuilder servePort(int servePort) {
|
||||
this.servePort = servePort;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ServerBuilder site(String site) {
|
||||
this.site = site;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ServerBuilder weight(int weight) {
|
||||
this.weight = weight;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ServerBuilder adWeight(int adWeight) {
|
||||
this.adWeight = adWeight;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ServerBuilder alive(boolean alive) {
|
||||
this.alive = alive;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ServerBuilder lastRefTime(long lastRefTime) {
|
||||
this.lastRefTime = lastRefTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ServerBuilder lastRefTimeStr(String lastRefTimeStr) {
|
||||
this.lastRefTimeStr = lastRefTimeStr;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Server build() {
|
||||
Server server = new Server();
|
||||
server.setIp(ip);
|
||||
server.setServePort(servePort);
|
||||
server.setSite(site);
|
||||
server.setWeight(weight);
|
||||
server.setAdWeight(adWeight);
|
||||
server.setAlive(alive);
|
||||
server.setLastRefTime(lastRefTime);
|
||||
server.setLastRefTimeStr(lastRefTimeStr);
|
||||
return server;
|
||||
}
|
||||
}
|
||||
}
|
@ -17,34 +17,33 @@
|
||||
package com.alibaba.nacos.naming.cluster;
|
||||
|
||||
import com.alibaba.nacos.common.utils.JacksonUtils;
|
||||
import com.alibaba.nacos.core.cluster.Member;
|
||||
import com.alibaba.nacos.core.cluster.MemberChangeEvent;
|
||||
import com.alibaba.nacos.core.cluster.MemberChangeListener;
|
||||
import com.alibaba.nacos.core.cluster.MemberMetaDataConstants;
|
||||
import com.alibaba.nacos.core.cluster.NodeState;
|
||||
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
||||
import com.alibaba.nacos.core.notify.NotifyCenter;
|
||||
import com.alibaba.nacos.core.utils.ApplicationUtils;
|
||||
import com.alibaba.nacos.naming.consistency.persistent.raft.RaftPeer;
|
||||
import com.alibaba.nacos.naming.misc.GlobalExecutor;
|
||||
import com.alibaba.nacos.naming.misc.Loggers;
|
||||
import com.alibaba.nacos.naming.misc.Message;
|
||||
import com.alibaba.nacos.naming.misc.NamingProxy;
|
||||
import com.alibaba.nacos.naming.misc.NetUtils;
|
||||
import com.alibaba.nacos.naming.misc.ServerStatusSynchronizer;
|
||||
import com.alibaba.nacos.naming.misc.SwitchDomain;
|
||||
import com.alibaba.nacos.naming.misc.Synchronizer;
|
||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* The manager to globally refresh and operate server list.
|
||||
@ -58,55 +57,46 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
@Component("serverListManager")
|
||||
public class ServerListManager implements MemberChangeListener {
|
||||
|
||||
private static final int STABLE_PERIOD = 60 * 1000;
|
||||
private final static String LOCALHOST_SITE = UtilsAndCommons.UNKNOWN_SITE;
|
||||
|
||||
private final SwitchDomain switchDomain;
|
||||
private final ServerMemberManager memberManager;
|
||||
private final Synchronizer synchronizer = new ServerStatusSynchronizer();
|
||||
|
||||
private volatile List<Server> servers;
|
||||
|
||||
private volatile List<Server> healthyServers = Collections.emptyList();
|
||||
|
||||
private Map<String, List<Server>> distroConfig = new ConcurrentHashMap<>(16);
|
||||
|
||||
private Map<String, Long> distroBeats = new ConcurrentHashMap<>(16);
|
||||
|
||||
private Set<String> liveSites = new HashSet<>();
|
||||
|
||||
private final static String LOCALHOST_SITE = UtilsAndCommons.UNKNOWN_SITE;
|
||||
|
||||
private long lastHealthServerMillis = 0L;
|
||||
|
||||
private boolean autoDisabledHealthCheck = false;
|
||||
|
||||
private Synchronizer synchronizer = new ServerStatusSynchronizer();
|
||||
private volatile List<Member> servers;
|
||||
|
||||
public ServerListManager(final SwitchDomain switchDomain,
|
||||
final ServerMemberManager memberManager) {
|
||||
this.switchDomain = switchDomain;
|
||||
this.memberManager = memberManager;
|
||||
NotifyCenter.registerSubscribe(this);
|
||||
this.servers = ServerUtils.toServers(memberManager.allMembers());
|
||||
this.servers = new ArrayList<>(memberManager.allMembers());
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
GlobalExecutor.registerServerStatusReporter(new ServerStatusReporter(), 2000);
|
||||
GlobalExecutor.registerServerInfoUpdater(new ServerInfoUpdater());
|
||||
}
|
||||
|
||||
public boolean contains(String s) {
|
||||
for (Server server : getServers()) {
|
||||
if (server.getKey().equals(s)) {
|
||||
for (Member server : getServers()) {
|
||||
if (Objects.equals(s, server.getAddress())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<Server> getServers() {
|
||||
public List<Member> getServers() {
|
||||
return servers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(MemberChangeEvent event) {
|
||||
this.servers = new ArrayList<>(event.getMembers());
|
||||
}
|
||||
|
||||
public synchronized void onReceiveServerStatus(String configInfo) {
|
||||
|
||||
Loggers.SRV_LOG.info("receive config info: {}", configInfo);
|
||||
@ -116,11 +106,7 @@ public class ServerListManager implements MemberChangeListener {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Server> newHealthyList = new ArrayList<>();
|
||||
List<Server> tmpServerList = new ArrayList<>();
|
||||
|
||||
for (String config : configs) {
|
||||
tmpServerList.clear();
|
||||
// site:ip:lastReportTime:weight
|
||||
String[] params = config.split("#");
|
||||
if (params.length <= 3) {
|
||||
@ -128,103 +114,56 @@ public class ServerListManager implements MemberChangeListener {
|
||||
continue;
|
||||
}
|
||||
|
||||
Server server = new Server();
|
||||
Member server = Member.builder()
|
||||
.ip(params[1].split(UtilsAndCommons.IP_PORT_SPLITER)[0])
|
||||
.state(NodeState.UP)
|
||||
.port(Integer.parseInt(params[1].split(UtilsAndCommons.IP_PORT_SPLITER)[1]))
|
||||
.build();
|
||||
|
||||
server.setSite(params[0]);
|
||||
server.setIp(params[1].split(UtilsAndCommons.IP_PORT_SPLITER)[0]);
|
||||
server.setServePort(Integer.parseInt(params[1].split(UtilsAndCommons.IP_PORT_SPLITER)[1]));
|
||||
server.setLastRefTime(Long.parseLong(params[2]));
|
||||
server.setExtendVal(MemberMetaDataConstants.SITE_KEY, params[0]);
|
||||
server.setExtendVal(MemberMetaDataConstants.WEIGHT, params.length == 4 ? Integer.parseInt(params[3]) : 1);
|
||||
memberManager.update(server);
|
||||
|
||||
if (!contains(server.getKey())) {
|
||||
throw new IllegalArgumentException("server: " + server.getKey() + " is not in serverlist");
|
||||
if (!contains(server.getAddress())) {
|
||||
throw new IllegalArgumentException("server: " + server.getAddress() + " is not in serverlist");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ServerInfoUpdater implements Runnable {
|
||||
|
||||
private int cursor = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
List<Member> members = servers;
|
||||
if (members.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Long lastBeat = distroBeats.get(server.getKey());
|
||||
long now = System.currentTimeMillis();
|
||||
if (null != lastBeat) {
|
||||
server.setAlive(now - lastBeat < switchDomain.getDistroServerExpiredMillis());
|
||||
this.cursor = (this.cursor + 1) % members.size();
|
||||
Member target = members.get(cursor);
|
||||
String path = UtilsAndCommons.NACOS_NAMING_OPERATOR_CONTEXT + UtilsAndCommons.NACOS_NAMING_CLUSTER_CONTEXT + "/state";
|
||||
Map<String, String> params = Maps.newHashMapWithExpectedSize(2);
|
||||
String server = target.getAddress();
|
||||
if (Objects.equals(target.getAddress(), ApplicationUtils.getLocalAddress())) {
|
||||
server = UtilsAndCommons.LOCAL_HOST_IP + ":" + target.getPort();
|
||||
}
|
||||
distroBeats.put(server.getKey(), now);
|
||||
|
||||
Date date = new Date(Long.parseLong(params[2]));
|
||||
server.setLastRefTimeStr(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));
|
||||
|
||||
server.setWeight(params.length == 4 ? Integer.parseInt(params[3]) : 1);
|
||||
List<Server> list = distroConfig.get(server.getSite());
|
||||
if (list == null || list.size() <= 0) {
|
||||
list = new ArrayList<>();
|
||||
list.add(server);
|
||||
distroConfig.put(server.getSite(), list);
|
||||
}
|
||||
|
||||
for (Server s : list) {
|
||||
String serverId = s.getKey() + "_" + s.getSite();
|
||||
String newServerId = server.getKey() + "_" + server.getSite();
|
||||
|
||||
if (serverId.equals(newServerId)) {
|
||||
if (s.isAlive() != server.isAlive() || s.getWeight() != server.getWeight()) {
|
||||
Loggers.SRV_LOG.warn("server beat out of date, current: {}, last: {}",
|
||||
JacksonUtils.toJson(server), JacksonUtils.toJson(s));
|
||||
try {
|
||||
String content = NamingProxy.reqCommon(path, params, server, false);
|
||||
if (!StringUtils.EMPTY.equals(content)) {
|
||||
RaftPeer raftPeer = JacksonUtils.toObj(content, RaftPeer.class);
|
||||
if (null != raftPeer) {
|
||||
String json = JacksonUtils.toJson(raftPeer);
|
||||
Map map = JacksonUtils.toObj(json, HashMap.class);
|
||||
target.setExtendVal("naming", map);
|
||||
memberManager.update(target);
|
||||
}
|
||||
tmpServerList.add(server);
|
||||
continue;
|
||||
}
|
||||
tmpServerList.add(s);
|
||||
} catch (Exception ignore) {
|
||||
//
|
||||
}
|
||||
|
||||
if (!tmpServerList.contains(server)) {
|
||||
tmpServerList.add(server);
|
||||
}
|
||||
|
||||
distroConfig.put(server.getSite(), tmpServerList);
|
||||
}
|
||||
liveSites.addAll(distroConfig.keySet());
|
||||
}
|
||||
|
||||
public void clean() {
|
||||
cleanInvalidServers();
|
||||
|
||||
for (Map.Entry<String, List<Server>> entry : distroConfig.entrySet()) {
|
||||
for (Server server : entry.getValue()) {
|
||||
//request other server to clean invalid servers
|
||||
if (!server.getKey().equals(NetUtils.localServer())) {
|
||||
requestOtherServerCleanInvalidServers(server.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Set<String> getLiveSites() {
|
||||
return liveSites;
|
||||
}
|
||||
|
||||
private void cleanInvalidServers() {
|
||||
for (Map.Entry<String, List<Server>> entry : distroConfig.entrySet()) {
|
||||
List<Server> currentServers = entry.getValue();
|
||||
if (null == currentServers) {
|
||||
distroConfig.remove(entry.getKey());
|
||||
continue;
|
||||
}
|
||||
|
||||
currentServers.removeIf(server -> !server.isAlive());
|
||||
}
|
||||
}
|
||||
|
||||
private void requestOtherServerCleanInvalidServers(String serverIP) {
|
||||
Map<String, String> params = new HashMap<String, String>(1);
|
||||
|
||||
params.put("action", "without-diamond-clean");
|
||||
try {
|
||||
NamingProxy.reqAPI("distroStatus", params, serverIP, false);
|
||||
} catch (Exception e) {
|
||||
Loggers.SRV_LOG.warn("[DISTRO-STATUS-CLEAN] Failed to request to clean server status to " + serverIP, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(MemberChangeEvent event) {
|
||||
this.servers = ServerUtils.toServers(memberManager.allMembers());
|
||||
}
|
||||
|
||||
private class ServerStatusReporter implements Runnable {
|
||||
@ -237,37 +176,31 @@ public class ServerListManager implements MemberChangeListener {
|
||||
return;
|
||||
}
|
||||
|
||||
checkDistroHeartbeat();
|
||||
|
||||
int weight = Runtime.getRuntime().availableProcessors() / 2;
|
||||
if (weight <= 0) {
|
||||
weight = 1;
|
||||
}
|
||||
|
||||
long curTime = System.currentTimeMillis();
|
||||
String status = LOCALHOST_SITE + "#" + NetUtils.localServer() + "#" + curTime + "#" + weight + "\r\n";
|
||||
String status = LOCALHOST_SITE + "#" + ApplicationUtils.getLocalAddress() + "#" + curTime + "#" + weight + "\r\n";
|
||||
|
||||
//send status to itself
|
||||
onReceiveServerStatus(status);
|
||||
List<Member> allServers = getServers();
|
||||
|
||||
List<Server> allServers = getServers();
|
||||
|
||||
if (!contains(NetUtils.localServer())) {
|
||||
Loggers.SRV_LOG.error("local ip is not in serverlist, ip: {}, serverlist: {}", NetUtils.localServer(), allServers);
|
||||
if (!contains(ApplicationUtils.getLocalAddress())) {
|
||||
Loggers.SRV_LOG.error("local ip is not in serverlist, ip: {}, serverlist: {}", ApplicationUtils.getLocalAddress(), allServers);
|
||||
return;
|
||||
}
|
||||
|
||||
if (allServers.size() > 0 && !ApplicationUtils.getLocalAddress().contains(UtilsAndCommons.LOCAL_HOST_IP)) {
|
||||
for (Server server : allServers) {
|
||||
if (server.getKey().equals(ApplicationUtils.getLocalAddress())) {
|
||||
for (Member server : allServers) {
|
||||
if (Objects.equals(server.getAddress(), ApplicationUtils.getLocalAddress())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Message msg = new Message();
|
||||
msg.setData(status);
|
||||
|
||||
synchronizer.send(server.getKey(), msg);
|
||||
|
||||
synchronizer.send(server.getAddress(), msg);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -279,76 +212,4 @@ public class ServerListManager implements MemberChangeListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDistroHeartbeat() {
|
||||
|
||||
Loggers.SRV_LOG.debug("check distro heartbeat.");
|
||||
|
||||
List<Server> servers = distroConfig.get(LOCALHOST_SITE);
|
||||
if (CollectionUtils.isEmpty(servers)) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Server> newHealthyList = new ArrayList<>(servers.size());
|
||||
long now = System.currentTimeMillis();
|
||||
for (Server s: servers) {
|
||||
Long lastBeat = distroBeats.get(s.getKey());
|
||||
if (null == lastBeat) {
|
||||
continue;
|
||||
}
|
||||
s.setAlive(now - lastBeat < switchDomain.getDistroServerExpiredMillis());
|
||||
}
|
||||
|
||||
//local site servers
|
||||
List<String> allLocalSiteSrvs = new ArrayList<>();
|
||||
for (Server server : servers) {
|
||||
|
||||
if (server.getKey().endsWith(":0")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
server.setAdWeight(switchDomain.getAdWeight(server.getKey()) == null ? 0 : switchDomain.getAdWeight(server.getKey()));
|
||||
|
||||
for (int i = 0; i < server.getWeight() + server.getAdWeight(); i++) {
|
||||
|
||||
if (!allLocalSiteSrvs.contains(server.getKey())) {
|
||||
allLocalSiteSrvs.add(server.getKey());
|
||||
}
|
||||
|
||||
if (server.isAlive() && !newHealthyList.contains(server)) {
|
||||
newHealthyList.add(server);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(newHealthyList);
|
||||
float curRatio = (float) newHealthyList.size() / allLocalSiteSrvs.size();
|
||||
|
||||
if (autoDisabledHealthCheck
|
||||
&& curRatio > switchDomain.getDistroThreshold()
|
||||
&& System.currentTimeMillis() - lastHealthServerMillis > STABLE_PERIOD) {
|
||||
Loggers.SRV_LOG.info("[NACOS-DISTRO] distro threshold restored and " +
|
||||
"stable now, enable health check. current ratio: {}", curRatio);
|
||||
|
||||
switchDomain.setHealthCheckEnabled(true);
|
||||
|
||||
// we must set this variable, otherwise it will conflict with user's action
|
||||
autoDisabledHealthCheck = false;
|
||||
}
|
||||
|
||||
if (!CollectionUtils.isEqualCollection(healthyServers, newHealthyList)) {
|
||||
// for every change disable healthy check for some while
|
||||
Loggers.SRV_LOG.info("[NACOS-DISTRO] healthy server list changed, old: {}, new: {}",
|
||||
healthyServers, newHealthyList);
|
||||
if (switchDomain.isHealthCheckEnabled() && switchDomain.isAutoChangeHealthCheckEnabled()) {
|
||||
Loggers.SRV_LOG.info("[NACOS-DISTRO] disable health check for {} ms from now on.", STABLE_PERIOD);
|
||||
|
||||
switchDomain.setHealthCheckEnabled(false);
|
||||
autoDisabledHealthCheck = true;
|
||||
|
||||
lastHealthServerMillis = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
healthyServers = newHealthyList;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.naming.cluster;
|
||||
|
||||
import com.alibaba.nacos.core.cluster.Member;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
|
||||
*/
|
||||
public final class ServerUtils {
|
||||
|
||||
public static Server memberToServer(Member member) {
|
||||
return Server.builder()
|
||||
.ip(member.getIp())
|
||||
.servePort(member.getPort())
|
||||
.alive(true)
|
||||
.lastRefTime(System.currentTimeMillis())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Member serverToMember(Server server) {
|
||||
return Member.builder()
|
||||
.ip(server.getIp())
|
||||
.port(server.getServePort())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static List<Member> toMembers(Collection<Server> servers) {
|
||||
return servers.stream().map(ServerUtils::serverToMember).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<Server> toServers(Collection<Member> members) {
|
||||
return members.stream().map(ServerUtils::memberToServer).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
@ -222,6 +222,15 @@ public class OperatorController {
|
||||
return "ok";
|
||||
}
|
||||
|
||||
/**
|
||||
* This interface will be removed in a future release
|
||||
*
|
||||
* // TODO This object will be deleted sometime after version 1.3.0
|
||||
*
|
||||
* @deprecated 1.3.0
|
||||
* @return {@link JsonNode}
|
||||
*/
|
||||
@Deprecated
|
||||
@RequestMapping(value = "/cluster/state", method = RequestMethod.GET)
|
||||
public JsonNode getClusterStates() {
|
||||
return JacksonUtils.transferToJsonNode(serviceManager.getMySelfClusterState());
|
||||
|
@ -30,8 +30,6 @@ public class GlobalExecutor {
|
||||
|
||||
public static final long TICK_PERIOD_MS = TimeUnit.MILLISECONDS.toMillis(500L);
|
||||
|
||||
private static final long NACOS_SERVER_LIST_REFRESH_INTERVAL = TimeUnit.SECONDS.toMillis(5);
|
||||
|
||||
private static final long PARTITION_DATA_TIMED_SYNC_INTERVAL = TimeUnit.SECONDS.toMillis(5);
|
||||
|
||||
private static final long SERVER_STATUS_UPDATE_PERIOD = TimeUnit.SECONDS.toMillis(5);
|
||||
@ -150,8 +148,8 @@ public class GlobalExecutor {
|
||||
executorService.scheduleAtFixedRate(runnable, 0, TICK_PERIOD_MS, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public static void registerServerListUpdater(Runnable runnable) {
|
||||
executorService.scheduleAtFixedRate(runnable, 0, NACOS_SERVER_LIST_REFRESH_INTERVAL, TimeUnit.MILLISECONDS);
|
||||
public static void registerServerInfoUpdater(Runnable runnable) {
|
||||
executorService.scheduleAtFixedRate(runnable, 0, 2, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public static void registerServerStatusReporter(Runnable runnable, long delay) {
|
||||
|
Loading…
Reference in New Issue
Block a user