@@ -41,6 +41,7 @@ use parquet::{
4141} ;
4242use rand:: distributions:: DistString ;
4343use relative_path:: RelativePathBuf ;
44+ use tokio:: task:: JoinSet ;
4445use tracing:: { error, info, trace, warn} ;
4546
4647use crate :: {
@@ -651,6 +652,13 @@ impl Stream {
651652 pub fn get_stream_type ( & self ) -> StreamType {
652653 self . metadata . read ( ) . expect ( LOCK_EXPECT ) . stream_type
653654 }
655+
656+ /// First flushes arrows onto disk and then converts the arrow into parquet
657+ pub fn flush_and_convert ( & self , shutdown_signal : bool ) -> Result < ( ) , StagingError > {
658+ self . flush ( ) ;
659+
660+ self . prepare_parquet ( shutdown_signal)
661+ }
654662}
655663
656664#[ derive( Deref , DerefMut , Default ) ]
@@ -717,21 +725,22 @@ impl Streams {
717725 . collect ( )
718726 }
719727
720- /// Convert arrow files into parquet, preparing it for upload
721- pub fn prepare_parquet ( & self , shutdown_signal : bool ) -> Result < ( ) , StagingError > {
728+ /// Asynchronously flushes arrows and compacts into parquet data on all streams in staging,
729+ /// so that it is ready to be pushed onto objectstore.
730+ pub fn flush_and_convert (
731+ & self ,
732+ joinset : & mut JoinSet < Result < ( ) , StagingError > > ,
733+ shutdown_signal : bool ,
734+ ) {
722735 let streams: Vec < Arc < Stream > > = self
723736 . read ( )
724737 . expect ( LOCK_EXPECT )
725738 . values ( )
726739 . map ( Arc :: clone)
727740 . collect ( ) ;
728741 for stream in streams {
729- stream
730- . prepare_parquet ( shutdown_signal)
731- . inspect_err ( |err| error ! ( "Failed to run conversion task {err:?}" ) ) ?;
742+ joinset. spawn ( async move { stream. flush_and_convert ( shutdown_signal) } ) ;
732743 }
733-
734- Ok ( ( ) )
735744 }
736745}
737746
0 commit comments