Skip to content

Commit c84c526

Browse files
committed
1)Push entire commit after previous reversion for clean diff 2)Handle ancient indices (with no supported codec) with graceful message
1 parent 150e82b commit c84c526

File tree

3 files changed

+62
-22
lines changed

3 files changed

+62
-22
lines changed

lucene/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ Other
131131
* GITHUB#14761: Use more Comparators for PriorityQueue implementations. (Simon Cooper)
132132
* GITHUB#14817: Refactor some complex uses of PriorityQueue to use Comparators. (Simon Cooper)
133133

134+
* GITHUB#14607: Index open performs version check on each segment, ignores indexCreatedVersionMajor (Rahul Goswami)
135+
134136
======================= Lucene 10.4.0 =======================
135137

136138
API Changes

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ public void testFailOpenOldIndex() throws IOException {
864864
assertTrue(
865865
ex.getMessage()
866866
.contains(
867-
"This Lucene version only supports indexes created with major version "
867+
"This Lucene version only supports indexes with major version "
868868
+ Version.LATEST.major
869869
+ " or later"));
870870
// now open with allowed min version

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

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -346,30 +346,12 @@ public static final SegmentInfos readCommit(
346346
input);
347347
}
348348

349-
if (indexCreatedVersion < minSupportedMajorVersion) {
350-
throw new IndexFormatTooOldException(
351-
input,
352-
"Index created with Lucene "
353-
+ indexCreatedVersion
354-
+ ".x is not supported by Lucene "
355-
+ Version.LATEST
356-
+ ". This Lucene version only supports indexes created with major version "
357-
+ minSupportedMajorVersion
358-
+ " or later (found: "
359-
+ indexCreatedVersion
360-
+ ", minimum: "
361-
+ minSupportedMajorVersion
362-
+ "). To resolve this issue: (1) Re-index your data using Lucene "
363-
+ Version.LATEST.major
364-
+ ".x, or (2) Use an older Lucene version that supports your index format.");
365-
}
366-
367349
SegmentInfos infos = new SegmentInfos(indexCreatedVersion);
368350
infos.id = id;
369351
infos.generation = generation;
370352
infos.lastGeneration = generation;
371353
infos.luceneVersion = luceneVersion;
372-
parseSegmentInfos(directory, input, infos, format);
354+
parseSegmentInfos(directory, input, infos, format, minSupportedMajorVersion);
373355
return infos;
374356

375357
} catch (Throwable t) {
@@ -385,7 +367,12 @@ public static final SegmentInfos readCommit(
385367
}
386368

387369
private static void parseSegmentInfos(
388-
Directory directory, DataInput input, SegmentInfos infos, int format) throws IOException {
370+
Directory directory,
371+
DataInput input,
372+
SegmentInfos infos,
373+
int format,
374+
int minSupportedMajorVersion)
375+
throws IOException {
389376
infos.version = CodecUtil.readBELong(input);
390377
// System.out.println("READ sis version=" + infos.version);
391378
infos.counter = input.readVLong();
@@ -402,11 +389,38 @@ private static void parseSegmentInfos(
402389
}
403390

404391
long totalDocs = 0;
392+
405393
for (int seg = 0; seg < numSegments; seg++) {
406394
String segName = input.readString();
407395
byte[] segmentID = new byte[StringHelper.ID_LENGTH];
408396
input.readBytes(segmentID, 0, segmentID.length);
409-
Codec codec = readCodec(input);
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+
}
410424
SegmentInfo info =
411425
codec.segmentInfoFormat().read(directory, segName, segmentID, IOContext.READONCE);
412426
info.setCodec(codec);
@@ -495,6 +509,30 @@ private static void parseSegmentInfos(
495509
+ infos.indexCreatedVersionMajor,
496510
input);
497511
}
512+
513+
int createdOrSegmentMinVersion =
514+
info.getMinVersion() == null
515+
? infos.indexCreatedVersionMajor
516+
: info.getMinVersion().major;
517+
518+
// version >=7 are expected to record minVersion
519+
if (info.getMinVersion() == null || info.getMinVersion().major < minSupportedMajorVersion) {
520+
throw new IndexFormatTooOldException(
521+
input,
522+
"Index has segments derived from Lucene version "
523+
+ createdOrSegmentMinVersion
524+
+ ".x and is not supported by Lucene "
525+
+ Version.LATEST
526+
+ ". This Lucene version only supports indexes with major version "
527+
+ minSupportedMajorVersion
528+
+ " or later (found: "
529+
+ createdOrSegmentMinVersion
530+
+ ", minimum supported: "
531+
+ minSupportedMajorVersion
532+
+ "). To resolve this issue re-index your data using Lucene "
533+
+ minSupportedMajorVersion
534+
+ ".x or later.");
535+
}
498536
}
499537

500538
infos.userData = input.readMapOfStrings();

0 commit comments

Comments
 (0)