lvyanquan opened a new pull request, #11406:
URL: https://github.com/apache/paimon/pull/11406
### Purpose
Fixes #11404.
Batch reads of postpone bucket tables with `postpone.merge-on-read = 'true'`
fail with a `NullPointerException` once the operator-side carrier sort buffer
spills to disk:
```
java.lang.NullPointerException
at
org.apache.paimon.data.serializer.BinaryRowSerializer.deserialize(BinaryRowSerializer.java:86)
at
org.apache.paimon.disk.ChannelReaderInputViewIterator.next(ChannelReaderInputViewIterator.java:50)
at
org.apache.paimon.sort.BinaryMergeIterator$HeadStream.noMoreHead(BinaryMergeIterator.java:93)
at
org.apache.paimon.sort.BinaryMergeIterator.next(BinaryMergeIterator.java:60)
...
at
org.apache.paimon.flink.source.PostponeMergeOperator$SortedCarriers.hasNext(PostponeMergeOperator.java:258)
at
org.apache.paimon.flink.source.PostponeMergeOperator.mergeBucket(PostponeMergeOperator.java:190)
at
org.apache.paimon.flink.source.PostponeMergeOperator.endInput(PostponeMergeOperator.java:147)
```
Root cause:
1. `PostponeMergeOperator#mergeBucket` probes `carriers.hasNext()` once more
after the bucket merge reader has drained the postpone records, so the last
bucket ends up polling the carrier iterator a second time after it already
returned `null`.
2. With spill, that iterator is a `BinaryMergeIterator`. When the last head
stream is exhausted, `next()` calls `heap.poll()` but leaves `currHead`
pointing at the evicted `HeadStream`, whose head is now `null`.
3. The next poll calls `currHead.noMoreHead()` again, i.e.
`iterator.next(null)`, and `BinaryRowSerializer#deserialize` starts with
`reuse.getSegments()` → NPE.
This violates the `MutableObjectIterator` contract ("The filled object or
null if the iterator is exhausted") and is data-size dependent: without spill
the in-memory iterator is returned and nothing happens, which is why existing
tests never caught it.
Changes:
- `BinaryMergeIterator#next()` resets `currHead` after polling the exhausted
stream. Behavior for non-exhausted streams is unchanged (the head is re-peeked
right after). Other consumers
(`AbstractBinaryExternalMerger#writeMergingOutput`) stop at the first `null`
and are unaffected.
- `PostponeMergeOperator.SortedCarriers#hasNext()` records that the iterator
is exhausted so it is never polled again after EOF.
### Tests
- [x] New `BinaryMergeIteratorDoublePollTest`: polls a spilled and a
non-spilled `BinaryExternalSortBuffer` iterator multiple times after EOF; each
must keep returning `null`.
- [x] New `PostponeBucketTableITCase#testMergeOnReadWithSpilledCarriers`:
batch merge-on-read read of a postpone bucket table with
`sort-spill-buffer-size = '192 kb'`, which forces the carriers to spill and
verifies the merged result.
- [x] `PostponeBucketTableITCase` (full class): 22 tests pass.
- [x] `BinaryExternalSortBufferTest` and related core sort tests: 16 tests
pass.
- [x] Verified the new ITCase fails with the original NPE chain when the fix
is reverted.
--
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]