Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix protocol version compatibility on 2.6.x #2117

Merged
merged 2 commits into from
Jul 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions dubbo-common/src/main/java/com/alibaba/dubbo/common/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@
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, "");

/**
* 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 {
Expand All @@ -66,7 +66,13 @@ public static boolean isSupportResponseAttatchment(String 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) {
Expand All @@ -82,12 +88,31 @@ private static int parseInt(String 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;
Expand Down