From b98b4919da146bc9f425acea256e9ef756f5cc21 Mon Sep 17 00:00:00 2001 From: Nicholas Walter Knize Date: Tue, 31 Aug 2021 15:14:33 -0500 Subject: [PATCH] [Bug] Fix mixed cluster support for OpenSearch 2+ 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 --- .../java/org/opensearch/LegacyESVersion.java | 2 +- .../src/main/java/org/opensearch/Version.java | 24 +++++++++++++++---- .../coordination/JoinTaskExecutor.java | 3 +-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/server/src/main/java/org/opensearch/LegacyESVersion.java b/server/src/main/java/org/opensearch/LegacyESVersion.java index e535d209e595e..ab1b4400906da 100644 --- a/server/src/main/java/org/opensearch/LegacyESVersion.java +++ b/server/src/main/java/org/opensearch/LegacyESVersion.java @@ -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); diff --git a/server/src/main/java/org/opensearch/Version.java b/server/src/main/java/org/opensearch/Version.java index 142fabf5ad079..999c39cabbc45 100644 --- a/server/src/main/java/org/opensearch/Version.java +++ b/server/src/main/java/org/opensearch/Version.java @@ -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); } @@ -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; @@ -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; } @@ -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; diff --git a/server/src/main/java/org/opensearch/cluster/coordination/JoinTaskExecutor.java b/server/src/main/java/org/opensearch/cluster/coordination/JoinTaskExecutor.java index ac725e613e0bd..7cf8caf22bccf 100644 --- a/server/src/main/java/org/opensearch/cluster/coordination/JoinTaskExecutor.java +++ b/server/src/main/java/org/opensearch/cluster/coordination/JoinTaskExecutor.java @@ -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 + "]."); }