-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Revise strategy for opening an index for reading #14607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 11 commits
2ae700d
60461d2
128b13a
01820b6
8975898
ff5bde9
10303e8
43b0efc
f9b7ec2
8015f2e
96c278c
841e7bb
ba9ab0c
b789067
150e82b
c84c526
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -346,30 +346,12 @@ public static final SegmentInfos readCommit( | |
| 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 static final SegmentInfos readCommit( | |
| } | ||
|
|
||
| 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 @@ private static void parseSegmentInfos( | |
| } | ||
|
|
||
| long totalDocs = 0; | ||
|
|
||
| for (int seg = 0; seg < numSegments; seg++) { | ||
| String segName = input.readString(); | ||
| byte[] segmentID = new byte[StringHelper.ID_LENGTH]; | ||
|
|
@@ -410,6 +398,85 @@ private static void parseSegmentInfos( | |
| SegmentInfo info = | ||
| codec.segmentInfoFormat().read(directory, segName, segmentID, IOContext.READONCE); | ||
| info.setCodec(codec); | ||
| Version segMinVersion = info.getMinVersion(); | ||
| Version segmentVersion = info.getVersion(); | ||
|
|
||
| if (!segmentVersion.onOrAfter(infos.minSegmentLuceneVersion)) { | ||
|
||
| throw new CorruptIndexException( | ||
| "segments file recorded minSegmentLuceneVersion=" | ||
| + infos.minSegmentLuceneVersion | ||
| + " but segment=" | ||
| + info | ||
| + " has older version=" | ||
| + segmentVersion, | ||
| input); | ||
| } | ||
|
|
||
| if (infos.indexCreatedVersionMajor >= 7 | ||
| && segmentVersion.major < infos.indexCreatedVersionMajor) { | ||
| throw new CorruptIndexException( | ||
| "segments file recorded indexCreatedVersionMajor=" | ||
| + infos.indexCreatedVersionMajor | ||
| + " but segment=" | ||
| + info | ||
| + " has older version=" | ||
| + segmentVersion, | ||
| input); | ||
| } | ||
|
|
||
| if (infos.indexCreatedVersionMajor >= 7 && segMinVersion == null) { | ||
| throw new CorruptIndexException( | ||
| "segments infos must record minVersion with indexCreatedVersionMajor=" | ||
| + infos.indexCreatedVersionMajor, | ||
| input); | ||
| } | ||
|
|
||
| // if trying to open some random old index (< Lucene 7) | ||
| if (segMinVersion == null) { | ||
| if (infos.indexCreatedVersionMajor < minSupportedMajorVersion) { | ||
| throw new IndexFormatTooOldException( | ||
| input, | ||
| "Index created with Lucene " | ||
| + infos.indexCreatedVersionMajor | ||
| + ".x is not supported by Lucene " | ||
| + Version.LATEST | ||
| + ". This Lucene version only supports indexes created with major version " | ||
| + minSupportedMajorVersion | ||
| + " or later (found: " | ||
| + infos.indexCreatedVersionMajor | ||
| + ", 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."); | ||
| } else { | ||
| throw new CorruptIndexException( | ||
| "segments infos must record minVersion with indexCreatedVersionMajor=" | ||
| + infos.indexCreatedVersionMajor, | ||
| input); | ||
| } | ||
| } | ||
|
|
||
| if (segMinVersion.major < minSupportedMajorVersion) { | ||
| throw new IndexFormatTooOldException( | ||
| input, | ||
| "Index has segment traces from Lucene version " | ||
|
||
| + segMinVersion.major | ||
| + ".x and is not supported by Lucene " | ||
| + Version.LATEST | ||
| + ". This Lucene version only supports indexes with major version " | ||
| + minSupportedMajorVersion | ||
| + " or later (found: " | ||
| + segMinVersion.major | ||
| + ", minimum supported: " | ||
| + minSupportedMajorVersion | ||
| + "). To resolve this issue: (1) Re-index your data using Lucene " | ||
| + minSupportedMajorVersion | ||
| + ".x or later (preferably " | ||
|
||
| + Version.LATEST.major | ||
| + ".x), or (2) Use an older Lucene version that supports your index format."); | ||
| } | ||
|
|
||
| totalDocs += info.maxDoc(); | ||
| long delGen = CodecUtil.readBELong(input); | ||
| int delCount = CodecUtil.readBEInt(input); | ||
|
|
@@ -463,38 +530,6 @@ private static void parseSegmentInfos( | |
| } | ||
| siPerCommit.setDocValuesUpdatesFiles(dvUpdateFiles); | ||
| infos.add(siPerCommit); | ||
|
|
||
| Version segmentVersion = info.getVersion(); | ||
|
|
||
| if (segmentVersion.onOrAfter(infos.minSegmentLuceneVersion) == false) { | ||
| throw new CorruptIndexException( | ||
| "segments file recorded minSegmentLuceneVersion=" | ||
| + infos.minSegmentLuceneVersion | ||
| + " but segment=" | ||
| + info | ||
| + " has older version=" | ||
| + segmentVersion, | ||
| input); | ||
| } | ||
|
|
||
| if (infos.indexCreatedVersionMajor >= 7 | ||
| && segmentVersion.major < infos.indexCreatedVersionMajor) { | ||
| throw new CorruptIndexException( | ||
| "segments file recorded indexCreatedVersionMajor=" | ||
| + infos.indexCreatedVersionMajor | ||
| + " but segment=" | ||
| + info | ||
| + " has older version=" | ||
| + segmentVersion, | ||
| input); | ||
| } | ||
|
|
||
| if (infos.indexCreatedVersionMajor >= 7 && info.getMinVersion() == null) { | ||
| throw new CorruptIndexException( | ||
| "segments infos must record minVersion with indexCreatedVersionMajor=" | ||
| + infos.indexCreatedVersionMajor, | ||
| input); | ||
| } | ||
| } | ||
|
|
||
| infos.userData = input.readMapOfStrings(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it a functional change to move this version checking early in the function? It makes reviewing harder since the diffs look bigger and one has to carefully read and scroll around to compare by eyeball, so if it's not needed, let's leave it where it was.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that was exactly the intention- to move the check early in the function to fail fast. Agree it makes the reviewing trickier. Will incorporate the suggestion.