[common] Release the input stream when FileIndexPredicate fails to open it - #9462
Merged
Merged
Conversation
…en it FileIndexPredicate opens a stream and hands it straight to FileIndexFormat.createReader, which rejects a file whose magic or version does not match. The constructor then exits with the stream open and unreferenced, so a corrupted index file leaks a file handle per attempt. Close it on the way out, the same way BitmapIndexReader and BTreeIndexReader guard their own construction.
Contributor
|
+1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
FileIndexPredicateopens a stream and hands it straight to the reader:FileIndexFormat.Readervalidates the file header and rejects anything that is not an index file:When that fires the constructor never returns, so nothing holds a reference to the stream and nobody can close it. A corrupted or truncated index file leaks a file handle per attempt, and scans retry per file.
BitmapIndexReaderandBTreeIndexReaderalready guard the same sequence, so this makes the three agree.Tests
FileIndexPredicateCloseTest#testFailedConstructionReleasesTheStreamwraps the stream so closes are counted, feeds bytes that are not an index file, and asserts the construction fails withnot file index fileand the stream is still released.Reverting the change turns it red on the close counter (
Expecting AtomicInteger(0) to have value: 1).mvn test -pl paimon-common -Dtest='org.apache.paimon.fileindex.**'— 68 tests, all passing. spotless and checkstyle clean.