Skip to content

Commit

Permalink
[Bug] Fix mixed cluster support for OpenSearch 2+
Browse files Browse the repository at this point in the history
The version framework only added support for OpenSearch 1.x bwc with legacy
clusters. This commit adds support for v2.0 which will be the last version with
bwc support for legacy clusters (v7.10)

Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
  • Loading branch information
nknize committed Sep 1, 2021
1 parent f298a41 commit b98b491
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion server/src/main/java/org/opensearch/LegacyESVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public class LegacyESVersion extends Version {
final int minor = Integer.valueOf(fields[2]) * 10000;
final int revision = Integer.valueOf(fields[3]) * 100;
final int expectedId;
if (fields[1].equals("1")) {
if (major > 0 && major < 6000000) {
expectedId = 0x08000000 ^ (major + minor + revision + 99);
} else {
expectedId = (major + minor + revision + 99);
Expand Down
24 changes: 20 additions & 4 deletions server/src/main/java/org/opensearch/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ public boolean onOrBefore(Version version) {

// LegacyESVersion major 7 is equivalent to Version major 1
public int compareMajor(Version other) {
int m = major == 1 ? 7 : major;
int om = other.major == 1 ? 7 : other.major;
int m = major == 1 ? 7 : major == 2 ? 8 : major;
int om = other.major == 1 ? 7 : other.major == 2 ? 8 : other.major;
return Integer.compare(m, om);
}

Expand Down Expand Up @@ -293,6 +293,8 @@ protected Version computeMinCompatVersion() {
} else if (major == 6) {
// force the minimum compatibility for version 6 to 5.6 since we don't reference version 5 anymore
return Version.fromId(5060099);
} else if (major == 2) {
return LegacyESVersion.V_7_10_0;
} else if (major >= 7) {
// all major versions from 7 onwards are compatible with last minor series of the previous major
Version bwcVersion = null;
Expand Down Expand Up @@ -339,6 +341,8 @@ private Version computeMinIndexCompatVersion() {
bwcMajor = 2; // we jumped from 2 to 5
} else if (major == 7 || major == 1) {
return LegacyESVersion.V_6_0_0_beta1;
} else if (major == 2) {
return LegacyESVersion.V_7_0_0;
} else {
bwcMajor = major - 1;
}
Expand All @@ -354,8 +358,20 @@ public boolean isCompatible(Version version) {
&& version.onOrAfter(minimumCompatibilityVersion());

// OpenSearch version 1 is the functional equivalent of predecessor version 7
int a = major == 1 ? 7 : major;
int b = version.major == 1 ? 7 : version.major;
// OpenSearch version 2 is the functional equivalent of predecessor unreleased version "8"
// todo refactor this logic after removing deprecated features
int a = major;
if (major == 1) {
a = 7;
} else if (major == 2) {
a = 8;
}
int b = version.major;
if (version.major == 1) {
b = 7;
} else if (version.major == 2) {
b = 8;
}

assert compatible == false || Math.max(a, b) - Math.min(a, b) <= 1;
return compatible;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,8 @@ public static void ensureNodesCompatibility(Version joiningNodeVersion, Version
* version mode
**/
public static void ensureMajorVersionBarrier(Version joiningNodeVersion, Version minClusterNodeVersion) {
final byte jnMajor = joiningNodeVersion.major == 1 ? 7 : joiningNodeVersion.major;
final byte clusterMajor = minClusterNodeVersion.major == 1? 7: minClusterNodeVersion.major;
if (jnMajor < clusterMajor) {
if (joiningNodeVersion.compareMajor(minClusterNodeVersion) < 0) {
throw new IllegalStateException("node version [" + joiningNodeVersion + "] is not supported. " +
"All nodes in the cluster are of a higher major [" + clusterMajor + "].");
}
Expand Down

0 comments on commit b98b491

Please sign in to comment.