Skip to content

Apache Lucene open-source search software

Change the access modifier for the "expert" readLatestCommit API to public. (#12229)

Kartik Ganesh3813f5ab7c78
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_index/TestBackwardsCompatibility.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_index/TestBackwardsCompatibility.java
index a2790d873c6..9eeebeefc62 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_index/TestBackwardsCompatibility.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_index/TestBackwardsCompatibility.java
@@ -2241,4 +2241,18 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
}
}
}
+
+ @Nightly
+ public void testReadNMinusTwoSegmentInfos() throws IOException {
+ for (String name : binarySupportedNames) {
+ Path oldIndexDir = createTempDir(name);
+ TestUtil.unzip(getDataInputStream("unsupported." + name + ".zip"), oldIndexDir);
+ try (BaseDirectoryWrapper dir = newFSDirectory(oldIndexDir)) {
+ expectThrows(
+ IndexFormatTooOldException.class,
+ () -> SegmentInfos.readLatestCommit(dir, Version.MIN_SUPPORTED_MAJOR));
+ SegmentInfos.readLatestCommit(dir, MIN_BINARY_SUPPORTED_MAJOR);
+ }
+ }
+ }
}
diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
index ecd064ac875..d2cb1abaa8a 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
@@ -517,8 +517,14 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
return readLatestCommit(directory, Version.MIN_SUPPORTED_MAJOR);
}
- static final SegmentInfos readLatestCommit(Directory directory, int minSupportedMajorVersion)
- throws IOException {
+ /**
+ * Find the latest commit ({@code segments_N file}) and load all {@link SegmentCommitInfo}s, as
+ * long as the commit's {@link SegmentInfos#getIndexCreatedVersionMajor()} is strictly greater
+ * than the provided minimum supported major version. If the commit's version is older, an {@link
+ * IndexFormatTooOldException} will be thrown.
+ */
+ public static final SegmentInfos readLatestCommit(
+ Directory directory, int minSupportedMajorVersion) throws IOException {
return new FindSegmentsFile<SegmentInfos>(directory) {
@Override
protected SegmentInfos doBody(String segmentFileName) throws IOException {