Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Fix multiple aspects of version resolution
Browse files Browse the repository at this point in the history
This change fixes resolution of the Lucene version for legacy versions since the Lucene 9 libraries no longer hold constants for Lucene 7 and below. The change also updates DECLARED_VERSIONS to derive from the Versions class rather than LegacyESVersions (thereby ignoring legacy versions). This in turn required a change to the minimumIndexCompatibleVersion logic for LegacyESVersion. Finally, the testMinimumIndexCompatibilityVersion unit test was updated to use accurate version identifiers.

All unit tests pass and the code compiles, but actual functionality is still broken because some backwards compatibility logic was removed in the current branch that is retained in 2.x

Signed-off-by: Kartik Ganesh <gkart@amazon.com>
  • Loading branch information
kartg committed Jan 11, 2023
1 parent f4bc00c commit 61097a9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
20 changes: 20 additions & 0 deletions server/src/main/java/org/opensearch/LegacyESVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Version> idToVersion;
protected static final ImmutableOpenMap<String, Version> stringToVersion;
Expand Down Expand Up @@ -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)
);
}
}
4 changes: 2 additions & 2 deletions server/src/main/java/org/opensearch/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Version> DECLARED_VERSIONS = Collections.unmodifiableList(getDeclaredVersions(LegacyESVersion.class));
protected static final List<Version> DECLARED_VERSIONS = Collections.unmodifiableList(getDeclaredVersions(Version.class));
}

// lazy initialized because we don't yet have the declared versions ready when instantiating the cached Version
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 3 additions & 4 deletions server/src/test/java/org/opensearch/VersionTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 61097a9

Please sign in to comment.