You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2018/07/23 12:50:58 UTC
[incubator-dubbo] branch master updated: Merge pull request #2118,
fix protocol version compatibility with lower versions.
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new 0b6e6f3 Merge pull request #2118, fix protocol version compatibility with lower versions.
0b6e6f3 is described below
commit 0b6e6f3a375d82aab1a1f17b034e666c63f61103
Author: Jerrick Zhu <di...@gmail.com>
AuthorDate: Mon Jul 23 20:50:53 2018 +0800
Merge pull request #2118, fix protocol version compatibility with lower versions.
---
.../main/java/org/apache/dubbo/common/Version.java | 37 ++++++++++++++++++----
1 file changed, 31 insertions(+), 6 deletions(-)
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java b/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java
index 5721859..c22242c 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java
@@ -34,8 +34,8 @@ import java.util.Set;
public final class Version {
private static final Logger logger = LoggerFactory.getLogger(Version.class);
- // Dubbo RPC protocol version
- public static final String DEFAULT_DUBBO_PROTOCOL_VERSION = "2.0.2";
+ // Dubbo RPC protocol version, for compatibility, it must not be between 2.0.10 ~ 2.6.2
+ public static final String DEFAULT_DUBBO_PROTOCOL_VERSION = "2.0.1";
// Dubbo implementation version, usually is jar version.
private static final String VERSION = getVersion(Version.class, "");
@@ -43,7 +43,7 @@ public final class Version {
* For protocol compatibility purpose.
* Because {@link #isSupportResponseAttatchment} is checked for every call, int compare expect to has higher performance than string.
*/
- private static final int LOWEST_VERSION_FOR_RESPONSE_ATTATCHMENT = 202; // 2.0.2
+ private static final int LOWEST_VERSION_FOR_RESPONSE_ATTATCHMENT = 20001; // 2.0.1
private static final Map<String, Integer> VERSION2INT = new HashMap<String, Integer>();
static {
@@ -66,7 +66,13 @@ public final class Version {
if (version == null || version.length() == 0) {
return false;
}
- return getIntVersion(version) >= LOWEST_VERSION_FOR_RESPONSE_ATTATCHMENT;
+ // for previous dubbo version(2.0.10/020010~2.6.2/020602), this version is the jar's version, so they need to be ignore
+ int iVersion = getIntVersion(version);
+ if (iVersion >= 20010 && iVersion <= 20602) {
+ return false;
+ }
+
+ return iVersion >= LOWEST_VERSION_FOR_RESPONSE_ATTATCHMENT;
}
public static int getIntVersion(String version) {
@@ -82,12 +88,31 @@ public final class Version {
int v = 0;
String[] vArr = version.split("\\.");
int len = vArr.length;
- for (int i = 1; i <= len; i++) {
- v += Integer.parseInt(vArr[len - i]) * Math.pow(10, i - 1);
+ for (int i = 0; i < len; i++) {
+ v += Integer.parseInt(getDigital(vArr[i])) * Math.pow(10, (len - i - 1) * 2);
}
return v;
}
+ private static String getDigital(String v) {
+ int index = 0;
+ for (int i = 0; i < v.length(); i++) {
+ char c = v.charAt(i);
+ if (Character.isDigit(c)) {
+ if (i == v.length() - 1) {
+ index = i + 1;
+ } else {
+ index = i;
+ }
+ continue;
+ } else {
+ index = i;
+ break;
+ }
+ }
+ return v.substring(0, index);
+ }
+
private static boolean hasResource(String path) {
try {
return Version.class.getClassLoader().getResource(path) != null;