|
70 | 70 | import org.elasticsearch.common.util.iterable.Iterables; |
71 | 71 | import org.elasticsearch.core.Nullable; |
72 | 72 | import org.elasticsearch.core.SuppressForbidden; |
73 | | -import org.elasticsearch.index.IndexVersion; |
74 | 73 | import org.elasticsearch.index.IndexVersions; |
75 | 74 | import org.elasticsearch.index.analysis.AnalyzerScope; |
76 | 75 | import org.elasticsearch.index.analysis.NamedAnalyzer; |
|
89 | 88 | import java.util.Map; |
90 | 89 | import java.util.Objects; |
91 | 90 |
|
92 | | -import static org.apache.lucene.util.Version.LUCENE_10_0_0; |
93 | | - |
94 | 91 | public class Lucene { |
| 92 | + |
| 93 | + // Support for reading N-2 |
| 94 | + public static final int MIN_SUPPORTED_MAJOR = Version.LATEST.major - 2; |
| 95 | + |
95 | 96 | public static final String LATEST_CODEC = "Lucene101"; |
96 | 97 |
|
97 | 98 | public static final String SOFT_DELETES_FIELD = "__soft_deletes"; |
@@ -156,25 +157,7 @@ public static SegmentInfos readSegmentInfos(IndexCommit commit) throws IOExcepti |
156 | 157 | * Reads the segments infos from the given segments file name, failing if it fails to load |
157 | 158 | */ |
158 | 159 | private static SegmentInfos readSegmentInfos(String segmentsFileName, Directory directory) throws IOException { |
159 | | - // TODO Use readCommit(Directory directory, String segmentFileName, int minSupportedMajorVersion) once Lucene 10.1 is available |
160 | | - // and remove the try-catch block for IndexFormatTooOldException |
161 | | - assert IndexVersion.current().luceneVersion().equals(LUCENE_10_0_0) : "remove the try-catch block below"; |
162 | | - try { |
163 | | - return SegmentInfos.readCommit(directory, segmentsFileName); |
164 | | - } catch (IndexFormatTooOldException e) { |
165 | | - try { |
166 | | - // Temporary workaround until Lucene 10.1 is available: try to leverage min. read-only compatibility to read the last commit |
167 | | - // and then check if this is the commit we want. This should always work for the case we are interested in (archive and |
168 | | - // searchable snapshots indices in N-2 version) as no newer commit should be ever written. |
169 | | - var segmentInfos = readSegmentInfos(directory); |
170 | | - if (segmentsFileName.equals(segmentInfos.getSegmentsFileName())) { |
171 | | - return segmentInfos; |
172 | | - } |
173 | | - } catch (Exception suppressed) { |
174 | | - e.addSuppressed(suppressed); |
175 | | - } |
176 | | - throw e; |
177 | | - } |
| 160 | + return SegmentInfos.readCommit(directory, segmentsFileName, MIN_SUPPORTED_MAJOR); |
178 | 161 | } |
179 | 162 |
|
180 | 163 | /** |
|
0 commit comments