Close all files when hitting an I/O exception with vectors. (#12807)

This was found by `testRandomExceptions()`: if an exception occurs when opening
the meta file, then the `rawVectorsReader` that is passed to the constructor
never gets closed.
This commit is contained in:
Adrien Grand 2023-11-15 08:42:08 +01:00 committed by GitHub
parent a13a4224d8
commit 5afc17d4b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 23 deletions

View File

@ -92,18 +92,8 @@ public final class Lucene99HnswVectorsReader extends KnnVectorsReader
} catch (Throwable exception) { } catch (Throwable exception) {
priorE = exception; priorE = exception;
} finally { } finally {
try { CodecUtil.checkFooter(meta, priorE);
CodecUtil.checkFooter(meta, priorE);
success = true;
} finally {
if (success == false) {
IOUtils.close(flatVectorsReader);
}
}
} }
}
success = false;
try {
vectorIndex = vectorIndex =
openDataInput( openDataInput(
state, state,

View File

@ -58,6 +58,7 @@ public final class Lucene99ScalarQuantizedVectorsReader extends FlatVectorsReade
Lucene99ScalarQuantizedVectorsReader(SegmentReadState state, FlatVectorsReader rawVectorsReader) Lucene99ScalarQuantizedVectorsReader(SegmentReadState state, FlatVectorsReader rawVectorsReader)
throws IOException { throws IOException {
this.rawVectorsReader = rawVectorsReader;
int versionMeta = -1; int versionMeta = -1;
String metaFileName = String metaFileName =
IndexFileNames.segmentFileName( IndexFileNames.segmentFileName(
@ -80,19 +81,8 @@ public final class Lucene99ScalarQuantizedVectorsReader extends FlatVectorsReade
} catch (Throwable exception) { } catch (Throwable exception) {
priorE = exception; priorE = exception;
} finally { } finally {
try { CodecUtil.checkFooter(meta, priorE);
CodecUtil.checkFooter(meta, priorE);
success = true;
} finally {
if (success == false) {
IOUtils.close(rawVectorsReader);
}
}
} }
}
success = false;
this.rawVectorsReader = rawVectorsReader;
try {
quantizedVectorData = quantizedVectorData =
openDataInput( openDataInput(
state, state,