pkuzmickas opened a new pull request, #41909:
URL: https://github.com/apache/beam/pull/41909
Addresses #40607. Follow-up to #40611.
`SortedBatchCombineOperator.BufferingCombiner` collects all values for the
current `GroupByKey` key into an unbounded on-heap `ArrayList` before emitting
the key. For pipelines with large keys (for example sorted-bucket writes
grouping millions of records per bucket key), holding every deserialized value
on heap across concurrent task slots causes heavy GC pressure or
`OutOfMemoryError: Java heap space`, especially when a chained downstream
operator also buffers per-key state on heap.
## What changes
- Update `SortedBatchCombineOperator.BufferingCombiner` to accept the value
`Coder`:
- Small keys (`< 256` elements) stay in a plain `ArrayList` with no
serialization overhead.
- Larger keys compact into a bounded in-memory encoded byte buffer (`16
MiB` default) returned as a re-iterable `EncodedIterable`.
- Keys whose encoded bytes reach the threshold spill to a local temporary
file under Flink's `IOManager` spilling directory (falling back to the default
temp directory when unavailable) and return a re-iterable `SpilledIterable`
backed by buffered file reads.
- Add `open(@Nullable File spillDirectory)` and `close()` lifecycle hooks on
`KeyCombiner` and invoke them from `SortedBatchCombineOperator#open` and
`#close`. Track live spill files with a `ReferenceQueue` so consumed keys are
deleted before task completion, and deterministically close any open streams
and delete remaining spill files on `close()`.
- Wire `accumulatorCoder` into `BufferingCombiner` in
`FlinkStreamingAggregationsTranslators#batchGroupByKey`.
- Add tests in `SortedBatchCombineOperatorTest` covering in-memory,
compact-encoded, and disk-spilled keys, re-iteration, partial iteration, and
spill cleanup on normal close and abort.
🤖 Generated with [Xirp Agent](https://spotify.ghe.com/xirp-org/agent)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]