Repository navigation
fix(arrow-flight): Improve FlightDataEncoded::max_flight_data_size semantics - #12542
Open
azecevic000 wants to merge 2 commits into
Open
azecevic000 wants to merge 2 commits into
azecevic000 wants to merge 2 commits into
Conversation
… size `split_batch_for_grpc_response` only estimates a RecordBatch's encoded size from `get_buffer_memory_size()`, which ignores IPC framing/padding overhead and can badly undercount for variable-length data (dictionaries, strings). This let `FlightDataEncoder` silently emit `FlightData` messages larger than `max_flight_data_size` (see apache#3478). `FlightDataEncoder::encode_batch` now delegates to a new `encode_piece_adaptive`, which encodes each heuristic-split piece, queues any dictionaries unconditionally (they're keyed by id and correct to send regardless of how the batch body ends up sliced), and if the *actual* encoded size still exceeds the limit, re-splits, recursively if necessary.
Continue apache#11048, which encodes each piece and splits a message that is larger than the limit again. Make the first split fit, and keep the splits from sending data again with every row: - Estimate the first split from the slices of the arrays (`ArrayData::get_slice_memory_size`, the idea of apache#10383), with room for the IPC framing of the message and of each column. Decoded and sliced batches are then no longer split into many small messages. - Compact the top-level view columns of a piece with `gc()` when that makes them smaller: the IPC writer writes all data buffers of a view array, however it is sliced. - Encode the pieces of a message over the limit before they are used. If they do not all fit and the overhead of each piece, for example a large IPC header or the child of a list view array, is more than half of the limit, send the message as-is. - Encode the pieces of a split message without reserving the scratch buffer of the IPC writer: every body would start with at least the capacity of the split message, which is over the limit. Document the limit and its exceptions.
Contributor
Author
|
Thank you for the patience, it should be ready for review. CC @Rich-T-kid |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
split_batch_for_grpc_responseover-splits batches after IPC deserialization #9388This is the continuation and refinement of PR started by @DevMattG in #11048. Also applies the idea by @Rich-T-kid from #10383.
Rationale for this change
FlightDataEncodersplit eachRecordBatchby an estimate of its size, made before the IPC encoding. There are two main related issues with current approach:max_flight_data_size(Improve ability of FlightDataEncoder to respect max_flight_data_size for certain data types (strings, dictionaries, etc) #3478): the assumption is that rows are approximately equal-sized, which can work badly for cases where variable-length data-type fields exist (likeUtf8);split_batch_for_grpc_responseover-splits batches after IPC deserialization #9388):get_buffer_memory_sizeis used for estimating data size in the buffer, which counts the whole buffers of sliced arrays, which results in overestimation of data size, sometimes easily by a few orders of magnitude. The most prominent and realistic example is re-encoding of IPC decoded batch, where everyArrayshare the same buffer.What changes are included in this PR?
1. First split, by an estimate:
We can call it the optimistic case. This is a refined idea from what the main currently does. It introduces framing estimate, which becomes significant for very wide and complex schemas. The refinments compared to the main are:
2. Encode each piece. Its top-level
Utf8ViewandBinaryViewcolumns are compacted withgc()first, whenused bytes < buffer bytes: the IPC writer writes all data buffers of a view array, however it is sliced. Amessage with
size > limitand more than one row is cut inton = ceil(size / limit)pieces with equal rowcounts, which are encoded before they are used. Each piece repeats an
overheadthat the message has only once(the IPC header, and the data that all slices keep):
Cost. When the estimate is right (1st step),
encodes = pieces, as on main, and nothing is split again.This still doesn't make
FlightDataEncoded::max_flight_data_sizea hard limit (it would require splitting a single row in the general case), but it should generally improve a lot of cases, sometimes dramatically andmax_flight_data_sizeshould be a much better approximation in all cases I could think of.Are these changes tested?
Yes, there are a lot of new unit tests, since there are a lot of edge cases to cover. Some existing tests are also changed (look at the explanation). These tests cover both the functional part (round-trip tests), and heuristic part (how close are splitted batches to the
max_flight_data_size).Are there any significant user-facing changes?
No API breaking changes. This is a user-facing change in terms of the number of batches and their sizes for
FlightDataEncoderusers.AI usage disclosure
AI was used for writing the implementation and tests and parts of the description of this PR. The design decisions and review of LLM implementation were done by me.