Skip to content

Commit dba0577

Browse files
committed
SegmentInfos header check requires 'segments' codec to be version 10 (Lucene v8.6.0) or older
1 parent c84c526 commit dba0577

File tree

2 files changed

+16
-29
lines changed

2 files changed

+16
-29
lines changed

lucene/backward-codecs/src/test/org/apache/lucene/backward_index/TestAncientIndicesCompatibility.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.apache.lucene.tests.util.LuceneTestCase;
4646
import org.apache.lucene.tests.util.TestUtil;
4747
import org.apache.lucene.util.IOUtils;
48+
import org.apache.lucene.util.Version;
4849

4950
public class TestAncientIndicesCompatibility extends LuceneTestCase {
5051
static final Set<String> UNSUPPORTED_INDEXES;
@@ -199,7 +200,7 @@ public void testUnsupportedOldIndexes() throws Exception {
199200
checker.setInfoStream(new PrintStream(bos, false, UTF_8));
200201
checker.setLevel(CheckIndex.Level.MIN_LEVEL_FOR_INTEGRITY_CHECKS);
201202
CheckIndex.Status indexStatus = checker.checkIndex();
202-
if (version.startsWith("8.") || version.startsWith("9.")) {
203+
if (getVersion(version).onOrAfter(Version.fromBits(8, 6, 0))) {
203204
assertTrue(indexStatus.clean);
204205
} else {
205206
assertFalse(indexStatus.clean);
@@ -217,6 +218,18 @@ public void testUnsupportedOldIndexes() throws Exception {
217218
}
218219
}
219220

221+
private Version getVersion(String version) {
222+
if (version.startsWith("5x")) {
223+
// couple of indices in unsupported_indices.txt start with "5x'
224+
return Version.fromBits(5, 0, 0);
225+
}
226+
String[] versionBitsStr = version.split("[.\\-]");
227+
return Version.fromBits(
228+
Integer.parseInt(versionBitsStr[0]),
229+
Integer.parseInt(versionBitsStr[1]),
230+
Integer.parseInt(versionBitsStr[2]));
231+
}
232+
220233
// #12895: test on a carefully crafted 9.8.0 index (from a small contiguous subset
221234
// of wikibigall unique terms) that shows the read-time exception of
222235
// IntersectTermsEnum (used by WildcardQuery)

lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public static final SegmentInfos readCommit(
328328
throw new IndexFormatTooOldException(
329329
input, magic, CodecUtil.CODEC_MAGIC, CodecUtil.CODEC_MAGIC);
330330
}
331-
format = CodecUtil.checkHeaderNoMagic(input, "segments", VERSION_74, VERSION_CURRENT);
331+
format = CodecUtil.checkHeaderNoMagic(input, "segments", VERSION_86, VERSION_CURRENT);
332332
byte[] id = new byte[StringHelper.ID_LENGTH];
333333
input.readBytes(id, 0, id.length);
334334
CodecUtil.checkIndexHeaderSuffix(input, Long.toString(generation, Character.MAX_RADIX));
@@ -394,33 +394,7 @@ private static void parseSegmentInfos(
394394
String segName = input.readString();
395395
byte[] segmentID = new byte[StringHelper.ID_LENGTH];
396396
input.readBytes(segmentID, 0, segmentID.length);
397-
Codec codec = null;
398-
try {
399-
codec = readCodec(input);
400-
} catch (IllegalArgumentException e) {
401-
if (e.getMessage() != null && e.getMessage().contains("Could not load codec")) {
402-
// maybe we tried loading an old default codec which isn't present in backward-codecs
403-
// anymore.
404-
// aka index is too old
405-
throw new IndexFormatTooOldException(
406-
input,
407-
"Index has segments derived from Lucene version "
408-
+ infos.indexCreatedVersionMajor
409-
+ ".x and is not supported by Lucene "
410-
+ Version.LATEST
411-
+ ". This Lucene version only supports indexes with major version "
412-
+ minSupportedMajorVersion
413-
+ " or later (found: "
414-
+ infos.indexCreatedVersionMajor
415-
+ ", minimum supported: "
416-
+ minSupportedMajorVersion
417-
+ "). To resolve this issue re-index your data using Lucene "
418-
+ minSupportedMajorVersion
419-
+ ".x or later.");
420-
} else {
421-
throw e;
422-
}
423-
}
397+
Codec codec = readCodec(input);
424398
SegmentInfo info =
425399
codec.segmentInfoFormat().read(directory, segName, segmentID, IOContext.READONCE);
426400
info.setCodec(codec);

0 commit comments

Comments
 (0)