mirror of https://github.com/apache/lucene.git
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:
parent
2d0dc6407a
commit
3813f5ab7c
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue