Skip to content

Arrow: Fix direct memory leak in row lineage vectorized readers#17296

Open
Neuw84 wants to merge 1 commit into
apache:mainfrom
Neuw84:fix-lineage-reader-vector-leak
Open

Arrow: Fix direct memory leak in row lineage vectorized readers#17296
Neuw84 wants to merge 1 commit into
apache:mainfrom
Neuw84:fix-lineage-reader-vector-leak

Conversation

@Neuw84

@Neuw84 Neuw84 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

RowIdVectorReader and LastUpdatedSeqVectorReader allocated a fresh BigIntVector from the root allocator on every batch, ignored the reuse parameter, kept no reference to the returned vector and had no-op close() methods. Nothing downstream closes the holders' vectors either, so every batch of a vectorized read that projects _row_id or _last_updated_sequence_number leaked one direct-memory vector.

On long-running Spark row-level operations against format-version 3 tables this grows without bound until the executor is killed (the identical workload against a v2 table runs flat, as the lineage readers are never instantiated).

The readers now own their result vector like the base reader owns vec: they allocate it lazily, reuse it across batches while its capacity suffices and release it in close(), which also closes the delegate readers. New tests assert the root allocator returns to its baseline after close and fail against the previous implementation.

AI Disclosure

Model: Claude Fable
Platform/Tool: Kiro
Human Oversight: reviewed

Relates to #17241

RowIdVectorReader and LastUpdatedSeqVectorReader allocated a fresh
BigIntVector from the root allocator on every batch, ignored the reuse
parameter, kept no reference to the returned vector and had no-op
close() methods. Nothing downstream closes the holders' vectors either,
so every batch of a vectorized read that projects _row_id or
_last_updated_sequence_number leaked one direct-memory vector. On
long-running Spark row-level operations against format-version 3 tables
this grows without bound until the executor is killed (the identical
workload against a v2 table runs flat, as the lineage readers are never
instantiated).

The readers now own their result vector like the base reader owns vec:
they allocate it lazily, reuse it across batches while its capacity
suffices and release it in close(), which also closes the delegate
readers. New tests assert the root allocator returns to its baseline
after close and fail against the previous implementation.

@uros-b uros-b left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix looks correct and well tested, thank you @Neuw84!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants