Skip to content

Commit

Permalink
Merge pull request #2934 from alibaba/hotfix_naming_compatibility
Browse files Browse the repository at this point in the history
[#2933] fixed compatibility issues with older versions
  • Loading branch information
yanlinly authored Jun 2, 2020
2 parents a8c5a8d + 01bb02b commit dc9d136
Showing 27 changed files with 459 additions and 143 deletions.
Original file line number Diff line number Diff line change
@@ -65,6 +65,7 @@ public void completed(HttpResponse response) {
try {
final String body = EntityUtils.toString(response.getEntity());
RestResult<T> data = ResponseHandler.convert(body, type);
data.setCode(response.getStatusLine().getStatusCode());
callback.onReceive(data);
}
catch (Throwable e) {
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Original file line number Diff line number Diff line change
@@ -17,12 +17,14 @@
package com.alibaba.nacos.common.utils;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import com.alibaba.nacos.api.common.Constants;
import org.apache.commons.lang3.StringUtils;

/**
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
*/
@SuppressWarnings("all")
public final class ByteUtils {

public static final byte[] EMPTY = new byte[0];
@@ -31,7 +33,7 @@ public static byte[] toBytes(String s) {
if (s == null) {
return EMPTY;
}
return s.getBytes(Charset.forName(StandardCharsets.UTF_8.name()));
return s.getBytes(Charset.forName(Constants.ENCODE));
}

public static byte[] toBytes(Object s) {
@@ -45,7 +47,7 @@ public static String toString(byte[] bytes) {
if (bytes == null) {
return StringUtils.EMPTY;
}
return new String(bytes, Charset.forName(StandardCharsets.UTF_8.name()));
return new String(bytes, Charset.forName(Constants.ENCODE));
}

public static boolean isEmpty(byte[] data) {
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@
import java.util.Collection;
import java.util.Dictionary;
import java.util.Map;
import java.util.Objects;

/**
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
Original file line number Diff line number Diff line change
@@ -15,13 +15,12 @@
*/
package com.alibaba.nacos.common.utils;

import org.apache.commons.lang3.CharSequenceUtils;
import com.alibaba.nacos.api.common.Constants;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Locale;

@@ -41,7 +40,7 @@ public class StringUtils {
public static final String EMPTY = "";

public static String newString4UTF8(byte[] bytes) {
return new String(bytes, Charset.forName(StandardCharsets.UTF_8.name()));
return new String(bytes, Charset.forName(Constants.ENCODE));
}

public static boolean isBlank(String str) {
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@

import org.slf4j.Logger;

import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ public class VersionUtils {
/**
* 获取当前version
*/
public static final String VERSION_DEFAULT = "${project.version}";
public static final String VERSION_PLACEHOLDER = "${project.version}";


static {
@@ -39,7 +39,7 @@ public class VersionUtils {
Properties props = new Properties();
props.load(in);
String val = props.getProperty("version");
if (val != null && !VERSION_DEFAULT.equals(val)) {
if (val != null && !VERSION_PLACEHOLDER.equals(val)) {
VERSION = val;
}
} catch (Exception e) {
2 changes: 1 addition & 1 deletion console/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -132,7 +132,7 @@ nacos.istio.mcp.server.enabled=false

### MemberLookup
### Addressing pattern category, If set, the priority is highest
# nacos.core.member.lookup.type=[file,address-server,discovery]
# nacos.core.member.lookup.type=[file,address-server]
## Set the cluster list with a configuration file or command-line argument
# nacos.member.list=192.168.16.101:8847?raft_port=8807,192.168.16.101?raft_port=8808,192.168.16.101:8849?raft_port=8809
## for AddressServerMemberLookup
Original file line number Diff line number Diff line change
@@ -25,19 +25,25 @@ 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 VERSION = "version";

public static final String[] META_KEY_LIST = new String[]{
RAFT_PORT,
SITE_KEY,
AD_WEIGHT,
WEIGHT,
LAST_REFRESH_TIME,
VERSION,
};

}
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
package com.alibaba.nacos.core.cluster;

import com.alibaba.nacos.common.utils.ExceptionUtil;
import com.alibaba.nacos.common.utils.VersionUtils;
import com.alibaba.nacos.core.utils.ApplicationUtils;
import com.alibaba.nacos.core.utils.Loggers;
import java.util.concurrent.ThreadLocalRandom;
@@ -74,6 +75,7 @@ public static Member singleParse(String member) {
Map<String, Object> extendInfo = new HashMap<>(4);
// The Raft Port information needs to be set by default
extendInfo.put(MemberMetaDataConstants.RAFT_PORT, String.valueOf(calculateRaftPort(target)));
extendInfo.put(MemberMetaDataConstants.VERSION, VersionUtils.VERSION);
target.setExtendInfo(extendInfo);
return target;
}
@@ -134,9 +136,7 @@ public static void syncToFile(Collection<Member> members) {

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

Original file line number Diff line number Diff line change
@@ -27,19 +27,22 @@
import com.alibaba.nacos.common.model.RestResult;
import com.alibaba.nacos.common.utils.ConcurrentHashSet;
import com.alibaba.nacos.common.utils.ExceptionUtil;
import com.alibaba.nacos.common.utils.VersionUtils;
import com.alibaba.nacos.core.cluster.lookup.LookupFactory;
import com.alibaba.nacos.core.notify.Event;
import com.alibaba.nacos.core.notify.NotifyCenter;
import com.alibaba.nacos.core.notify.listener.Subscribe;
import com.alibaba.nacos.core.utils.ApplicationUtils;
import com.alibaba.nacos.core.utils.Commons;
import com.alibaba.nacos.core.utils.Constants;
import com.alibaba.nacos.core.utils.GenericType;
import com.alibaba.nacos.core.utils.GlobalExecutor;
import com.alibaba.nacos.core.utils.InetUtils;
import com.alibaba.nacos.core.utils.Loggers;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
@@ -123,14 +126,15 @@ public class ServerMemberManager
*/
private final MemberInfoReportTask infoReportTask = new MemberInfoReportTask();

public ServerMemberManager(ServletContext servletContext) {
public ServerMemberManager(ServletContext servletContext) throws Exception {
this.serverList = new ConcurrentSkipListMap();
ApplicationUtils.setContextPath(servletContext.getContextPath());
MemberUtils.setManager(this);

init();
}

@PostConstruct
public void init() throws NacosException {
protected void init() throws NacosException {
Loggers.CORE.info("Nacos-related cluster resource initialization");
this.port = ApplicationUtils.getProperty("server.port", Integer.class, 8848);
this.localAddress = InetUtils.getSelfIp() + ":" + port;
@@ -198,11 +202,7 @@ public boolean update(Member newMember) {
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;
@@ -238,6 +238,10 @@ public Member getSelf() {
return this.self;
}

public Member find(String address) {
return serverList.get(address);
}

public Collection<Member> allMembers() {
// We need to do a copy to avoid affecting the real data
HashSet<Member> set = new HashSet<>(serverList.values());
@@ -408,10 +412,15 @@ protected void executeBody() {
"/cluster/report");

try {
asyncHttpClient.post(url, Header.EMPTY, Query.EMPTY, getSelf(),
asyncHttpClient.post(url, Header.newInstance().addParam(Constants.NACOS_SERVER_HEADER,
VersionUtils.VERSION), Query.EMPTY, getSelf(),
reference.getType(), new Callback<String>() {
@Override
public void onReceive(RestResult<String> result) {
if (result.getCode() == HttpStatus.NOT_IMPLEMENTED.value() || result.getCode() == HttpStatus.NOT_FOUND.value()) {
Loggers.CLUSTER.warn("{} version is too low, it is recommended to upgrade the version : {}", target, VersionUtils.VERSION);
return;
}
if (result.ok()) {
MemberUtils.onSuccess(target);
}
Original file line number Diff line number Diff line change
@@ -204,7 +204,7 @@ public RestResult<String> execute(Map<String, String> args) {

private void injectProtocolMetaData(ProtocolMetaData metaData) {
Member member = memberManager.getSelf();
member.setExtendVal("raft_meta_data", metaData);
member.setExtendVal("raftMetaData", metaData);
memberManager.update(member);
}

Original file line number Diff line number Diff line change
@@ -67,11 +67,11 @@ public class NotifyCenter {
static {
// Internal ArrayBlockingQueue buffer size. For applications with high write throughput,
// this value needs to be increased appropriately. default value is 16384
String ringBufferSizeProperty = "com.alibaba.nacos.core.notify.ringBufferSize";
String ringBufferSizeProperty = "nacos.core.notify.ring-buffer-size";
RING_BUFFER_SIZE = Integer.getInteger(ringBufferSizeProperty, 16384);

// The size of the public publisher's message staging queue buffer
String shareBufferSizeProperty = "com.alibaba.nacos.core.notify.shareBufferSize";
String shareBufferSizeProperty = "nacos.core.notify.share-buffer-size";
SHATE_BUFFER_SIZE = Integer.getInteger(shareBufferSizeProperty, 1024);

ServiceLoader<EventPublisher> loader = ServiceLoader.load(EventPublisher.class);
2 changes: 0 additions & 2 deletions distribution/logs/start.out

This file was deleted.

Loading

0 comments on commit dc9d136

Please sign in to comment.