[FLINK-40645][state/forst] Unregister closed streams from FileCacheEntry#openedStreams - #29169
Open
seungjoo-choi-bucketplace wants to merge 1 commit into
Conversation
…try#openedStreams FileCacheEntry#open registers every CachedDataInputStream in openedStreams, but entries were only removed by doRemoveFile(), i.e. when the file was evicted or deleted. While a file stayed cached, every open/close cycle of a stream on it (table cache reopen with a small files.open, stream pool overflow, failed reads) left a closed stream and the remote stream it wraps on the heap: 83,403 S3AInputStream instances (~650 MB) in 24 minutes were observed with files.open=64. Remove the stream from openedStreams as the first step of close(), so that a failing close cannot skip it. LinkedBlockingQueue#remove is safe against the concurrent iteration in doRemoveFile(). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Collaborator
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.
What is the purpose of the change
Fixes FLINK-40645:
FileCacheEntry#openregisters everyCachedDataInputStreamit creates inFileCacheEntry#openedStreams, but the only place that removes entries isFileCacheEntry#doRemoveFile(), i.e. when the file is evicted from or deleted in the cache. While a file stays cached, every open/close cycle of a stream on it leaves a closed stream object — together with the remote stream and its statistics objects it wraps — in the queue. Streams are opened and closed repeatedly when the RocksDB table cache reopens SST files (state.backend.forst.files.opensmall relative to the number of live files), when the per-file stream pool overflows, or when a read fails. In production (Flink 2.1.3, ForSt on S3A,files.open=64) this accumulated 83,403S3AInputStreaminstances (~650 MB) in 24 minutes and the TaskManagers died of heap exhaustion.Brief change log
CachedDataInputStream#close: remove the stream fromcacheEntry.openedStreamsas the first step, so that a failing close cannot skip the removal.LinkedBlockingQueue#removeis safe against the concurrent iteration indoRemoveFile().FileCacheEntryTest.Verifying this change
This change added tests and can be verified as follows:
FileCacheEntryTest#testClosedStreamIsUnregisteredFromEntry: two streams opened throughFileCacheEntry#openare registered; closing one removes exactly that one (idempotently), closing the other empties the queue. Fails on master (closed stream must not stay registered).files.open=-1) the number ofS3AInputStreaminstances stays proportional to the number of open files (468 instances for 67 files after 18 hours).Does this pull request potentially affect one of the following parts:
@Public(Evolving): noDocumentation
FLINK-40644 (#29168) fixes the other half of the same stream life cycle (the remote stream not being closed) and touches the same method; the two changes are independent and merge cleanly in either order. The analysis and the patch were prepared with AI assistance (Claude Code) and validated in production as described above.
🤖 Generated with Claude Code