Apache Lucene open-source search software
LUCENE-7837: Use indexCreatedVersionMajor to fail opening too old indices.
Adrien Grand43442a6354b9
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 5c7431e19d8..85b4957b69c 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -4,7 +4,14 @@ For more information on past and future Lucene versions, please see:http://s.apache.org/luceneversions======================= Lucene 8.0.0 =======================-(No Changes)++Changes in Runtime Behavior++* LUCENE-7837: Indices that were created before the previous major version+ will now fail to open even if they have been merged with the previous major+ version. (Adrien Grand)++======================= Lucene 7.1.0 =======================(No Changes)diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.javaindex 9f1450bcfb3..23ad9fb0789 100644--- a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java@@ -306,12 +306,17 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfoCodecUtil.checkIndexHeaderSuffix(input, Long.toString(generation, Character.MAX_RADIX));Version luceneVersion = Version.fromBits(input.readVInt(), input.readVInt(), input.readVInt());- if (luceneVersion.onOrAfter(Version.LUCENE_7_0_0) == false) {- // TODO: should we check indexCreatedVersion instead?- throw new IndexFormatTooOldException(input, "this index is too old (version: " + luceneVersion + ")");+ int indexCreatedVersion = input.readVInt();+ if (luceneVersion.major < indexCreatedVersion) {+ throw new CorruptIndexException("Creation version [" + indexCreatedVersion+ + ".x] can't be greater than the version that wrote the segment infos: [" + luceneVersion + "]" , input);}- int indexCreatedVersion = input.readVInt();+ if (indexCreatedVersion < Version.LATEST.major - 1) {+ throw new IndexFormatTooOldException(input, "This index was initially created with Lucene "+ + indexCreatedVersion + ".x while the current version is " + Version.LATEST+ + " and Lucene only supports reading the current and previous major versions.");+ }SegmentInfos infos = new SegmentInfos(indexCreatedVersion);infos.id = id;