Merge pull request #1042 from alibaba/hotfix_recognize_080_data

Hotfix recognize 080 data
This commit is contained in:
Fury Zhu 2019-04-10 21:07:59 +08:00 committed by GitHub
commit 20a6a3b422
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 10 deletions

View File

@ -22,6 +22,7 @@ import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.naming.consistency.ApplyAction;
import com.alibaba.nacos.naming.consistency.Datum;
import com.alibaba.nacos.naming.consistency.KeyBuilder;
import com.alibaba.nacos.naming.core.Instance;
import com.alibaba.nacos.naming.core.Instances;
import com.alibaba.nacos.naming.core.Service;
import com.alibaba.nacos.naming.misc.Loggers;
@ -37,6 +38,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
@ -157,8 +159,34 @@ public class RaftStore {
}
if (KeyBuilder.matchInstanceListKey(file.getName())) {
return JSON.parseObject(json, new TypeReference<Datum<Instances>>() {
Datum<Instances> instancesDatum;
try {
instancesDatum = JSON.parseObject(json, new TypeReference<Datum<Instances>>() {
});
} catch (Exception e) {
JSONObject jsonObject = JSON.parseObject(json);
instancesDatum = new Datum<>();
instancesDatum.timestamp.set(jsonObject.getLongValue("timestamp"));
String key = jsonObject.getString("key");
String serviceName = KeyBuilder.getServiceName(key);
key = key.substring(0, key.indexOf(serviceName)) +
Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER + serviceName;
instancesDatum.key = key;
instancesDatum.value = new Instances();
instancesDatum.value.setInstanceList(JSON.parseObject(jsonObject.getString("value"),
new TypeReference<List<Instance>>(){}));
if (!instancesDatum.value.getInstanceList().isEmpty()) {
for (Instance instance : instancesDatum.value.getInstanceList()) {
instance.setEphemeral(false);
}
}
}
return instancesDatum;
}
return JSON.parseObject(json, Datum.class);
@ -208,6 +236,21 @@ public class RaftStore {
fc.close();
}
}
// remove old format file:
if (StringUtils.isNoneBlank(namespaceId)) {
if (datum.key.contains(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER)) {
String oldFormatKey =
datum.key.replace(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER, StringUtils.EMPTY);
cacheFile = new File(cacheDir + File.separator + namespaceId + File.separator + encodeFileName(oldFormatKey));
if (cacheFile.exists() && !cacheFile.delete()) {
Loggers.RAFT.error("[RAFT-DELETE] failed to delete old format datum: {}, value: {}",
datum.key, datum.value);
throw new IllegalStateException("failed to delete old format datum: " + datum.key);
}
}
}
}
private File[] listCaches() throws Exception {

View File

@ -135,10 +135,10 @@ public class InstanceController {
ClientInfo clientInfo = new ClientInfo(agent);
if (clientInfo.type == ClientInfo.ClientType.JAVA &&
clientInfo.version.compareTo(VersionUtil.parseVersion("1.0.0")) < 0) {
serviceManager.registerInstance(namespaceId, serviceName, parseInstance(request));
} else {
clientInfo.version.compareTo(VersionUtil.parseVersion("1.0.0")) >= 0) {
serviceManager.updateInstance(namespaceId, serviceName, parseInstance(request));
} else {
serviceManager.registerInstance(namespaceId, serviceName, parseInstance(request));
}
return "ok";
}
@ -364,6 +364,7 @@ public class InstanceController {
public JSONObject doSrvIPXT(String namespaceId, String serviceName, String agent, String clusters, String clientIP, int udpPort,
String env, boolean isCheck, String app, String tid, boolean healthyOnly) throws Exception {
ClientInfo clientInfo = new ClientInfo(agent);
JSONObject result = new JSONObject();
Service service = serviceManager.getService(namespaceId, serviceName);
@ -407,8 +408,14 @@ public class InstanceController {
Loggers.DEBUG_LOG.debug("no instance to serve for service: " + serviceName);
}
result.put("hosts", new JSONArray());
if (clientInfo.type == ClientInfo.ClientType.JAVA &&
clientInfo.version.compareTo(VersionUtil.parseVersion("1.0.0")) >= 0) {
result.put("dom", serviceName);
} else {
result.put("dom", NamingUtils.getServiceName(serviceName));
}
result.put("hosts", new JSONArray());
result.put("name", serviceName);
result.put("cacheMillis", cacheMillis);
result.put("lastRefTime", System.currentTimeMillis());
@ -454,8 +461,6 @@ public class InstanceController {
JSONArray hosts = new JSONArray();
ClientInfo clientInfo = new ClientInfo(agent);
for (Map.Entry<Boolean, List<Instance>> entry : ipMap.entrySet()) {
List<Instance> ips = entry.getValue();

View File

@ -94,8 +94,8 @@
<maven.test.skip>false</maven.test.skip>
<maven.javadoc.skip>true</maven.javadoc.skip>
<!-- Compiler settings properties -->
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<!-- Exclude all generated code -->
<sonar.jacoco.itReportPath>${project.basedir}/../test/target/jacoco-it.exec</sonar.jacoco.itReportPath>