diff --git a/server/src/main/java/org/opensearch/LegacyESVersion.java b/server/src/main/java/org/opensearch/LegacyESVersion.java index 8cd60084ad710..38e17d6bcc353 100644 --- a/server/src/main/java/org/opensearch/LegacyESVersion.java +++ b/server/src/main/java/org/opensearch/LegacyESVersion.java @@ -48,6 +48,8 @@ */ public class LegacyESVersion extends Version { + public static final LegacyESVersion V_6_0_0 = new LegacyESVersion(6000099, org.apache.lucene.util.Version.fromBits(7, 0, 0)); + // todo move back to Version.java if retiring legacy version support protected static final ImmutableOpenIntMap idToVersion; protected static final ImmutableOpenMap stringToVersion; @@ -237,4 +239,22 @@ public String toString() { } return sb.toString(); } + + @Override + protected Version computeMinIndexCompatVersion() { + final int prevLuceneVersionMajor = this.luceneVersion.major - 1; + final int bwcMajor; + if (major == 5) { + bwcMajor = 2; // we jumped from 2 to 5 + } else if (major == 7) { + return LegacyESVersion.fromId(6000026); + } else { + bwcMajor = major - 1; + } + final int bwcMinor = 0; + return new LegacyESVersion( + bwcMajor * 1000000 + bwcMinor * 10000 + 99, + org.apache.lucene.util.Version.fromBits(prevLuceneVersionMajor, 0, 0) + ); + } } diff --git a/server/src/main/java/org/opensearch/Version.java b/server/src/main/java/org/opensearch/Version.java index 8dd6776b2d5f4..14287b003e52e 100644 --- a/server/src/main/java/org/opensearch/Version.java +++ b/server/src/main/java/org/opensearch/Version.java @@ -317,7 +317,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws */ static class DeclaredVersionsHolder { // use LegacyESVersion.class since it inherits Version fields - protected static final List DECLARED_VERSIONS = Collections.unmodifiableList(getDeclaredVersions(LegacyESVersion.class)); + protected static final List DECLARED_VERSIONS = Collections.unmodifiableList(getDeclaredVersions(Version.class)); } // lazy initialized because we don't yet have the declared versions ready when instantiating the cached Version @@ -394,7 +394,7 @@ public Version minimumIndexCompatibilityVersion() { return res; } - private Version computeMinIndexCompatVersion() { + protected Version computeMinIndexCompatVersion() { final int bwcMajor; if (major == 5) { bwcMajor = 2; // we jumped from 2 to 5 diff --git a/server/src/main/java/org/opensearch/index/store/remote/directory/RemoteSnapshotDirectory.java b/server/src/main/java/org/opensearch/index/store/remote/directory/RemoteSnapshotDirectory.java index e723c831b213d..840dc37569081 100644 --- a/server/src/main/java/org/opensearch/index/store/remote/directory/RemoteSnapshotDirectory.java +++ b/server/src/main/java/org/opensearch/index/store/remote/directory/RemoteSnapshotDirectory.java @@ -38,7 +38,7 @@ */ public final class RemoteSnapshotDirectory extends Directory { - public static final Version SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY_MINIMUM_VERSION = LegacyESVersion.fromId(6000099); + public static final Version SEARCHABLE_SNAPSHOT_EXTENDED_COMPATIBILITY_MINIMUM_VERSION = LegacyESVersion.V_6_0_0; private static final String VIRTUAL_FILE_PREFIX = BlobStoreRepository.VIRTUAL_DATA_BLOB_PREFIX; diff --git a/server/src/test/java/org/opensearch/VersionTests.java b/server/src/test/java/org/opensearch/VersionTests.java index bb5ab4228e264..cb6874b00c161 100644 --- a/server/src/test/java/org/opensearch/VersionTests.java +++ b/server/src/test/java/org/opensearch/VersionTests.java @@ -119,10 +119,9 @@ public void testMax() { } public void testMinimumIndexCompatibilityVersion() { - // note: all Legacy compatibility support will be removed in OpenSearch 3.0 - assertEquals(LegacyESVersion.fromId(7000099), Version.fromId(2000099).minimumIndexCompatibilityVersion()); - assertEquals(LegacyESVersion.fromId(7000099), Version.fromId(2010000).minimumIndexCompatibilityVersion()); - assertEquals(LegacyESVersion.fromId(7000099), Version.fromId(2000001).minimumIndexCompatibilityVersion()); + assertEquals(LegacyESVersion.fromId(7000099), Version.fromId(2000099 ^ MASK).minimumIndexCompatibilityVersion()); + assertEquals(LegacyESVersion.fromId(7000099), Version.fromId(2010000 ^ MASK).minimumIndexCompatibilityVersion()); + assertEquals(LegacyESVersion.fromId(7000099), Version.fromId(2000001 ^ MASK).minimumIndexCompatibilityVersion()); } public void testVersionConstantPresent() { diff --git a/server/src/test/java/org/opensearch/common/lucene/LuceneTests.java b/server/src/test/java/org/opensearch/common/lucene/LuceneTests.java index 67ff269a5827c..966c47b2f42d9 100644 --- a/server/src/test/java/org/opensearch/common/lucene/LuceneTests.java +++ b/server/src/test/java/org/opensearch/common/lucene/LuceneTests.java @@ -334,7 +334,7 @@ public void testNumDocs() throws IOException { */ public void testReadSegmentInfosExtendedCompatibility() throws IOException { final String pathToTestIndex = "/indices/bwc/es-6.3.0/testIndex-es-6.3.0.zip"; - final Version minVersion = LegacyESVersion.fromId(6000099); + final Version minVersion = LegacyESVersion.V_6_0_0; Path tmp = createTempDir(); TestUtil.unzip(getClass().getResourceAsStream(pathToTestIndex), tmp); try (MockDirectoryWrapper dir = newMockFSDirectory(tmp)) {