Skip to content

fix(shm): split oversized batches so every frame fits its ring#37

Draft
mdashti wants to merge 1 commit into
rj.use-datafusion-55from
moe/frame-split
Draft

fix(shm): split oversized batches so every frame fits its ring#37
mdashti wants to merge 1 commit into
rj.use-datafusion-55from
moe/frame-split

Conversation

@mdashti

@mdashti mdashti commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

What

This PR splits an oversized batch at the shm send path so every encoded frame fits its ring.

Why

Operators emit offset slices of their accumulated state, and arrow-ipc writes a sliced variable-length array's whole values buffer, so one frame balloons to the state's size no matter the batch size. Small rings then fail wide GROUP BY and DISTINCT shapes with MessageTooLarge, and the only workaround was sizing every ring for the widest state any query might carry.

How

BatchChannelSender gains max_frame_bytes() (the ring's combined slot payload; None for unbounded in-proc channels). When an encoded frame exceeds it, the send path compacts the rows with take (dropping the shared buffers that cause the ballooning) and halves by rows until each frame fits, left-to-right so row order survives for sorted streams. The common case pays one length check. A single row larger than the ring still errors with the raise-the-knob message.

Tests

Unit: an oversized sliced batch splits into under-cap frames that decode back to the identical rows in order; a single oversized row still errors. End-to-end: a wide max(s) GROUP BY over 64KiB rings, whose raw partial-aggregate emits are ~10x the ring, matches the serial reference exactly.

Operators emit offset slices of their accumulated state, and arrow-ipc
writes a sliced variable-length array's whole values buffer, so one
frame balloons to the state's size no matter the batch size. Compacting
and halving on the oversized path bounds frames by the ring instead of
asking embedders to size rings for their widest state.
@mdashti
mdashti changed the base branch from main to rj.use-datafusion-55 July 22, 2026 22:33
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