JingsongLi commented on code in PR #1480:
URL: https://github.com/apache/paimon-rust/pull/1480#discussion_r4674529007
##########
crates/paimon/src/table/sort_merge.rs:
##########
@@ -2013,9 +2020,49 @@ fn sort_merge_stream(
.boxed())
}
-/// Concatenates per-key changelog batches into one changelog batch.
-fn changelog_batch(schema: &SchemaRef, batches: &[RecordBatch]) ->
crate::Result<RecordBatch> {
- arrow_select::concat::concat_batches(schema, batches).map_err(|error|
Error::DataInvalid {
+/// Copies the pending per-key changelog rows into one chunk that owns its
+/// buffers. A row sliced from a source batch keeps that whole batch alive and
+/// is charged in full by the format writer.
+fn detach_changelog(
+ chunks: &mut Vec<RecordBatch>,
+ pending: &mut Vec<RecordBatch>,
+) -> crate::Result<()> {
+ if pending.is_empty() {
+ return Ok(());
+ }
+ let batches = pending.iter().collect::<Vec<_>>();
+ let indices = pending
+ .iter()
+ .enumerate()
+ .flat_map(|(batch, rows)| (0..rows.num_rows()).map(move |row| (batch,
row)))
+ .collect::<Vec<_>>();
+ let chunk =
+ arrow_select::interleave::interleave_record_batch(&batches,
&indices).map_err(|error| {
Review Comment:
I reproduced the extra scratch allocation through an actual write, lookup
compaction and incremental read on the current `main` merge. The test published
127 existing keys and wrote one new key with a `MAP<INT, INT>` containing
500,000 entries. Both the base and this head produced the same single `+I`
event and all map entries. During compaction, this head allocated one
8,000,000-byte `(usize, usize)` vector, compared with zero on `main`. The full
task’s peak heap and peak resource reservation were effectively the same in
this fixture. The extra allocation still occurs before the changelog writer
reserves memory. A nested-column `take` or range-copy path would retain the
source-buffer fix while avoiding this scratch vector.
The two source-buffer regressions now pass. The local PK compaction suite
and changelog unit filter passed 113 and 44 tests respectively.
--
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]