arrow: Fix memory leak in ColumnVector by caching decoded vector - #17738
Open
waterWang wants to merge 1 commit into
Open
arrow: Fix memory leak in ColumnVector by caching decoded vector#17738waterWang wants to merge 1 commit into
waterWang wants to merge 1 commit into
Conversation
Every call to getArrowVector() on a dictionary-encoded column allocated a new decoded FieldVector that was never released. Since ColumnarBatch.createVectorSchemaRootFromVectors() calls it for every column of every batch, a scan over dict-encoded data leaked one vector per batch per dict-encoded column. Fix: cache the decoded vector in a private field (lazy init), and release it in close(). Repeated calls to getArrowVector() within the same batch return the same cached vector. Closes apache#17722
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.
Every call to
ColumnVector.getArrowVector()on a dictionary-encoded column allocates a new decodedFieldVectorthat is never released. SinceColumnarBatch.createVectorSchemaRootFromVectors()calls it for every column of every batch, a scan over dict-encoded data leaks one vector per batch per dict-encoded column, and the memory survives a fully drained and fully closed scan.Root cause
ColumnVector.getArrowVector()routes dict-encoded columns throughDictEncodedArrowConverter.toArrowVector()which allocates and populates a new vector from the reader's allocator on each call.ColumnVector.close()only closes the accessor, never the decoded vector.Fix
Cache the decoded vector in a private field, materializing it once per batch instead of on every
getArrowVector()call, and release it inclose(). Repeated calls within the same batch return the same cached vector. This matches the documented contract ("the arrow vectors are owned by the reader").Closes #17722