You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "itsjunetime (via GitHub)" <gi...@apache.org> on 2024/11/05 17:30:14 UTC
[PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
itsjunetime opened a new pull request, #6690:
URL: https://github.com/apache/arrow-rs/pull/6690
# Which issue does this PR close?
Closes #3478
# What changes are included in this PR?
This reworks the encoding/writing step of flight data messages to ensure it never overflows the given limit whenever possible (specifically, it's impossible when we can't even fit a single row + header within the limit - there are still no mechanisms for splitting a single row of data between multiple messages).
It does this by first constructing a fake IPC header, then getting that header's encoded length, and then subtracting that length from the provided max size. Because the header's size stays the same with the same schema (the only thing that changes is the value within the 'length of data' fields), we don't need to continually recalculate it.
There are more tests I'd like to add before merging this, I was just hoping to get this filed first so that I could get feedback in case any behavior seemed seriously off.
# Rationale for these changes
Since we are dynamically checking array data sizes to see if they can fit within the alloted size, this ensures that they will never go over if possible. Of course, as I said before, they will still go over if necessary, but I've rewritten the tests to check this behavior (if the tests sense an overage, but decode it to see that only one row was written, they allow it as there is no other way to get the data across).
# Are there any user-facing changes?
Yes, there are API additions. They are documented. As far as I can tell, this shouldn't require a breaking release, but I haven't run anything like cargo-semver-checks on it to actually verify.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #6690:
URL: https://github.com/apache/arrow-rs/pull/6690#issuecomment-2549834919
Marking as draft while we decide next steps -- From my perspective it isn't waiting on any additional feedback and I am trying to clear the review queue.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "itsjunetime (via GitHub)" <gi...@apache.org>.
itsjunetime commented on code in PR #6690:
URL: https://github.com/apache/arrow-rs/pull/6690#discussion_r1838650259
##########
arrow-flight/src/encode.rs:
##########
@@ -327,6 +327,10 @@ impl FlightDataEncoder {
/// Encodes batch into one or more `FlightData` messages in self.queue
fn encode_batch(&mut self, batch: RecordBatch) -> Result<()> {
+ if batch.num_rows() == 0 {
Review Comment:
So it looks like there are two contradicting comments regarding this behavior:
1. The doc comment for this function says `one or more` FlightData messages - implying that if we send an empty batch, it should still load one `FlightData` message into the queue. This is at odds with the previous behavior, which just used the response from `split_batch_for_grpc_response` as an iterator for batches to load in, but `split_batch...` returned an empty vector when given a `RecordBatch` with 0 rows.
2. A comment in the arrow-flight tests ([here](https://github.com/apache/arrow-rs/blob/3ee5048c8ea3aa531d111afe33d0a3551eabcd84/arrow-flight/tests/encode_decode.rs#L454)) that are relevant to this change says that empty batches should not be encoded. If we comment out the `filter` that removes empty batches AND comment out this check for empty batches, all tests pass.
Because there are multiple conflicting records of what is the expected behavior, I'm not sure what to do. I feel like we should respect the doc-comment, as that's what's documented to the users, but the behavior seems to be contrary to that, and it's also contrary to some other tests in arrow-ipc that always expect encoding of a Batch to return some encoded data (even if it's just a header).
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "itsjunetime (via GitHub)" <gi...@apache.org>.
itsjunetime commented on PR #6690:
URL: https://github.com/apache/arrow-rs/pull/6690#issuecomment-2463610613
It looks like CI failed due to some network flakiness - I'm going to close and reopen to try it again
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "itsjunetime (via GitHub)" <gi...@apache.org>.
itsjunetime commented on code in PR #6690:
URL: https://github.com/apache/arrow-rs/pull/6690#discussion_r1838632325
##########
arrow-data/src/data.rs:
##########
@@ -423,72 +423,97 @@ impl ArrayData {
size
}
- /// Returns the total number of the bytes of memory occupied by
- /// the buffers by this slice of [`ArrayData`] (See also diagram on [`ArrayData`]).
+ /// Returns the total number of the bytes of memory occupied by the buffers by this slice of
+ /// [`ArrayData`] (See also diagram on [`ArrayData`]).
///
- /// This is approximately the number of bytes if a new
- /// [`ArrayData`] was formed by creating new [`Buffer`]s with
- /// exactly the data needed.
+ /// This is approximately the number of bytes if a new [`ArrayData`] was formed by creating new
+ /// [`Buffer`]s with exactly the data needed.
///
- /// For example, a [`DataType::Int64`] with `100` elements,
- /// [`Self::get_slice_memory_size`] would return `100 * 8 = 800`. If
- /// the [`ArrayData`] was then [`Self::slice`]ed to refer to its
- /// first `20` elements, then [`Self::get_slice_memory_size`] on the
- /// sliced [`ArrayData`] would return `20 * 8 = 160`.
- pub fn get_slice_memory_size(&self) -> Result<usize, ArrowError> {
- let mut result: usize = 0;
+ /// For example, a [`DataType::Int64`] with `100` elements, [`Self::get_slice_memory_size`]
+ /// would return `100 * 8 = 800`. If the [`ArrayData`] was then [`Self::slice`]d to refer to
+ /// its first `20` elements, then [`Self::get_slice_memory_size`] on the sliced [`ArrayData`]
+ /// would return `20 * 8 = 160`.
+ ///
+ /// The `alignment` parameter is used to add padding to each buffer being counted, to ensure
+ /// the size for each one is aligned to `alignment` bytes (if it is `Some`)
+ pub fn get_slice_memory_size_with_alignment(
+ &self,
+ alignment: Option<u8>,
+ ) -> Result<usize, ArrowError> {
+ // Note: This accounts for data used by the Dictionary DataType that isn't actually encoded
+ // as a part of `write_array_data` in arrow-ipc - specifically, the `values` part of
+ // each Dictionary are encoded in the `child_data` of the `ArrayData` it produces, but (for
+ // some reason that I don't fully understand) it doesn't encode those values. hmm.
let layout = layout(&self.data_type);
- for spec in layout.buffers.iter() {
- match spec {
+ // Just pulled from arrow-ipc
+ #[inline]
+ fn pad_to_alignment(alignment: u8, len: usize) -> usize {
Review Comment:
Done in ae37b13e2e6cba462789c87d961436ad24c9919e
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "itsjunetime (via GitHub)" <gi...@apache.org>.
itsjunetime commented on code in PR #6690:
URL: https://github.com/apache/arrow-rs/pull/6690#discussion_r1835109766
##########
arrow-flight/src/encode.rs:
##########
@@ -1485,93 +1481,62 @@ mod tests {
hydrate_dictionaries(&batch, batch.schema()).expect("failed to optimize");
}
- pub fn make_flight_data(
- batch: &RecordBatch,
- options: &IpcWriteOptions,
- ) -> (Vec<FlightData>, FlightData) {
- let data_gen = IpcDataGenerator::default();
- let mut dictionary_tracker = DictionaryTracker::new_with_preserve_dict_id(false, true);
-
- let (encoded_dictionaries, encoded_batch) = data_gen
- .encoded_batch(batch, &mut dictionary_tracker, options)
- .expect("DictionaryTracker configured above to not error on replacement");
-
- let flight_dictionaries = encoded_dictionaries.into_iter().map(Into::into).collect();
- let flight_batch = encoded_batch.into();
-
- (flight_dictionaries, flight_batch)
- }
+ #[tokio::test]
+ async fn test_split_batch_for_grpc_response() {
+ async fn get_decoded(schema: SchemaRef, encoded: Vec<EncodedData>) -> Vec<RecordBatch> {
+ FlightDataDecoder::new(futures::stream::iter(
+ std::iter::once(SchemaAsIpc::new(&schema, &IpcWriteOptions::default()).into())
+ .chain(encoded.into_iter().map(FlightData::from))
+ .map(Ok),
+ ))
+ .collect::<Vec<Result<_>>>()
+ .await
+ .into_iter()
+ .map(|r| r.unwrap())
+ .filter_map(|data| match data.payload {
+ DecodedPayload::RecordBatch(rb) => Some(rb),
+ _ => None,
+ })
+ .collect()
+ }
- #[test]
- fn test_split_batch_for_grpc_response() {
let max_flight_data_size = 1024;
+ let write_opts = IpcWriteOptions::default();
+ let mut dict_tracker = DictionaryTracker::new(false);
+ let gen = IpcDataGenerator {};
// no split
let c = UInt32Array::from(vec![1, 2, 3, 4, 5, 6]);
let batch = RecordBatch::try_from_iter(vec![("a", Arc::new(c) as ArrayRef)])
.expect("cannot create record batch");
- let split = split_batch_for_grpc_response(batch.clone(), max_flight_data_size);
+ let split = gen
+ .encoded_batch_with_size(&batch, &mut dict_tracker, &write_opts, max_flight_data_size)
+ .unwrap()
+ .1;
assert_eq!(split.len(), 1);
- assert_eq!(batch, split[0]);
+ assert_eq!(batch, get_decoded(batch.schema(), split).await[0]);
// split once
let n_rows = max_flight_data_size + 1;
assert!(n_rows % 2 == 1, "should be an odd number");
let c = UInt8Array::from((0..n_rows).map(|i| (i % 256) as u8).collect::<Vec<_>>());
let batch = RecordBatch::try_from_iter(vec![("a", Arc::new(c) as ArrayRef)])
.expect("cannot create record batch");
- let split = split_batch_for_grpc_response(batch.clone(), max_flight_data_size);
- assert_eq!(split.len(), 3);
+ let split = gen
+ .encoded_batch_with_size(&batch, &mut dict_tracker, &write_opts, max_flight_data_size)
+ .unwrap()
+ .1;
+ assert_eq!(split.len(), 2);
+ let batches = get_decoded(batch.schema(), split).await;
assert_eq!(
- split.iter().map(|batch| batch.num_rows()).sum::<usize>(),
+ batches.iter().map(RecordBatch::num_rows).sum::<usize>(),
n_rows
);
- let a = pretty_format_batches(&split).unwrap().to_string();
+ let a = pretty_format_batches(&batches).unwrap().to_string();
let b = pretty_format_batches(&[batch]).unwrap().to_string();
assert_eq!(a, b);
}
- #[test]
Review Comment:
This test simply checked something that isn't applicable anymore - it assumes that we can split a single RecordBatch into smaller RecordBatches with less rows which saturate the given size, but we don't want to verify that we can do that anymore as we don't want to provide any way to split RecordBatches without also accomodating for the size of the IPC Headers (and the rest of the functions in this mod are already doing that).
This test was just mainly there for the `split_batch_for_grpc_response` function, and that's just not part of the design anymore.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "itsjunetime (via GitHub)" <gi...@apache.org>.
itsjunetime commented on code in PR #6690:
URL: https://github.com/apache/arrow-rs/pull/6690#discussion_r1835114076
##########
arrow-ipc/src/writer.rs:
##########
@@ -1414,44 +1314,73 @@ fn get_buffer_element_width(spec: &BufferSpec) -> usize {
}
}
-/// Common functionality for re-encoding offsets. Returns the new offsets as well as
-/// original start offset and length for use in slicing child data.
-fn reencode_offsets<O: OffsetSizeTrait>(
- offsets: &Buffer,
- data: &ArrayData,
-) -> (Buffer, usize, usize) {
- let offsets_slice: &[O] = offsets.typed_data::<O>();
- let offset_slice = &offsets_slice[data.offset()..data.offset() + data.len() + 1];
-
- let start_offset = offset_slice.first().unwrap();
- let end_offset = offset_slice.last().unwrap();
-
- let offsets = match start_offset.as_usize() {
- 0 => offsets.clone(),
- _ => offset_slice.iter().map(|x| *x - *start_offset).collect(),
- };
-
- let start_offset = start_offset.as_usize();
- let end_offset = end_offset.as_usize();
-
- (offsets, start_offset, end_offset - start_offset)
-}
-
-/// Returns the values and offsets [`Buffer`] for a ByteArray with offset type `O`
+/// Returns the offsets and values [`Buffer`]s for a ByteArray with offset type `O`
///
/// In particular, this handles re-encoding the offsets if they don't start at `0`,
/// slicing the values buffer as appropriate. This helps reduce the encoded
/// size of sliced arrays, as values that have been sliced away are not encoded
-fn get_byte_array_buffers<O: OffsetSizeTrait>(data: &ArrayData) -> (Buffer, Buffer) {
+///
+/// # Panics
+///
+/// Panics if self.buffers does not contain at least 2 buffers (this code expects that the
+/// first will contain the offsets for this variable-length array and the other will contain
+/// the values)
+pub fn get_byte_array_buffers<O: OffsetSizeTrait>(data: &ArrayData) -> (Buffer, Buffer) {
if data.is_empty() {
return (MutableBuffer::new(0).into(), MutableBuffer::new(0).into());
}
- let (offsets, original_start_offset, len) = reencode_offsets::<O>(&data.buffers()[0], data);
+ // get the buffer of offsets, now shifted so they are shifted to be accurate to the slice
+ // of values that we'll be taking (e.g. if they previously said [0, 3, 5, 7], but we slice
+ // to only get the last offset, they'll be shifted to be [0, 2], since that would be the
+ // offset pair for the last value in this shifted slice).
+ // also, in this example, original_start_offset would be 5 and len would be 2.
+ let (offsets, original_start_offset, len) = reencode_offsets::<O>(data);
let values = data.buffers()[1].slice_with_length(original_start_offset, len);
(offsets, values)
}
+/// Common functionality for re-encoding offsets. Returns the new offsets as well as
+/// original start offset and length for use in slicing child data.
+///
+/// # Panics
+///
+/// Will panic if you call this on an `ArrayData` that does not have a buffer of offsets as the
+/// very first buffer (i.e. expects this to be a valid variable-length array)
+pub fn reencode_offsets<O: OffsetSizeTrait>(data: &ArrayData) -> (Buffer, usize, usize) {
Review Comment:
No - thank you for catching that.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #6690:
URL: https://github.com/apache/arrow-rs/pull/6690#discussion_r1834632924
##########
arrow-ipc/src/writer.rs:
##########
@@ -448,15 +454,45 @@ impl IpcDataGenerator {
Ok(())
}
+ /// Calls [`Self::encoded_batch_with_size`] with no limit, returning the first (and only)
+ /// [`EncodedData`] that is produced. This method should be used over
+ /// [`Self::encoded_batch_with_size`] if the consumer has no concerns about encoded message
+ /// size limits
+ pub fn encoded_batch(
+ &self,
+ batch: &RecordBatch,
+ dictionary_tracker: &mut DictionaryTracker,
+ write_options: &IpcWriteOptions,
+ ) -> Result<(Vec<EncodedData>, EncodedData), ArrowError> {
+ let (encoded_dictionaries, mut encoded_messages) =
+ self.encoded_batch_with_size(batch, dictionary_tracker, write_options, usize::MAX)?;
+
+ assert_eq!(
+ encoded_messages.len(),
+ 1,
+ "encoded_batch with max size of usize::MAX should not be able to return more or less than 1 batch"
+ );
+
+ Ok((encoded_dictionaries, encoded_messages.pop().unwrap()))
+ }
+
/// Encodes a batch to a number of [EncodedData] items (dictionary batches + the record batch).
/// The [DictionaryTracker] keeps track of dictionaries with new `dict_id`s (so they are only sent once)
/// Make sure the [DictionaryTracker] is initialized at the start of the stream.
- pub fn encoded_batch(
+ /// The `max_flight_data_size` is used to control how much space each encoded [`RecordBatch`] is
Review Comment:
Since this is the IPC encoder (which can be used directly in addition to in Flight) what do you think about changing the name of `max_flight_data_size` to `max_encoded_data_size`?
##########
arrow-ipc/src/writer.rs:
##########
@@ -1414,44 +1314,73 @@ fn get_buffer_element_width(spec: &BufferSpec) -> usize {
}
}
-/// Common functionality for re-encoding offsets. Returns the new offsets as well as
-/// original start offset and length for use in slicing child data.
-fn reencode_offsets<O: OffsetSizeTrait>(
- offsets: &Buffer,
- data: &ArrayData,
-) -> (Buffer, usize, usize) {
- let offsets_slice: &[O] = offsets.typed_data::<O>();
- let offset_slice = &offsets_slice[data.offset()..data.offset() + data.len() + 1];
-
- let start_offset = offset_slice.first().unwrap();
- let end_offset = offset_slice.last().unwrap();
-
- let offsets = match start_offset.as_usize() {
- 0 => offsets.clone(),
- _ => offset_slice.iter().map(|x| *x - *start_offset).collect(),
- };
-
- let start_offset = start_offset.as_usize();
- let end_offset = end_offset.as_usize();
-
- (offsets, start_offset, end_offset - start_offset)
-}
-
-/// Returns the values and offsets [`Buffer`] for a ByteArray with offset type `O`
+/// Returns the offsets and values [`Buffer`]s for a ByteArray with offset type `O`
///
/// In particular, this handles re-encoding the offsets if they don't start at `0`,
/// slicing the values buffer as appropriate. This helps reduce the encoded
/// size of sliced arrays, as values that have been sliced away are not encoded
-fn get_byte_array_buffers<O: OffsetSizeTrait>(data: &ArrayData) -> (Buffer, Buffer) {
+///
+/// # Panics
+///
+/// Panics if self.buffers does not contain at least 2 buffers (this code expects that the
+/// first will contain the offsets for this variable-length array and the other will contain
+/// the values)
+pub fn get_byte_array_buffers<O: OffsetSizeTrait>(data: &ArrayData) -> (Buffer, Buffer) {
if data.is_empty() {
return (MutableBuffer::new(0).into(), MutableBuffer::new(0).into());
}
- let (offsets, original_start_offset, len) = reencode_offsets::<O>(&data.buffers()[0], data);
+ // get the buffer of offsets, now shifted so they are shifted to be accurate to the slice
+ // of values that we'll be taking (e.g. if they previously said [0, 3, 5, 7], but we slice
+ // to only get the last offset, they'll be shifted to be [0, 2], since that would be the
+ // offset pair for the last value in this shifted slice).
+ // also, in this example, original_start_offset would be 5 and len would be 2.
+ let (offsets, original_start_offset, len) = reencode_offsets::<O>(data);
let values = data.buffers()[1].slice_with_length(original_start_offset, len);
(offsets, values)
}
+/// Common functionality for re-encoding offsets. Returns the new offsets as well as
+/// original start offset and length for use in slicing child data.
+///
+/// # Panics
+///
+/// Will panic if you call this on an `ArrayData` that does not have a buffer of offsets as the
+/// very first buffer (i.e. expects this to be a valid variable-length array)
+pub fn reencode_offsets<O: OffsetSizeTrait>(data: &ArrayData) -> (Buffer, usize, usize) {
Review Comment:
does this need to be pub?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "itsjunetime (via GitHub)" <gi...@apache.org>.
itsjunetime commented on code in PR #6690:
URL: https://github.com/apache/arrow-rs/pull/6690#discussion_r1835082863
##########
arrow-flight/src/encode.rs:
##########
@@ -327,6 +327,10 @@ impl FlightDataEncoder {
/// Encodes batch into one or more `FlightData` messages in self.queue
fn encode_batch(&mut self, batch: RecordBatch) -> Result<()> {
+ if batch.num_rows() == 0 {
Review Comment:
This is not an optimization, but rather due to a difference in behavior that the tests dictate - in some of the tests, encoding an empty batch should result in an IPC header + empty data, but in some other tests, encoding an empty batch should result in nothing. I haven't yet figured out exactly why that is, and need to do some more poking to figure out why different parts of the code want this different behavior.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "itsjunetime (via GitHub)" <gi...@apache.org>.
itsjunetime commented on code in PR #6690:
URL: https://github.com/apache/arrow-rs/pull/6690#discussion_r1838630127
##########
arrow-data/src/data.rs:
##########
@@ -423,72 +423,97 @@ impl ArrayData {
size
}
- /// Returns the total number of the bytes of memory occupied by
- /// the buffers by this slice of [`ArrayData`] (See also diagram on [`ArrayData`]).
+ /// Returns the total number of the bytes of memory occupied by the buffers by this slice of
+ /// [`ArrayData`] (See also diagram on [`ArrayData`]).
///
- /// This is approximately the number of bytes if a new
- /// [`ArrayData`] was formed by creating new [`Buffer`]s with
- /// exactly the data needed.
+ /// This is approximately the number of bytes if a new [`ArrayData`] was formed by creating new
+ /// [`Buffer`]s with exactly the data needed.
///
- /// For example, a [`DataType::Int64`] with `100` elements,
- /// [`Self::get_slice_memory_size`] would return `100 * 8 = 800`. If
- /// the [`ArrayData`] was then [`Self::slice`]ed to refer to its
- /// first `20` elements, then [`Self::get_slice_memory_size`] on the
- /// sliced [`ArrayData`] would return `20 * 8 = 160`.
- pub fn get_slice_memory_size(&self) -> Result<usize, ArrowError> {
- let mut result: usize = 0;
+ /// For example, a [`DataType::Int64`] with `100` elements, [`Self::get_slice_memory_size`]
+ /// would return `100 * 8 = 800`. If the [`ArrayData`] was then [`Self::slice`]d to refer to
+ /// its first `20` elements, then [`Self::get_slice_memory_size`] on the sliced [`ArrayData`]
+ /// would return `20 * 8 = 160`.
+ ///
+ /// The `alignment` parameter is used to add padding to each buffer being counted, to ensure
+ /// the size for each one is aligned to `alignment` bytes (if it is `Some`)
+ pub fn get_slice_memory_size_with_alignment(
+ &self,
+ alignment: Option<u8>,
+ ) -> Result<usize, ArrowError> {
+ // Note: This accounts for data used by the Dictionary DataType that isn't actually encoded
+ // as a part of `write_array_data` in arrow-ipc - specifically, the `values` part of
+ // each Dictionary are encoded in the `child_data` of the `ArrayData` it produces, but (for
+ // some reason that I don't fully understand) it doesn't encode those values. hmm.
let layout = layout(&self.data_type);
- for spec in layout.buffers.iter() {
- match spec {
+ // Just pulled from arrow-ipc
+ #[inline]
+ fn pad_to_alignment(alignment: u8, len: usize) -> usize {
Review Comment:
Thanks for catching that - I think the best move would just be documenting this in the function doc-comment so people can be aware of that.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #6690:
URL: https://github.com/apache/arrow-rs/pull/6690#issuecomment-2549831846
Hi @itsjunetime -- what is the next step for this PR?
Both @tustvold and I have suggested various ways to break it into parts that are more easy to review and the parts you were able to split off we got in
- https://github.com/apache/arrow-rs/pull/6725
- https://github.com/apache/arrow-rs/pull/6707
This PR has now accumulated a bunch of conflicts and I am not sure what to do with it now.
To reiterate, I don't feel comfortable / able to review this PR in its current form . That isn't to say I can't read the code, but it is beyond my ability to review it in pieces and verify it won't cause some issue / regression due to the number of things it changes.
Please let us know how you want to proceed.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "itsjunetime (via GitHub)" <gi...@apache.org>.
itsjunetime commented on PR #6690:
URL: https://github.com/apache/arrow-rs/pull/6690#issuecomment-2480879299
> Let me see if I can help to find a way to break this PR up into smaller, more manageable pieces, so that we can get this in / tested in a way that is reasonable to maintain
One change I could make that may help with breaking this up and also with @tustvold's concern about the IPC-specific interface would be to maybe genericize the `get_memory_slice_size_with_alignment` over a `T: MemoryAccountant` (or something like that), e.g.:
```rust
enum SizeSource {
Buffer(BufferType),
NullBuffer,
ChildData,
// does it need to be more granular? idk
}
trait MemoryAccountant {
fn count_size(&mut self, size: usize, source: SizeSource);
}
impl ArrayData {
fn get_slice_memory_size_with_accountant<A: MemoryAccountant>(
&self,
acc: &mut A
) -> Result<(), ArrowError> {
// ...
}
fn get_slice_memory_size(&self) -> Result<usize, ArrowError> {
struct DefaultAccountant(usize);
impl MemoryAccountant for DefaultAccountant {
fn count_size(&mut self, size: usize, _: SizeSource) {
self.0 += size;
}
}
let mut acc = DefaultAccountant(0);
self.get_slice_memory_size_with_accountant(&mut acc)?;
Ok(acc.0)
}
}
```
This would allows us to use it nicely with the 'alignment' accounting that we need without being too IPC-specific. It would also allow us to remove the ugly re-accounting for `RunEndEncoded` buffers that this PR adds in `get_encoded_arr_batch_size`, which would be nice.
Obviously, I'd be happy to make this change and pull it out to a separate PR (to make this PR easier to review once that separate PR is merged) if we feel like this would be a better move.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "itsjunetime (via GitHub)" <gi...@apache.org>.
itsjunetime commented on code in PR #6690:
URL: https://github.com/apache/arrow-rs/pull/6690#discussion_r1835086786
##########
arrow-flight/src/encode.rs:
##########
@@ -700,6 +682,9 @@ mod tests {
use super::*;
#[test]
+ // flight_data_from_arrow_batch is deprecated but does exactly what we need. Would probably be
Review Comment:
I guess I just didn't see the purpose for duplicating code when this method already existed and did the exact same thing as `make_flight_data`. It also seems that `flight_data_from_arrow_batch` is a perfectly fine method, just easy to misuse, and that's why it was deprecated. Its behavior was duplicated in many different places throughout this crate, though - I don't think it's something that we would ever want to completely remove from usage, as it clearly has an internal purpose.
When we want to remove `flight_data_from_arrow_batch` from the public API, we could just comfortably make it private, and keep using its functionality internally.
Does that make sense? I feel like I may not be explaining my thoughts perfectly.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "itsjunetime (via GitHub)" <gi...@apache.org>.
itsjunetime closed pull request #6690: Prevent FlightData overflowing max size limit whenever possible.
URL: https://github.com/apache/arrow-rs/pull/6690
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #6690:
URL: https://github.com/apache/arrow-rs/pull/6690#discussion_r1837844977
##########
arrow-data/src/data.rs:
##########
@@ -423,72 +423,97 @@ impl ArrayData {
size
}
- /// Returns the total number of the bytes of memory occupied by
- /// the buffers by this slice of [`ArrayData`] (See also diagram on [`ArrayData`]).
+ /// Returns the total number of the bytes of memory occupied by the buffers by this slice of
+ /// [`ArrayData`] (See also diagram on [`ArrayData`]).
///
- /// This is approximately the number of bytes if a new
- /// [`ArrayData`] was formed by creating new [`Buffer`]s with
- /// exactly the data needed.
+ /// This is approximately the number of bytes if a new [`ArrayData`] was formed by creating new
+ /// [`Buffer`]s with exactly the data needed.
///
- /// For example, a [`DataType::Int64`] with `100` elements,
- /// [`Self::get_slice_memory_size`] would return `100 * 8 = 800`. If
- /// the [`ArrayData`] was then [`Self::slice`]ed to refer to its
- /// first `20` elements, then [`Self::get_slice_memory_size`] on the
- /// sliced [`ArrayData`] would return `20 * 8 = 160`.
- pub fn get_slice_memory_size(&self) -> Result<usize, ArrowError> {
- let mut result: usize = 0;
+ /// For example, a [`DataType::Int64`] with `100` elements, [`Self::get_slice_memory_size`]
+ /// would return `100 * 8 = 800`. If the [`ArrayData`] was then [`Self::slice`]d to refer to
+ /// its first `20` elements, then [`Self::get_slice_memory_size`] on the sliced [`ArrayData`]
+ /// would return `20 * 8 = 160`.
+ ///
+ /// The `alignment` parameter is used to add padding to each buffer being counted, to ensure
+ /// the size for each one is aligned to `alignment` bytes (if it is `Some`)
+ pub fn get_slice_memory_size_with_alignment(
+ &self,
+ alignment: Option<u8>,
+ ) -> Result<usize, ArrowError> {
+ // Note: This accounts for data used by the Dictionary DataType that isn't actually encoded
+ // as a part of `write_array_data` in arrow-ipc - specifically, the `values` part of
+ // each Dictionary are encoded in the `child_data` of the `ArrayData` it produces, but (for
+ // some reason that I don't fully understand) it doesn't encode those values. hmm.
let layout = layout(&self.data_type);
- for spec in layout.buffers.iter() {
- match spec {
+ // Just pulled from arrow-ipc
+ #[inline]
+ fn pad_to_alignment(alignment: u8, len: usize) -> usize {
Review Comment:
I think this is assuming alignment is a power of two
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on PR #6690:
URL: https://github.com/apache/arrow-rs/pull/6690#issuecomment-3691174284
Closing this PR as stale. Feel free to reopen if it becomes active again.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "itsjunetime (via GitHub)" <gi...@apache.org>.
itsjunetime commented on code in PR #6690:
URL: https://github.com/apache/arrow-rs/pull/6690#discussion_r1832863993
##########
arrow-ipc/src/writer.rs:
##########
@@ -1462,280 +1391,508 @@ fn get_list_array_buffers<O: OffsetSizeTrait>(data: &ArrayData) -> (Buffer, Arra
);
}
- let (offsets, original_start_offset, len) = reencode_offsets::<O>(&data.buffers()[0], data);
+ let (offsets, original_start_offset, len) = reencode_offsets::<O>(data);
let child_data = data.child_data()[0].slice(original_start_offset, len);
(offsets, child_data)
}
-/// Write array data to a vector of bytes
-#[allow(clippy::too_many_arguments)]
-fn write_array_data(
- array_data: &ArrayData,
- buffers: &mut Vec<crate::Buffer>,
- arrow_data: &mut Vec<u8>,
- nodes: &mut Vec<crate::FieldNode>,
- offset: i64,
- num_rows: usize,
- null_count: usize,
- compression_codec: Option<CompressionCodec>,
+const DEFAULT_ALIGNMENT: u8 = 64;
+const PADDING: [u8; DEFAULT_ALIGNMENT as usize] = [0; DEFAULT_ALIGNMENT as usize];
+
+/// Calculate an alignment boundary and return the number of bytes needed to pad to the alignment boundary
+#[inline]
+fn pad_to_alignment(alignment: u8, len: usize) -> usize {
+ let a = usize::from(alignment - 1);
+ ((len + a) & !a) - len
+}
+
+fn chunked_encoded_batch_bytes(
+ batch: &RecordBatch,
write_options: &IpcWriteOptions,
-) -> Result<i64, ArrowError> {
- let mut offset = offset;
- if !matches!(array_data.data_type(), DataType::Null) {
- nodes.push(crate::FieldNode::new(num_rows as i64, null_count as i64));
- } else {
- // NullArray's null_count equals to len, but the `null_count` passed in is from ArrayData
- // where null_count is always 0.
- nodes.push(crate::FieldNode::new(num_rows as i64, num_rows as i64));
- }
- if has_validity_bitmap(array_data.data_type(), write_options) {
- // write null buffer if exists
- let null_buffer = match array_data.nulls() {
- None => {
- // create a buffer and fill it with valid bits
- let num_bytes = bit_util::ceil(num_rows, 8);
- let buffer = MutableBuffer::new(num_bytes);
- let buffer = buffer.with_bitset(num_bytes, true);
- buffer.into()
- }
- Some(buffer) => buffer.inner().sliced(),
+ max_flight_data_size: usize,
+) -> Result<Vec<EncodedData>, ArrowError> {
+ encode_array_datas(
+ &batch
+ .columns()
+ .iter()
+ .map(ArrayRef::to_data)
+ .collect::<Vec<_>>(),
+ batch.num_rows(),
+ |_, offset| offset.as_union_value(),
+ MessageHeader::RecordBatch,
+ max_flight_data_size,
+ write_options,
+ )
+}
+
+fn get_encoded_arr_batch_size<AD: Borrow<ArrayData>>(
+ iter: impl IntoIterator<Item = AD>,
+ write_options: &IpcWriteOptions,
+) -> Result<usize, ArrowError> {
+ iter.into_iter()
+ .map(|arr| {
+ let arr = arr.borrow();
+ arr.get_slice_memory_size_with_alignment(Some(write_options.alignment))
+ .map(|size| {
+ let didnt_count_nulls = arr.nulls().is_none();
+ let will_write_nulls = has_validity_bitmap(arr.data_type(), write_options);
+
+ if will_write_nulls && didnt_count_nulls {
+ let null_len = bit_util::ceil(arr.len(), 8);
+ size + null_len + pad_to_alignment(write_options.alignment, null_len)
+ } else {
+ size
+ }
+ })
+ })
+ .sum()
+}
+
+fn encode_array_datas(
+ arr_datas: &[ArrayData],
+ n_rows: usize,
+ encode_root: impl Fn(
+ &mut FlatBufferSizeTracker,
+ WIPOffset<crate::gen::Message::RecordBatch>,
+ ) -> WIPOffset<UnionWIPOffset>,
+ header_type: MessageHeader,
+ mut max_msg_size: usize,
+ write_options: &IpcWriteOptions,
+) -> Result<Vec<EncodedData>, ArrowError> {
+ let mut fbb = FlatBufferSizeTracker::for_dry_run(arr_datas.len());
+ fbb.encode_array_datas(
+ arr_datas,
+ n_rows as i64,
+ &encode_root,
+ header_type,
+ write_options,
+ )?;
+
+ let header_len = fbb.fbb.finished_data().len();
+ max_msg_size = max_msg_size.saturating_sub(header_len).max(1);
+
+ let total_size = get_encoded_arr_batch_size(arr_datas.iter(), write_options)?;
+
+ let n_batches = bit_util::ceil(total_size, max_msg_size);
+ let mut out = Vec::with_capacity(n_batches);
+
+ let mut offset = 0;
+ while offset < n_rows.max(1) {
+ let slice_arrays = |len: usize| {
+ arr_datas.iter().map(move |arr| {
+ if len >= arr.len() {
+ arr.clone()
+ } else {
+ arr.slice(offset, len)
+ }
+ })
};
- offset = write_buffer(
- null_buffer.as_slice(),
- buffers,
- arrow_data,
- offset,
- compression_codec,
- write_options.alignment,
- )?;
- }
+ let rows_left = n_rows - offset;
+ // TODO? maybe this could be more efficient by continually approximating the maximum number
+ // of rows based on (size / n_rows) of the current ArrayData slice until we've found the
+ // maximum that can fit? e.g. 'oh, it's 200 bytes and 10 rows, so each row is probably 20
+ // bytes - let's do (max_size / 20) rows and see if that fits'
+ let length = (1..=rows_left)
+ .find(|len| {
+ // If we've exhausted the available length of the array datas, then just return -
+ // we've got it.
+ if offset + len > n_rows {
+ return true;
+ }
- let data_type = array_data.data_type();
- if matches!(data_type, DataType::Binary | DataType::Utf8) {
- let (offsets, values) = get_byte_array_buffers::<i32>(array_data);
- for buffer in [offsets, values] {
- offset = write_buffer(
- buffer.as_slice(),
- buffers,
- arrow_data,
- offset,
- compression_codec,
- write_options.alignment,
+ // we can unwrap this here b/c this only errors on malformed buffer-type/data-type
+ // combinations, and if any of these arrays had that, this function would've
+ // already short-circuited on an earlier call of this function
+ get_encoded_arr_batch_size(slice_arrays(*len), write_options).unwrap()
+ > max_msg_size
+ })
+ // If no rows fit in the given max size, we want to try to get the data across anyways,
+ // so that just means doing a single row. Calling `max(2)` is how we ensure that - if
+ // the very first item would go over the max size, giving us a length of 0, we want to
+ // set this to `2` so that taking away 1 leaves us with one row to encode.
+ .map(|len| len.max(2) - 1)
+ // If all rows can comfortably fit in this given size, then just get them all
+ .unwrap_or(rows_left);
+
+ // We could get into a situtation where we were given all 0-row arrays to be sent over
+ // flight - we do need to send a flight message to show that there is no data, but we also
+ // can't have `length` be 0 at this point because it could also be that all rows are too
+ // large to send with the provided limits and so we just want to try to send one now
+ // anyways, so the checks in this fn are just how we cover our bases there.
+ let new_arrs = slice_arrays(length).collect::<Vec<_>>();
+
+ // If we've got more than one row to encode or if we have 0 rows to encode but we haven't
+ // encoded anything yet, then continue with encoding. We don't need to do encoding, though,
+ // if we've already encoded some rows and there's no rows left
+ if length != 0 || offset == 0 {
+ fbb.reset_for_real_run();
+ fbb.encode_array_datas(
+ &new_arrs,
+ length as i64,
+ &encode_root,
+ header_type,
+ write_options,
)?;
+
+ let finished_data = fbb.fbb.finished_data();
+
+ out.push(EncodedData {
+ ipc_message: finished_data.to_vec(),
+ arrow_data: fbb.arrow_data.clone(),
+ });
}
- } else if matches!(data_type, DataType::BinaryView | DataType::Utf8View) {
- // Slicing the views buffer is safe and easy,
- // but pruning unneeded data buffers is much more nuanced since it's complicated to prove that no views reference the pruned buffers
- //
- // Current implementation just serialize the raw arrays as given and not try to optimize anything.
- // If users wants to "compact" the arrays prior to sending them over IPC,
- // they should consider the gc API suggested in #5513
- for buffer in array_data.buffers() {
- offset = write_buffer(
- buffer.as_slice(),
- buffers,
- arrow_data,
- offset,
- compression_codec,
- write_options.alignment,
- )?;
+
+ // If length == 0, that means they gave us ArrayData with no rows, so a single iteration is
+ // always sufficient.
+ if length == 0 {
+ break;
}
- } else if matches!(data_type, DataType::LargeBinary | DataType::LargeUtf8) {
- let (offsets, values) = get_byte_array_buffers::<i64>(array_data);
- for buffer in [offsets, values] {
- offset = write_buffer(
- buffer.as_slice(),
- buffers,
- arrow_data,
- offset,
- compression_codec,
- write_options.alignment,
+
+ offset += length;
+ }
+
+ Ok(out)
+}
+
+/// A struct to help ensure that the size of encoded flight messages never goes over a provided
+/// limit (except in ridiculous cases like a limit of 1 byte). The way it does so is by first
+/// running through a provided slice of [`ArrayData`], producing an IPC header message for that
+/// slice, and then subtracting the size of that generated header from the message limit it has
+/// been given. Because IPC header message sizes don't change due to a different amount of rows,
+/// this header size will stay consistent throughout the entire time that we have to transmit a
+/// chunk of rows, so we can just subtract it from the overall limit and use that to check
+/// different slices of `ArrayData` against to know how many to transmit each time.
+///
+/// This whole process is done in [`encode_array_datas()`] above
+#[derive(Default)]
+struct FlatBufferSizeTracker<'fbb> {
+ // the builder and backing flatbuffer that we use to write the arrow data into.
+ fbb: FlatBufferBuilder<'fbb>,
+ // tracks the data in `arrow_data` - `buffers` contains the offsets and length of different
+ // buffers encoded within the big chunk that is `arrow_data`.
+ buffers: Vec<crate::Buffer>,
+ // the raw array data that we need to send across the wire
+ arrow_data: Vec<u8>,
+ nodes: Vec<crate::FieldNode>,
+ dry_run: bool,
+}
+
+impl<'fbb> FlatBufferSizeTracker<'fbb> {
+ /// Preferred initializer, as this should always be used with a dry-run before a real run to
+ /// figure out the size of the IPC header.
+ #[must_use]
+ fn for_dry_run(capacity: usize) -> Self {
+ Self {
+ dry_run: true,
+ buffers: Vec::with_capacity(capacity),
+ nodes: Vec::with_capacity(capacity),
+ ..Self::default()
+ }
+ }
+
+ /// Should be called in-between calls to `encode_array_datas` to ensure we don't accidentally
+ /// keep & encode old data each time.
+ fn reset_for_real_run(&mut self) {
+ self.fbb.reset();
+ self.buffers.clear();
+ self.arrow_data.clear();
+ self.nodes.clear();
+ self.dry_run = false;
+
+ // this helps us avoid completely re-allocating the buffers by just creating a new `Self`.
+ // So everything should be allocated correctly now besides arrow_data. If we're calling
+ // this after only a dry run, `arrow_data` shouldn't have anything written into it, but
+ // we call this after every real run loop, so we still need to clear it.
+ }
+
+ fn encode_array_datas(
+ &mut self,
+ arr_datas: &[ArrayData],
+ n_rows: i64,
+ encode_root: impl FnOnce(
+ &mut FlatBufferSizeTracker,
+ WIPOffset<crate::gen::Message::RecordBatch>,
+ ) -> WIPOffset<UnionWIPOffset>,
+ header_type: MessageHeader,
+ write_options: &IpcWriteOptions,
+ ) -> Result<(), ArrowError> {
+ let batch_compression_type = write_options.batch_compression_type;
+
+ let compression = batch_compression_type.map(|compression_type| {
+ let mut builder = BodyCompressionBuilder::new(&mut self.fbb);
+ builder.add_method(BodyCompressionMethod::BUFFER);
+ builder.add_codec(compression_type);
+ builder.finish()
+ });
+
+ let mut variadic_buffer_counts = Vec::<i64>::default();
+ let mut offset = 0;
+
+ for array in arr_datas {
+ self.write_array_data(
+ array,
+ &mut offset,
+ array.len(),
+ array.null_count(),
+ write_options,
)?;
+
+ append_variadic_buffer_counts(&mut variadic_buffer_counts, array);
}
- } else if DataType::is_numeric(data_type)
- || DataType::is_temporal(data_type)
- || matches!(
- array_data.data_type(),
- DataType::FixedSizeBinary(_) | DataType::Dictionary(_, _)
- )
- {
- // Truncate values
- assert_eq!(array_data.buffers().len(), 1);
-
- let buffer = &array_data.buffers()[0];
- let layout = layout(data_type);
- let spec = &layout.buffers[0];
-
- let byte_width = get_buffer_element_width(spec);
- let min_length = array_data.len() * byte_width;
- let buffer_slice = if buffer_need_truncate(array_data.offset(), buffer, spec, min_length) {
- let byte_offset = array_data.offset() * byte_width;
- let buffer_length = min(min_length, buffer.len() - byte_offset);
- &buffer.as_slice()[byte_offset..(byte_offset + buffer_length)]
- } else {
- buffer.as_slice()
+
+ // pad the tail of the body data
+ let pad_len = pad_to_alignment(write_options.alignment, self.arrow_data.len());
+ self.arrow_data.extend_from_slice(&PADDING[..pad_len]);
+
+ let buffers = self.fbb.create_vector(&self.buffers);
+ let nodes = self.fbb.create_vector(&self.nodes);
+ let variadic_buffer = (!variadic_buffer_counts.is_empty())
+ .then(|| self.fbb.create_vector(&variadic_buffer_counts));
+
+ let root = {
+ let mut builder = RecordBatchBuilder::new(&mut self.fbb);
+
+ builder.add_length(n_rows);
+ builder.add_nodes(nodes);
+ builder.add_buffers(buffers);
+ if let Some(c) = compression {
+ builder.add_compression(c);
+ }
+ if let Some(v) = variadic_buffer {
+ builder.add_variadicBufferCounts(v);
+ }
+
+ builder.finish()
};
- offset = write_buffer(
- buffer_slice,
- buffers,
- arrow_data,
- offset,
- compression_codec,
- write_options.alignment,
- )?;
- } else if matches!(data_type, DataType::Boolean) {
- // Bools are special because the payload (= 1 bit) is smaller than the physical container elements (= bytes).
- // The array data may not start at the physical boundary of the underlying buffer, so we need to shift bits around.
- assert_eq!(array_data.buffers().len(), 1);
-
- let buffer = &array_data.buffers()[0];
- let buffer = buffer.bit_slice(array_data.offset(), array_data.len());
- offset = write_buffer(
- &buffer,
- buffers,
- arrow_data,
- offset,
- compression_codec,
- write_options.alignment,
- )?;
- } else if matches!(
- data_type,
- DataType::List(_) | DataType::LargeList(_) | DataType::Map(_, _)
- ) {
- assert_eq!(array_data.buffers().len(), 1);
- assert_eq!(array_data.child_data().len(), 1);
-
- // Truncate offsets and the child data to avoid writing unnecessary data
- let (offsets, sliced_child_data) = match data_type {
- DataType::List(_) => get_list_array_buffers::<i32>(array_data),
- DataType::Map(_, _) => get_list_array_buffers::<i32>(array_data),
- DataType::LargeList(_) => get_list_array_buffers::<i64>(array_data),
- _ => unreachable!(),
+
+ let root = encode_root(self, root);
+
+ let arrow_len = self.arrow_data.len() as i64;
+ let msg = {
+ let mut builder = MessageBuilder::new(&mut self.fbb);
+ builder.add_version(write_options.metadata_version);
+ builder.add_header_type(header_type);
+ builder.add_bodyLength(arrow_len);
+
+ builder.add_header(root);
+ builder.finish()
};
- offset = write_buffer(
- offsets.as_slice(),
- buffers,
- arrow_data,
- offset,
- compression_codec,
- write_options.alignment,
- )?;
- offset = write_array_data(
- &sliced_child_data,
- buffers,
- arrow_data,
- nodes,
- offset,
- sliced_child_data.len(),
- sliced_child_data.null_count(),
- compression_codec,
- write_options,
- )?;
- return Ok(offset);
- } else {
- for buffer in array_data.buffers() {
- offset = write_buffer(
- buffer,
- buffers,
- arrow_data,
+
+ self.fbb.finish(msg, None);
+ Ok(())
+ }
+
+ fn write_array_data(
+ &mut self,
+ array_data: &ArrayData,
+ offset: &mut i64,
+ num_rows: usize,
+ null_count: usize,
+ write_options: &IpcWriteOptions,
+ ) -> Result<(), ArrowError> {
+ let compression_codec: Option<CompressionCodec> = write_options
+ .batch_compression_type
+ .map(TryInto::try_into)
+ .transpose()?;
+
+ // NullArray's null_count equals to len, but the `null_count` passed in is from ArrayData
+ // where null_count is always 0.
+ self.nodes.push(crate::FieldNode::new(
+ num_rows as i64,
+ match array_data.data_type() {
+ DataType::Null => num_rows,
+ _ => null_count,
+ } as i64,
+ ));
+
+ if has_validity_bitmap(array_data.data_type(), write_options) {
+ // write null buffer if exists
+ let null_buffer = match array_data.nulls() {
+ None => {
+ let num_bytes = bit_util::ceil(num_rows, 8);
+ // create a buffer and fill it with valid bits
+ MutableBuffer::new(num_bytes)
+ .with_bitset(num_bytes, true)
+ .into()
+ }
+ Some(buffer) => buffer.inner().sliced(),
+ };
+
+ self.write_buffer(
+ &null_buffer,
offset,
compression_codec,
write_options.alignment,
)?;
}
- }
- match array_data.data_type() {
- DataType::Dictionary(_, _) => {}
- DataType::RunEndEncoded(_, _) => {
- // unslice the run encoded array.
- let arr = unslice_run_array(array_data.clone())?;
- // recursively write out nested structures
- for data_ref in arr.child_data() {
- // write the nested data (e.g list data)
- offset = write_array_data(
- data_ref,
- buffers,
- arrow_data,
- nodes,
+ let mut write_byte_array_byffers = |(offsets, values): (Buffer, Buffer)| {
+ for buffer in [offsets, values] {
+ self.write_buffer(&buffer, offset, compression_codec, write_options.alignment)?;
+ }
+ Ok::<_, ArrowError>(())
+ };
+
+ match array_data.data_type() {
+ DataType::Binary | DataType::Utf8 => {
+ write_byte_array_byffers(get_byte_array_buffers::<i32>(array_data))?
+ }
+ DataType::LargeBinary | DataType::LargeUtf8 => {
+ write_byte_array_byffers(get_byte_array_buffers::<i64>(array_data))?
+ }
+ dt if DataType::is_numeric(dt)
+ || DataType::is_temporal(dt)
+ || matches!(
+ dt,
+ DataType::FixedSizeBinary(_) | DataType::Dictionary(_, _)
+ ) =>
+ {
+ // Truncate values
+ let [buffer] = array_data.buffers() else {
+ panic!("Temporal, Numeric, FixedSizeBinary, and Dictionary data types must contain only one buffer");
+ };
+
+ let layout = layout(dt);
+ let spec = &layout.buffers[0];
+
+ let byte_width = get_buffer_element_width(spec);
+ let min_length = array_data.len() * byte_width;
+ let mut buffer_slice = buffer.as_slice();
+
+ if buffer_need_truncate(array_data.offset(), buffer, spec, min_length) {
+ let byte_offset = array_data.offset() * byte_width;
+ let buffer_length = min(min_length, buffer.len() - byte_offset);
+ buffer_slice = &buffer_slice[byte_offset..(byte_offset + buffer_length)];
+ }
+
+ self.write_buffer(
+ buffer_slice,
offset,
- data_ref.len(),
- data_ref.null_count(),
compression_codec,
+ write_options.alignment,
+ )?;
+ }
+ DataType::Boolean => {
+ // Bools are special because the payload (= 1 bit) is smaller than the physical container elements (= bytes).
+ // The array data may not start at the physical boundary of the underlying buffer,
+ // so we need to shift bits around.
+ let [single_buf] = array_data.buffers() else {
+ panic!("ArrayData of type Boolean should only contain 1 buffer");
+ };
+
+ let buffer = &single_buf.bit_slice(array_data.offset(), array_data.len());
+ self.write_buffer(buffer, offset, compression_codec, write_options.alignment)?;
+ }
+ dt @ (DataType::List(_) | DataType::LargeList(_) | DataType::Map(_, _)) => {
+ assert_eq!(array_data.buffers().len(), 1);
+ assert_eq!(array_data.child_data().len(), 1);
+
+ // Truncate offsets and the child data to avoid writing unnecessary data
+ let (offsets, sliced_child_data) = match dt {
+ DataType::List(_) | DataType::Map(_, _) => {
+ get_list_array_buffers::<i32>(array_data)
+ }
+ DataType::LargeList(_) => get_list_array_buffers::<i64>(array_data),
+ _ => unreachable!(),
+ };
+ self.write_buffer(&offsets, offset, compression_codec, write_options.alignment)?;
+ self.write_array_data(
+ &sliced_child_data,
+ offset,
+ sliced_child_data.len(),
+ sliced_child_data.null_count(),
write_options,
)?;
+ return Ok(());
+ }
+ _ => {
+ // This accommodates for even the `View` types (e.g. BinaryView and Utf8View):
+ // Slicing the views buffer is safe and easy,
+ // but pruning unneeded data buffers is much more nuanced since it's complicated
+ // to prove that no views reference the pruned buffers
+ //
+ // Current implementation just serialize the raw arrays as given and not try to optimize anything.
+ // If users wants to "compact" the arrays prior to sending them over IPC,
+ // they should consider the gc API suggested in #5513
+ for buffer in array_data.buffers() {
+ self.write_buffer(buffer, offset, compression_codec, write_options.alignment)?;
+ }
}
}
- _ => {
- // recursively write out nested structures
- for data_ref in array_data.child_data() {
- // write the nested data (e.g list data)
- offset = write_array_data(
+
+ let mut write_arr = |arr: &ArrayData| {
+ for data_ref in arr.child_data() {
+ self.write_array_data(
data_ref,
- buffers,
- arrow_data,
- nodes,
offset,
data_ref.len(),
data_ref.null_count(),
- compression_codec,
write_options,
)?;
}
+ Ok::<_, ArrowError>(())
+ };
+
+ match array_data.data_type() {
+ DataType::Dictionary(_, _) => Ok(()),
Review Comment:
This is something that I wasn't able to figure out about this encoding process - it seems we don't write the `child_data` for dictionaries into the encoded message, but that's where all the values of the dictionary are. Without this, we only have the keys written. Does anyone know why this is?
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #6690:
URL: https://github.com/apache/arrow-rs/pull/6690#discussion_r1834572196
##########
arrow-flight/src/encode.rs:
##########
@@ -327,6 +327,10 @@ impl FlightDataEncoder {
/// Encodes batch into one or more `FlightData` messages in self.queue
fn encode_batch(&mut self, batch: RecordBatch) -> Result<()> {
+ if batch.num_rows() == 0 {
Review Comment:
What is the purpose of this optimization?
I vaguely remember at least one usecase of encoding empty batches is send the schema information. With this change it seems empty batches can no longer be encoded
Unless there is a reason to prevent empty batches, I would suggest we remove this check here and instead callers of the encoder can decide to filter out empty batches if they want
##########
arrow-flight/src/encode.rs:
##########
@@ -1726,59 +1680,49 @@ mod tests {
/// Coverage for <https://github.com/apache/arrow-rs/issues/3478>
///
- /// Encodes the specified batch using several values of
- /// `max_flight_data_size` between 1K to 5K and ensures that the
- /// resulting size of the flight data stays within the limit
- /// + `allowed_overage`
- ///
- /// `allowed_overage` is how far off the actual data encoding is
- /// from the target limit that was set. It is an improvement when
- /// the allowed_overage decreses.
- ///
- /// Note this overhead will likely always be greater than zero to
- /// account for encoding overhead such as IPC headers and padding.
+ /// Encodes the specified batch using several values of `max_flight_data_size` between 1K to 5K
+ /// and ensures that the resulting size of the flight data stays within the limit, except for
+ /// in cases where only 1 row is sent - if only 1 row is sent, then we know that there was no
+ /// way to keep the data within the limit (since the minimum possible amount of data was sent),
+ /// so we allow it to go over.
///
- ///
- async fn verify_encoded_split(batch: RecordBatch, allowed_overage: usize) {
+ async fn verify_encoded_split_no_overage(batch: RecordBatch) {
let num_rows = batch.num_rows();
- // Track the overall required maximum overage
- let mut max_overage_seen = 0;
-
for max_flight_data_size in [1024, 2021, 5000] {
println!("Encoding {num_rows} with a maximum size of {max_flight_data_size}");
- let mut stream = FlightDataEncoderBuilder::new()
+ let stream = FlightDataEncoderBuilder::new()
.with_max_flight_data_size(max_flight_data_size)
// use 8-byte alignment - default alignment is 64 which produces bigger ipc data
.with_options(IpcWriteOptions::try_new(8, false, MetadataVersion::V5).unwrap())
.build(futures::stream::iter([Ok(batch.clone())]));
+ let mut stream = FlightDataDecoder::new(stream);
+
let mut i = 0;
while let Some(data) = stream.next().await.transpose().unwrap() {
- let actual_data_size = flight_data_size(&data);
+ let actual_data_size = flight_data_size(&data.inner);
let actual_overage = actual_data_size.saturating_sub(max_flight_data_size);
- assert!(
- actual_overage <= allowed_overage,
- "encoded data[{i}]: actual size {actual_data_size}, \
- actual_overage: {actual_overage} \
- allowed_overage: {allowed_overage}"
- );
+ let is_1_row =
+ matches!(data.payload, DecodedPayload::RecordBatch(rb) if rb.num_rows() == 1);
+
+ // If only 1 row was sent over via this recordBatch, there was no way to avoid
+ // going over the limit. There's currently no mechanism for splitting a single row
+ // of results over multiple messages, so we allow going over the limit if it's the
Review Comment:
this makes sense -- could you also put this caveat in the documentation for `max_encoding_message_size` ? (we can do it as a follow on PR too)
https://docs.rs/arrow-flight/latest/arrow_flight/flight_service_client/struct.FlightServiceClient.html#method.max_encoding_message_size
##########
arrow-flight/src/encode.rs:
##########
@@ -700,6 +682,9 @@ mod tests {
use super::*;
#[test]
+ // flight_data_from_arrow_batch is deprecated but does exactly what we need. Would probably be
Review Comment:
Why not continue to use `make_flight_data` (which seems like is exactly what this comment proposes -- a copy of `flight_data_from_arrow_batch`?
This change seems like it would only make the final removal of `flight_data_from_arrow_batch` harder (would have to re-create `make_flight_data`)
##########
arrow-flight/src/encode.rs:
##########
@@ -1485,93 +1481,62 @@ mod tests {
hydrate_dictionaries(&batch, batch.schema()).expect("failed to optimize");
}
- pub fn make_flight_data(
- batch: &RecordBatch,
- options: &IpcWriteOptions,
- ) -> (Vec<FlightData>, FlightData) {
- let data_gen = IpcDataGenerator::default();
- let mut dictionary_tracker = DictionaryTracker::new_with_preserve_dict_id(false, true);
-
- let (encoded_dictionaries, encoded_batch) = data_gen
- .encoded_batch(batch, &mut dictionary_tracker, options)
- .expect("DictionaryTracker configured above to not error on replacement");
-
- let flight_dictionaries = encoded_dictionaries.into_iter().map(Into::into).collect();
- let flight_batch = encoded_batch.into();
-
- (flight_dictionaries, flight_batch)
- }
+ #[tokio::test]
+ async fn test_split_batch_for_grpc_response() {
+ async fn get_decoded(schema: SchemaRef, encoded: Vec<EncodedData>) -> Vec<RecordBatch> {
+ FlightDataDecoder::new(futures::stream::iter(
+ std::iter::once(SchemaAsIpc::new(&schema, &IpcWriteOptions::default()).into())
+ .chain(encoded.into_iter().map(FlightData::from))
+ .map(Ok),
+ ))
+ .collect::<Vec<Result<_>>>()
+ .await
+ .into_iter()
+ .map(|r| r.unwrap())
+ .filter_map(|data| match data.payload {
+ DecodedPayload::RecordBatch(rb) => Some(rb),
+ _ => None,
+ })
+ .collect()
+ }
- #[test]
- fn test_split_batch_for_grpc_response() {
let max_flight_data_size = 1024;
+ let write_opts = IpcWriteOptions::default();
+ let mut dict_tracker = DictionaryTracker::new(false);
+ let gen = IpcDataGenerator {};
// no split
let c = UInt32Array::from(vec![1, 2, 3, 4, 5, 6]);
let batch = RecordBatch::try_from_iter(vec![("a", Arc::new(c) as ArrayRef)])
.expect("cannot create record batch");
- let split = split_batch_for_grpc_response(batch.clone(), max_flight_data_size);
+ let split = gen
+ .encoded_batch_with_size(&batch, &mut dict_tracker, &write_opts, max_flight_data_size)
+ .unwrap()
+ .1;
assert_eq!(split.len(), 1);
- assert_eq!(batch, split[0]);
+ assert_eq!(batch, get_decoded(batch.schema(), split).await[0]);
// split once
let n_rows = max_flight_data_size + 1;
assert!(n_rows % 2 == 1, "should be an odd number");
let c = UInt8Array::from((0..n_rows).map(|i| (i % 256) as u8).collect::<Vec<_>>());
let batch = RecordBatch::try_from_iter(vec![("a", Arc::new(c) as ArrayRef)])
.expect("cannot create record batch");
- let split = split_batch_for_grpc_response(batch.clone(), max_flight_data_size);
- assert_eq!(split.len(), 3);
+ let split = gen
+ .encoded_batch_with_size(&batch, &mut dict_tracker, &write_opts, max_flight_data_size)
+ .unwrap()
+ .1;
+ assert_eq!(split.len(), 2);
+ let batches = get_decoded(batch.schema(), split).await;
assert_eq!(
- split.iter().map(|batch| batch.num_rows()).sum::<usize>(),
+ batches.iter().map(RecordBatch::num_rows).sum::<usize>(),
n_rows
);
- let a = pretty_format_batches(&split).unwrap().to_string();
+ let a = pretty_format_batches(&batches).unwrap().to_string();
let b = pretty_format_batches(&[batch]).unwrap().to_string();
assert_eq!(a, b);
}
- #[test]
Review Comment:
Can you please explain why this test removed?
##########
arrow-integration-testing/src/flight_client_scenarios/integration_test.rs:
##########
@@ -125,16 +125,9 @@ async fn send_batch(
batch: &RecordBatch,
options: &writer::IpcWriteOptions,
) -> Result {
- let data_gen = writer::IpcDataGenerator::default();
- let mut dictionary_tracker = writer::DictionaryTracker::new_with_preserve_dict_id(false, true);
-
- let (encoded_dictionaries, encoded_batch) = data_gen
- .encoded_batch(batch, &mut dictionary_tracker, options)
- .expect("DictionaryTracker configured above to not error on replacement");
-
- let dictionary_flight_data: Vec<FlightData> =
- encoded_dictionaries.into_iter().map(Into::into).collect();
- let mut batch_flight_data: FlightData = encoded_batch.into();
+ #[allow(deprecated)]
Review Comment:
It seems unfortunate that we are reverting back to the deprecated method. Maybe we can figure out some non deprecated API 🤔
##########
arrow-flight/src/encode.rs:
##########
@@ -1679,9 +1637,7 @@ mod tests {
let batch = RecordBatch::try_from_iter(vec![("a1", Arc::new(array) as _)]).unwrap();
- // overage is much higher than ideal
- // https://github.com/apache/arrow-rs/issues/3478
Review Comment:
🎉
##########
arrow-buffer/src/buffer/immutable.rs:
##########
@@ -261,11 +261,11 @@ impl Buffer {
}
/// Returns a slice of this buffer starting at a certain bit offset.
- /// If the offset is byte-aligned the returned buffer is a shallow clone,
+ /// If the offset and length are byte-aligned the returned buffer is a shallow clone,
/// otherwise a new buffer is allocated and filled with a copy of the bits in the range.
pub fn bit_slice(&self, offset: usize, len: usize) -> Self {
- if offset % 8 == 0 {
- return self.slice(offset / 8);
+ if offset % 8 == 0 && len % 8 == 0 {
Review Comment:
It seems like it may fix a bug where the length is incorrectly set after slice if the offset is zero 👍
Can you please also add a unit tests showing this bug fix (aka a unit test in immutable.rs)
I verified that the tests in this PR fail after this change:
```
Encoding 1023 with a maximum size of 1024
test encode::tests::flight_data_size_string_dictionary ... FAILED
failures:
failures:
encode::tests::flight_data_size_string_dictionary
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 28 filtered out; finished in 0.00s
--- STDERR: arrow-flight encode::tests::flight_data_size_string_dictionary ---
thread 'encode::tests::flight_data_size_string_dictionary' panicked at arrow-flight/src/encode.rs:1717:21:
assertion `left == right` failed: encoded data[1]: actual size 1136, actual_overage: 112
left: 112
right: 0
```
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "itsjunetime (via GitHub)" <gi...@apache.org>.
itsjunetime commented on code in PR #6690:
URL: https://github.com/apache/arrow-rs/pull/6690#discussion_r1835162135
##########
arrow-buffer/src/buffer/immutable.rs:
##########
@@ -261,11 +261,11 @@ impl Buffer {
}
/// Returns a slice of this buffer starting at a certain bit offset.
- /// If the offset is byte-aligned the returned buffer is a shallow clone,
+ /// If the offset and length are byte-aligned the returned buffer is a shallow clone,
/// otherwise a new buffer is allocated and filled with a copy of the bits in the range.
pub fn bit_slice(&self, offset: usize, len: usize) -> Self {
- if offset % 8 == 0 {
- return self.slice(offset / 8);
+ if offset % 8 == 0 && len % 8 == 0 {
Review Comment:
I've moved this to #6707
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "itsjunetime (via GitHub)" <gi...@apache.org>.
itsjunetime commented on code in PR #6690:
URL: https://github.com/apache/arrow-rs/pull/6690#discussion_r1835081592
##########
arrow-buffer/src/buffer/immutable.rs:
##########
@@ -261,11 +261,11 @@ impl Buffer {
}
/// Returns a slice of this buffer starting at a certain bit offset.
- /// If the offset is byte-aligned the returned buffer is a shallow clone,
+ /// If the offset and length are byte-aligned the returned buffer is a shallow clone,
/// otherwise a new buffer is allocated and filled with a copy of the bits in the range.
pub fn bit_slice(&self, offset: usize, len: usize) -> Self {
- if offset % 8 == 0 {
- return self.slice(offset / 8);
+ if offset % 8 == 0 && len % 8 == 0 {
Review Comment:
Yes - I'll pull this out to a separate PR to make this easier to review and add a unit test there.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "itsjunetime (via GitHub)" <gi...@apache.org>.
itsjunetime commented on code in PR #6690:
URL: https://github.com/apache/arrow-rs/pull/6690#discussion_r1842622244
##########
arrow-ipc/src/writer.rs:
##########
@@ -448,15 +454,45 @@ impl IpcDataGenerator {
Ok(())
}
+ /// Calls [`Self::encoded_batch_with_size`] with no limit, returning the first (and only)
+ /// [`EncodedData`] that is produced. This method should be used over
+ /// [`Self::encoded_batch_with_size`] if the consumer has no concerns about encoded message
+ /// size limits
+ pub fn encoded_batch(
+ &self,
+ batch: &RecordBatch,
+ dictionary_tracker: &mut DictionaryTracker,
+ write_options: &IpcWriteOptions,
+ ) -> Result<(Vec<EncodedData>, EncodedData), ArrowError> {
+ let (encoded_dictionaries, mut encoded_messages) =
+ self.encoded_batch_with_size(batch, dictionary_tracker, write_options, usize::MAX)?;
+
+ assert_eq!(
+ encoded_messages.len(),
+ 1,
+ "encoded_batch with max size of usize::MAX should not be able to return more or less than 1 batch"
+ );
+
+ Ok((encoded_dictionaries, encoded_messages.pop().unwrap()))
+ }
+
/// Encodes a batch to a number of [EncodedData] items (dictionary batches + the record batch).
/// The [DictionaryTracker] keeps track of dictionaries with new `dict_id`s (so they are only sent once)
/// Make sure the [DictionaryTracker] is initialized at the start of the stream.
- pub fn encoded_batch(
+ /// The `max_flight_data_size` is used to control how much space each encoded [`RecordBatch`] is
Review Comment:
Done in 652aa2753204a7b25ffcdd324449791679edf0ad
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #6690:
URL: https://github.com/apache/arrow-rs/pull/6690#issuecomment-2479892853
> I had a brief skim, couple of comments
>
> Adding an IPC specific API to ArrayData seems a touch unfortunate. It's probably ok, but a little off.
>
> I'm not really sure of the context for this PR, but assuming it is to better avoid the gRPC limits, I worry this may be a fools errand. There is a lot beyond the data buffers going into those payloads (e.g. metadata flatbuffers, framing protobuf, HTTP framing, etc...) and trying to account for all of this is going to be a never ending game of wack a mole. Ultimately the only solution I can see is to set the soft limit in the encoder well below the hard limit enforced by the transport.
The context of this PR is that we have set the soft limit well below the hard limit (2MB vs 4MB) and somehow a customer still managed to hit the hard limit. So @itsjunetime is trying to improve the specificity of the size.
We (at least our team in Influx) don't directly control all layers involved in gRPC communication -- this limit is being enforced by one of the various programs / mixings installed in kubernetes to manage traffic, report on things, etc. While in theory we should be able to figure out which one and increase its limits, that will also likely be a never ending game of whack a mole.
Let me see if I can help to find a way to break this PR up into smaller, more manageable pieces, so that we can get this in / tested in a way that is reasonable to maintain
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Prevent FlightData overflowing max size limit whenever possible. [arrow-rs]
Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey closed pull request #6690: Prevent FlightData overflowing max size limit whenever possible.
URL: https://github.com/apache/arrow-rs/pull/6690
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org