Browse Source

Fix incorrect assumption in Lucene versions

This commit addresses an incorrect assumption in Lucene versions which
is that we never advance the Lucene version in a patch release. That is
not true, since we will upgrade to patch releases of Lucene in patch
release of Elasticsearch. This commit then fixes a related test, for
which the assertion is only true for unknown versions.
Jason Tedor 5 years ago
parent
commit
da54ab6323

+ 1 - 3
server/src/main/java/org/elasticsearch/Version.java

@@ -137,9 +137,7 @@ public class Version implements Comparable<Version>, ToXContentFragment {
             default:
                 // We need at least the major of the Lucene version to be correct.
                 // Our best guess is to use the same Lucene version as the previous
-                // version in the list, assuming that it didn't change. This is at
-                // least correct for patch versions of known minors since we never
-                // update the Lucene dependency for patch versions.
+                // version in the list, assuming that it didn't change.
                 List<Version> versions = DeclaredVersionsHolder.DECLARED_VERSIONS;
                 Version tmp = new Version(id, org.apache.lucene.util.Version.LATEST);
                 int index = Collections.binarySearch(versions, tmp);

+ 8 - 1
server/src/test/java/org/elasticsearch/common/lucene/uid/VersionsTests.java

@@ -203,7 +203,14 @@ public class VersionsTests extends ESTestCase {
     public void testLuceneVersionOnUnknownVersions() {
         // between two known versions, should use the lucene version of the previous version
         Version version = VersionUtils.getPreviousVersion(Version.CURRENT);
-        assertEquals(Version.fromId(version.id + 100).luceneVersion, version.luceneVersion);
+        final Version nextVersion = Version.fromId(version.id + 100);
+        if (Version.getDeclaredVersions(Version.class).contains(nextVersion) == false) {
+            // the version is not known, we make an assumption the Lucene version stays the same
+            assertEquals(nextVersion.luceneVersion, version.luceneVersion);
+        } else {
+            // the version is known, the most we can assert is that the Lucene version is not earlier
+            assertTrue(nextVersion.luceneVersion.onOrAfter(version.luceneVersion));
+        }
 
         // too old version, major should be the oldest supported lucene version minus 1
         version = Version.fromString("5.2.1");