You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2023/04/18 18:46:53 UTC
[lucene] branch branch_9x updated: Change the access modifier for the "expert" readLatestCommit API to public. (#12229)
This is an automated email from the ASF dual-hosted git repository.
mikemccand pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new 1b349317f68 Change the access modifier for the "expert" readLatestCommit API to public. (#12229)
1b349317f68 is described below
commit 1b349317f687de68e861fd86473603ecda87fac3
Author: Kartik Ganesh <gk...@amazon.com>
AuthorDate: Tue Apr 18 11:38:35 2023 -0700
Change the access modifier for the "expert" readLatestCommit API to public. (#12229)
This change also includes a unit test for this functionality.
Signed-off-by: Kartik Ganesh <gk...@amazon.com>
---
.../lucene/backward_index/TestBackwardsCompatibility.java | 14 ++++++++++++++
.../src/java/org/apache/lucene/index/SegmentInfos.java | 10 ++++++++--
2 files changed, 22 insertions(+), 2 deletions(-)
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 2ea1c670d2a..542b3a5e2e6 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
@@ -2269,4 +2269,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 b98c061b811..fbded16cf9f 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
@@ -528,8 +528,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 {