Skip to content

Commit 8d72916

Browse files
committed
Update readCommit for N-2
1 parent 9202d49 commit 8d72916

File tree

2 files changed

+5
-23
lines changed

2 files changed

+5
-23
lines changed

server/src/main/java/org/elasticsearch/common/lucene/Lucene.java

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
import org.elasticsearch.common.util.iterable.Iterables;
7171
import org.elasticsearch.core.Nullable;
7272
import org.elasticsearch.core.SuppressForbidden;
73-
import org.elasticsearch.index.IndexVersion;
7473
import org.elasticsearch.index.IndexVersions;
7574
import org.elasticsearch.index.analysis.AnalyzerScope;
7675
import org.elasticsearch.index.analysis.NamedAnalyzer;
@@ -89,9 +88,11 @@
8988
import java.util.Map;
9089
import java.util.Objects;
9190

92-
import static org.apache.lucene.util.Version.LUCENE_10_0_0;
93-
9491
public class Lucene {
92+
93+
// Support for reading N-2
94+
public static final int MIN_SUPPORTED_MAJOR = Version.LATEST.major - 2;
95+
9596
public static final String LATEST_CODEC = "Lucene101";
9697

9798
public static final String SOFT_DELETES_FIELD = "__soft_deletes";
@@ -156,25 +157,7 @@ public static SegmentInfos readSegmentInfos(IndexCommit commit) throws IOExcepti
156157
* Reads the segments infos from the given segments file name, failing if it fails to load
157158
*/
158159
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);
178161
}
179162

180163
/**

server/src/main/java/org/elasticsearch/index/IndexVersions.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ private static Version parseUnchecked(String version) {
138138
public static final IndexVersion TIME_BASED_K_ORDERED_DOC_ID = def(9_002_00_0, Version.LUCENE_10_0_0);
139139
public static final IndexVersion DEPRECATE_SOURCE_MODE_MAPPER = def(9_003_00_0, Version.LUCENE_10_0_0);
140140
public static final IndexVersion USE_SYNTHETIC_SOURCE_FOR_RECOVERY = def(9_004_00_0, Version.LUCENE_10_0_0);
141-
142141
public static final IndexVersion UPGRADE_TO_LUCENE_10_1_0 = def(9_005_00_0, Version.LUCENE_10_1_0);
143142

144143
/*

0 commit comments

Comments
 (0)