Skip to content

[SPARK-52809][SQL] Don't hold reader and iterator references for all partitions in task completion listeners for metric update - #51503

Closed
viirya wants to merge 2 commits into
apache:masterfrom
viirya:fix_metric_callback
Closed

[SPARK-52809][SQL] Don't hold reader and iterator references for all partitions in task completion listeners for metric update#51503
viirya wants to merge 2 commits into
apache:masterfrom
viirya:fix_metric_callback

Conversation

@viirya

@viiryaviirya commented Jul 15, 2025

Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

This patch adds only one task completion listener for metric updating for DataSourceRDD, instead of adding separate one for each partition iterator.

Why are the changes needed?

For each partition iterator, currently we add one task completion listener used to update final metrics if the task is stopped early. In the listener, the reader and iterator are held. So if the partition is normally exhausted, the references cannot be released early. It is a problem especially if the references are heavy as reported by apache/iceberg#13297.

Since the purpose of the callback is to update the final metrics if the task is stopped early, it means that we only need to do it for the last partition iterator. So we don't need set up a listener for each partition iterator. Thus, we can set up just one listener for all iterator. Once we advance to next partition iterator, we can update the update target (reader and partition iterator).

Does this PR introduce any user-facing change?

No

How was this patch tested?

Existing tests.

Was this patch authored or co-authored using generative AI tooling?

No

@viirya
viiryaforce-pushed the fix_metric_callback branch from 402e28b to b03c749CompareJuly 15, 2025 20:14
@viiryaviirya changed the title [SPARK-XXXXX][SQL] Add only one task completion listener for metric update callback[SPARK-XXXXX][SQL] Don't hold reader and iterator references for all partitions in task completion listenersJul 15, 2025
@viiryaviirya changed the title [SPARK-XXXXX][SQL] Don't hold reader and iterator references for all partitions in task completion listeners[SPARK-XXXXX][SQL] Don't hold reader and iterator references for all partitions in task completion listeners for metric updateJul 15, 2025
@viiryaviirya changed the title [SPARK-XXXXX][SQL] Don't hold reader and iterator references for all partitions in task completion listeners for metric update[SPARK-52809][SQL] Don't hold reader and iterator references for all partitions in task completion listeners for metric updateJul 15, 2025

@dongjoon-hyundongjoon-hyun 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.

+1, LGTM. Thank you, @viirya .
(Pending CIs).

@dongjoon-hyun

Copy link
Copy Markdown
Member

cc @peter-toth

@viirya
viiryaforce-pushed the fix_metric_callback branch from b03c749 to f9645adCompareJuly 15, 2025 21:46

@mridulmmridulm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

new PartitionMetricCallback[ColumnarBatch](customMetrics)
} else {
new PartitionMetricCallback[InternalRow](customMetrics)
}

@mridulmmridulmJul 16, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: We dont really need the if/else here ... the type param gets ignored.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Removed. Thanks.

viirya added a commit that referenced this pull request Jul 16, 2025
…partitions in task completion listeners for metric update
### What changes were proposed in this pull request?
This patch adds only one task completion listener for metric updating for `DataSourceRDD`, instead of adding separate one for each partition iterator.
### Why are the changes needed?
For each partition iterator, currently we add one task completion listener used to update final metrics if the task is stopped early. In the listener, the reader and iterator are held. So if the partition is normally exhausted, the references cannot be released early. It is a problem especially if the references are heavy as reported by apache/iceberg#13297.
Since the purpose of the callback is to update the final metrics if the task is stopped early, it means that we only need to do it for the last partition iterator. So we don't need set up a listener for each partition iterator. Thus, we can set up just one listener for all iterator. Once we advance to next partition iterator, we can update the update target (reader and partition iterator).
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Existing tests.
### Was this patch authored or co-authored using generative AI tooling?
No
Closes#51503 from viirya/fix_metric_callback.
Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
(cherry picked from commit cea0051)
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
viirya added a commit that referenced this pull request Jul 16, 2025
…partitions in task completion listeners for metric update
This patch adds only one task completion listener for metric updating for `DataSourceRDD`, instead of adding separate one for each partition iterator.
For each partition iterator, currently we add one task completion listener used to update final metrics if the task is stopped early. In the listener, the reader and iterator are held. So if the partition is normally exhausted, the references cannot be released early. It is a problem especially if the references are heavy as reported by apache/iceberg#13297.
Since the purpose of the callback is to update the final metrics if the task is stopped early, it means that we only need to do it for the last partition iterator. So we don't need set up a listener for each partition iterator. Thus, we can set up just one listener for all iterator. Once we advance to next partition iterator, we can update the update target (reader and partition iterator).
No
Existing tests.
No
Closes#51503 from viirya/fix_metric_callback.
Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
(cherry picked from commit cea0051)
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
@viirya

Copy link
Copy Markdown
MemberAuthor

Merged to master/branch-4.0/branch-3.5.

Thank you @dongjoon-hyun@szehon-ho@mridulm

@viirya
viirya deleted the fix_metric_callback branch July 16, 2025 07:22
viirya added a commit that referenced this pull request Jul 18, 2025
…cing to next file in ParquetPartitionReaderFactory
### What changes were proposed in this pull request?
This patch adds only one task completion listener for closing iterators in `ParquetPartitionReaderFactory`, instead of adding separate one for each file iterator.
### Why are the changes needed?
For each file iterator, currently we add one task completion listener used to update closing the iterator when the task is finished. In the listener, the iterator reference is held. So if the file is normally exhausted, the reference cannot be released early. It is a problem especially if the reference are heavy as reported by apache/iceberg#13297.
Similar to #51503, we don't need set up a listener for each file iterator. Thus, we can set up just one listener for all iterator. Once we advance to next file, we can update the update target to new iterator.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Existing tests.
### Was this patch authored or co-authored using generative AI tooling?
No
Closes#51528 from viirya/fix_iter_callback.
Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
viirya added a commit that referenced this pull request Jul 18, 2025
…cing to next file in ParquetPartitionReaderFactory
### What changes were proposed in this pull request?
This patch adds only one task completion listener for closing iterators in `ParquetPartitionReaderFactory`, instead of adding separate one for each file iterator.
### Why are the changes needed?
For each file iterator, currently we add one task completion listener used to update closing the iterator when the task is finished. In the listener, the iterator reference is held. So if the file is normally exhausted, the reference cannot be released early. It is a problem especially if the reference are heavy as reported by apache/iceberg#13297.
Similar to #51503, we don't need set up a listener for each file iterator. Thus, we can set up just one listener for all iterator. Once we advance to next file, we can update the update target to new iterator.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Existing tests.
### Was this patch authored or co-authored using generative AI tooling?
No
Closes#51528 from viirya/fix_iter_callback.
Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
(cherry picked from commit 197c9d6)
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
viirya added a commit that referenced this pull request Jul 18, 2025
…cing to next file in ParquetPartitionReaderFactory
### What changes were proposed in this pull request?
This patch adds only one task completion listener for closing iterators in `ParquetPartitionReaderFactory`, instead of adding separate one for each file iterator.
### Why are the changes needed?
For each file iterator, currently we add one task completion listener used to update closing the iterator when the task is finished. In the listener, the iterator reference is held. So if the file is normally exhausted, the reference cannot be released early. It is a problem especially if the reference are heavy as reported by apache/iceberg#13297.
Similar to #51503, we don't need set up a listener for each file iterator. Thus, we can set up just one listener for all iterator. Once we advance to next file, we can update the update target to new iterator.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Existing tests.
### Was this patch authored or co-authored using generative AI tooling?
No
Closes#51528 from viirya/fix_iter_callback.
Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
(cherry picked from commit 197c9d6)
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
zifeif2 pushed a commit to zifeif2/spark that referenced this pull request Nov 14, 2025
…partitions in task completion listeners for metric update
### What changes were proposed in this pull request?
This patch adds only one task completion listener for metric updating for `DataSourceRDD`, instead of adding separate one for each partition iterator.
### Why are the changes needed?
For each partition iterator, currently we add one task completion listener used to update final metrics if the task is stopped early. In the listener, the reader and iterator are held. So if the partition is normally exhausted, the references cannot be released early. It is a problem especially if the references are heavy as reported by apache/iceberg#13297.
Since the purpose of the callback is to update the final metrics if the task is stopped early, it means that we only need to do it for the last partition iterator. So we don't need set up a listener for each partition iterator. Thus, we can set up just one listener for all iterator. Once we advance to next partition iterator, we can update the update target (reader and partition iterator).
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Existing tests.
### Was this patch authored or co-authored using generative AI tooling?
No
Closesapache#51503 from viirya/fix_metric_callback.
Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
(cherry picked from commit 007d593)
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
zifeif2 pushed a commit to zifeif2/spark that referenced this pull request Nov 14, 2025
…cing to next file in ParquetPartitionReaderFactory
### What changes were proposed in this pull request?
This patch adds only one task completion listener for closing iterators in `ParquetPartitionReaderFactory`, instead of adding separate one for each file iterator.
### Why are the changes needed?
For each file iterator, currently we add one task completion listener used to update closing the iterator when the task is finished. In the listener, the iterator reference is held. So if the file is normally exhausted, the reference cannot be released early. It is a problem especially if the reference are heavy as reported by apache/iceberg#13297.
Similar to apache#51503, we don't need set up a listener for each file iterator. Thus, we can set up just one listener for all iterator. Once we advance to next file, we can update the update target to new iterator.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Existing tests.
### Was this patch authored or co-authored using generative AI tooling?
No
Closesapache#51528 from viirya/fix_iter_callback.
Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
(cherry picked from commit dcdb482)
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
Asmoday pushed a commit to arenadata/spark that referenced this pull request Feb 20, 2026
…cing to next file in ParquetPartitionReaderFactory
### What changes were proposed in this pull request?
This patch adds only one task completion listener for closing iterators in `ParquetPartitionReaderFactory`, instead of adding separate one for each file iterator.
### Why are the changes needed?
For each file iterator, currently we add one task completion listener used to update closing the iterator when the task is finished. In the listener, the iterator reference is held. So if the file is normally exhausted, the reference cannot be released early. It is a problem especially if the reference are heavy as reported by apache/iceberg#13297.
Similar to apache#51503, we don't need set up a listener for each file iterator. Thus, we can set up just one listener for all iterator. Once we advance to next file, we can update the update target to new iterator.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Existing tests.
### Was this patch authored or co-authored using generative AI tooling?
No
Closesapache#51528 from viirya/fix_iter_callback.
Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
(cherry picked from commit 197c9d6)
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
Asmoday pushed a commit to arenadata/spark that referenced this pull request Feb 20, 2026
…partitions in task completion listeners for metric update
This patch adds only one task completion listener for metric updating for `DataSourceRDD`, instead of adding separate one for each partition iterator.
For each partition iterator, currently we add one task completion listener used to update final metrics if the task is stopped early. In the listener, the reader and iterator are held. So if the partition is normally exhausted, the references cannot be released early. It is a problem especially if the references are heavy as reported by apache/iceberg#13297.
Since the purpose of the callback is to update the final metrics if the task is stopped early, it means that we only need to do it for the last partition iterator. So we don't need set up a listener for each partition iterator. Thus, we can set up just one listener for all iterator. Once we advance to next partition iterator, we can update the update target (reader and partition iterator).
No
Existing tests.
No
Closesapache#51503 from viirya/fix_metric_callback.
Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
(cherry picked from commit cea0051)
Signed-off-by: Liang-Chi Hsieh <viirya@gmail.com>
Sign up for freeto 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.

4 participants

@viirya@dongjoon-hyun@mridulm@szehon-ho