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 <gkart@amazon.com>
This commit is contained in:
Kartik Ganesh 2023-04-18 11:38:35 -07:00 committed by GitHub
parent 2d0dc6407a
commit 3813f5ab7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -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);
}
}
}
}

View File

@ -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 {