@@ -2,7 +2,7 @@ use crate::common::ttl_map::{TTLMap, TTLMapConfig};
22use crate :: flight_service:: DistributedSessionBuilder ;
33use crate :: flight_service:: do_get:: TaskData ;
44use crate :: protobuf:: StageKey ;
5- use arrow_flight:: flight_service_server:: FlightService ;
5+ use arrow_flight:: flight_service_server:: { FlightService , FlightServiceServer } ;
66use arrow_flight:: {
77 Action , ActionType , Criteria , Empty , FlightData , FlightDescriptor , FlightInfo ,
88 HandshakeRequest , HandshakeResponse , PollInfo , PutResult , SchemaResult , Ticket ,
@@ -28,6 +28,7 @@ pub struct ArrowFlightEndpoint {
2828 pub ( super ) task_data_entries : Arc < TTLMap < StageKey , Arc < OnceCell < TaskData > > > > ,
2929 pub ( super ) session_builder : Arc < dyn DistributedSessionBuilder + Send + Sync > ,
3030 pub ( super ) hooks : ArrowFlightEndpointHooks ,
31+ pub ( super ) max_message_size : Option < usize > ,
3132}
3233
3334impl ArrowFlightEndpoint {
@@ -40,6 +41,7 @@ impl ArrowFlightEndpoint {
4041 task_data_entries : Arc :: new ( ttl_map) ,
4142 session_builder : Arc :: new ( session_builder) ,
4243 hooks : ArrowFlightEndpointHooks :: default ( ) ,
44+ max_message_size : Some ( usize:: MAX ) ,
4345 } )
4446 }
4547
@@ -54,6 +56,44 @@ impl ArrowFlightEndpoint {
5456 ) {
5557 self . hooks . on_plan . push ( Arc :: new ( hook) ) ;
5658 }
59+
60+ /// Set the maximum message size for FlightData chunks.
61+ ///
62+ /// Defaults to `usize::MAX` to minimize chunking overhead for internal communication.
63+ /// See [`FlightDataEncoderBuilder::with_max_flight_data_size`] for details.
64+ ///
65+ /// If you change this to a lower value, ensure you configure the server's
66+ /// max_encoding_message_size and max_decoding_message_size to at least 2x this value
67+ /// to allow for overhead. For most use cases, the default of `usize::MAX` is appropriate.
68+ ///
69+ /// [`FlightDataEncoderBuilder::with_max_flight_data_size`]: https://arrow.apache.org/rust/arrow_flight/encode/struct.FlightDataEncoderBuilder.html#structfield.max_flight_data_size
70+ pub fn with_max_message_size ( mut self , size : usize ) -> Self {
71+ self . max_message_size = Some ( size) ;
72+ self
73+ }
74+
75+ /// Converts this endpoint into a [`FlightServiceServer`] with high default message size limits.
76+ ///
77+ /// This is a convenience method that wraps the endpoint in a [`FlightServiceServer`] and
78+ /// configures it with `max_decoding_message_size(usize::MAX)` and
79+ /// `max_encoding_message_size(usize::MAX)` to avoid message size limitations for internal
80+ /// communication.
81+ ///
82+ /// You can further customize the returned server by chaining additional tonic methods.
83+ ///
84+ /// # Example
85+ ///
86+ /// ```rust,ignore
87+ /// let endpoint = ArrowFlightEndpoint::try_new(session_builder)?;
88+ /// let server = endpoint.into_flight_server();
89+ /// // Can chain additional tonic methods if needed
90+ /// // let server = server.some_other_tonic_method(...);
91+ /// ```
92+ pub fn into_flight_server ( self ) -> FlightServiceServer < Self > {
93+ FlightServiceServer :: new ( self )
94+ . max_decoding_message_size ( usize:: MAX )
95+ . max_encoding_message_size ( usize:: MAX )
96+ }
5797}
5898
5999#[ async_trait]
0 commit comments