LUCENE-7837: Use indexCreatedVersionMajor to fail opening too old indices.

This commit is contained in:
Adrien Grand 2017-07-06 16:39:21 +02:00
parent 77ee4ddb99
commit 43442a6354
2 changed files with 17 additions and 5 deletions

View File

@ -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)

View File

@ -306,12 +306,17 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
CodecUtil.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;