Skip to content

fix: count buffers shared by sliced batches once in BufferExec - #2845

Open
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:fix/buffer-exec-shared-buffers
Open

andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:fix/buffer-exec-shared-buffers

Conversation

@andygrove

Copy link
Copy Markdown
Member

Which issue does this PR close?

No separate issue. Follow-up to #2796, split out of #2792.

Rationale for this change

#2796 made the sort shuffle buffer count each Arrow buffer once with DataFusion's RecordBatchMemoryCounter, so zero-copy slices of one large array (as aggregates emit) are not each charged with the whole shared buffer. BufferExec's dam mode has the same problem and was left out of that PR: it reserves get_array_memory_size() per buffered batch, so ten slices of one batch reserve ten times the memory they actually hold. Over-reserving makes the dam break early under memory pressure, even though the real memory use would have fit.

What changes are included in this PR?

  • BufferExec's dam fill phase reserves each batch's size from a RecordBatchMemoryCounter shared across the buffered batches, so a buffer shared by several slices is charged once.
  • New test dam_charges_buffer_shared_by_slices_once: it buffers ten slices of one 10,000-row batch and checks what stays reserved. Without the fix, 720,864 bytes stay reserved after the first drain (9 times the 80,096-byte shared buffer). With the fix, less than one buffer's worth does.
  • dam_reservation_shrinks_incrementally_during_drain now computes its expected sizes the same way.

Are there any user-facing changes?

No.

🤖 Generated with Claude Code

BufferExec's dam mode charged each buffered batch with
get_array_memory_size(), so zero-copy slices of one large array (as
aggregates emit) were each charged with the whole shared buffer. Use
RecordBatchMemoryCounter, as the sort shuffle buffer does since apache#2796.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant