[FLINK-40339][table] Do not read buffer entries after removing them - #28933
Conversation
| } | ||
|
|
||
| // Clear only after all values were read. | ||
| buffer.clear(); |
There was a problem hiding this comment.
This is simpler indeed, but RocksDB opens a new iterator here IIRC.
Opening an iterator is quite expensive, so this might cause a performance regression.
There was a problem hiding this comment.
This is the branch for the unordered state backends - so Rocksdb is not affected by the change. Currently in open source, only heap backend uses this path. I don't have a strong opinion though, if you think the delete strategy is safer, I can go with that
There was a problem hiding this comment.
Ops, that is not correct. I just went with the delete approach which means also less changes
The value of a Map.Entry is undefined once the entry has been removed, and RocksDBMapEntry returns null for it. consolidateBufferToMinValue removed the entries while iterating and read their values afterwards, which only works because the heap backend keeps them readable. Copy every entry before removing it. The key is copied as well because the entries are sorted by timestamp afterwards. This is hardening, no behaviour changes on the backends Flink ships: heap is the only unordered one, and RocksDB and ForSt take the ordered branch that already read the value before removing.
d64a01a to
7de938b
Compare
geeknarrator
left a comment
There was a problem hiding this comment.
LGTM. Should we add a test for this? I don't think it is covered by existing test, is it?
|
Hey @geeknarrator, our only state backend that tests this code is heap which already worked accidentally. Didn’t find a clean way to add additional testing without a adding a load of bloat but the current tests passing is a good coverage. If you have a good/clean suggestion on how to test this, let me know |
What is the purpose of the change
WatermarkCompactingSinkMaterializer removed buffer entries while iterating and read their values afterwards. The value of a Map.Entry is undefined once the entry has been removed, and RocksDBMapEntry returns null for it, so consolidation on restore only works because the heap backend keeps removed values readable.
Brief change log
Verifying this change
Does this pull request potentially affect one of the following parts:
@Public(Evolving): noDocumentation
Was generative AI tooling used to co-author this PR?
2.1.220 (Claude Code) with Opus 5