Skip to content

Apache Lucene open-source search software

Index open performs version check on each segment, ignores indexCreatedVersionMajor (#14607)

Rahul Goswami3bf1011a4e2f
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index ea9db0d698b..ef9830e0f81 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -131,6 +131,7 @@ Other
* GITHUB#14761: Use more Comparators for PriorityQueue implementations. (Simon Cooper)
* GITHUB#14817: Refactor some complex uses of PriorityQueue to use Comparators. (Simon Cooper)
+* GITHUB#14607: Index open performs version check on each segment, ignores indexCreatedVersionMajor (Rahul Goswami)
======================= Lucene 10.4.0 =======================
API Changes
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_index/TestBasicBackwardsCompatibility.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_index/TestBasicBackwardsCompatibility.java
index 77dc6d2412c..15088e14fb6 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_index/TestBasicBackwardsCompatibility.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_index/TestBasicBackwardsCompatibility.java
@@ -864,7 +864,7 @@ public class TestBasicBackwardsCompatibility extends BackwardsCompatibilityTestB
assertTrue(
ex.getMessage()
.contains(
- "This Lucene version only supports indexes created with major version "
+ "This Lucene version only supports indexes with major version "
+ Version.LATEST.major
+ " or later"));
// now open with allowed min version
diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
index 204bd89b350..aae2833782b 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
@@ -346,30 +346,12 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
input);
}
- if (indexCreatedVersion < minSupportedMajorVersion) {
- throw new IndexFormatTooOldException(
- input,
- "Index created with Lucene "
- + indexCreatedVersion
- + ".x is not supported by Lucene "
- + Version.LATEST
- + ". This Lucene version only supports indexes created with major version "
- + minSupportedMajorVersion
- + " or later (found: "
- + indexCreatedVersion
- + ", minimum: "
- + minSupportedMajorVersion
- + "). To resolve this issue: (1) Re-index your data using Lucene "
- + Version.LATEST.major
- + ".x, or (2) Use an older Lucene version that supports your index format.");
- }
-
SegmentInfos infos = new SegmentInfos(indexCreatedVersion);
infos.id = id;
infos.generation = generation;
infos.lastGeneration = generation;
infos.luceneVersion = luceneVersion;
- parseSegmentInfos(directory, input, infos, format);
+ parseSegmentInfos(directory, input, infos, format, minSupportedMajorVersion);
return infos;
} catch (Throwable t) {
@@ -385,7 +367,12 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
}
private static void parseSegmentInfos(
- Directory directory, DataInput input, SegmentInfos infos, int format) throws IOException {
+ Directory directory,
+ DataInput input,
+ SegmentInfos infos,
+ int format,
+ int minSupportedMajorVersion)
+ throws IOException {
infos.version = CodecUtil.readBELong(input);
// System.out.println("READ sis version=" + infos.version);
infos.counter = input.readVLong();
@@ -402,6 +389,7 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
}
long totalDocs = 0;
+
for (int seg = 0; seg < numSegments; seg++) {
String segName = input.readString();
byte[] segmentID = new byte[StringHelper.ID_LENGTH];
@@ -495,6 +483,30 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
+ infos.indexCreatedVersionMajor,
input);
}
+
+ int createdOrSegmentMinVersion =
+ info.getMinVersion() == null
+ ? infos.indexCreatedVersionMajor
+ : info.getMinVersion().major;
+
+ // version >=7 are expected to record minVersion
+ if (info.getMinVersion() == null || info.getMinVersion().major < minSupportedMajorVersion) {
+ throw new IndexFormatTooOldException(
+ input,
+ "Index has segments derived from Lucene version "
+ + createdOrSegmentMinVersion
+ + ".x and is not supported by Lucene "
+ + Version.LATEST
+ + ". This Lucene version only supports indexes with major version "
+ + minSupportedMajorVersion
+ + " or later (found: "
+ + createdOrSegmentMinVersion
+ + ", minimum supported: "
+ + minSupportedMajorVersion
+ + "). To resolve this issue re-index your data using Lucene "
+ + minSupportedMajorVersion
+ + ".x or later.");
+ }
}
infos.userData = input.readMapOfStrings();