@@ -29,7 +29,7 @@ use std::{
2929
3030use arrow_array:: RecordBatch ;
3131use arrow_schema:: { Field , Fields , Schema } ;
32- use chrono:: { NaiveDateTime , Timelike } ;
32+ use chrono:: { NaiveDateTime , Timelike , Utc } ;
3333use derive_more:: { Deref , DerefMut } ;
3434use itertools:: Itertools ;
3535use parquet:: {
@@ -51,7 +51,7 @@ use crate::{
5151 metrics,
5252 option:: Mode ,
5353 storage:: { object_storage:: to_bytes, retention:: Retention , StreamType } ,
54- utils:: time:: Minute ,
54+ utils:: time:: { Minute , TimeRange } ,
5555 LOCK_EXPECT , OBJECT_STORE_DATA_GRANULARITY ,
5656} ;
5757
@@ -132,7 +132,11 @@ impl Stream {
132132 ) ;
133133 std:: fs:: create_dir_all ( & self . data_path ) ?;
134134
135- let mut writer = DiskWriter :: try_new ( file_path, & record. schema ( ) )
135+ let range = TimeRange :: granularity_range (
136+ parsed_timestamp. and_local_timezone ( Utc ) . unwrap ( ) ,
137+ OBJECT_STORE_DATA_GRANULARITY ,
138+ ) ;
139+ let mut writer = DiskWriter :: try_new ( file_path, & record. schema ( ) , range)
136140 . expect ( "File and RecordBatch both are checked" ) ;
137141
138142 writer. write ( record) ?;
@@ -357,12 +361,12 @@ impl Stream {
357361 self . writer . lock ( ) . unwrap ( ) . mem . clear ( ) ;
358362 }
359363
360- pub fn flush ( & self ) {
364+ pub fn flush ( & self , forced : bool ) {
361365 let mut writer = self . writer . lock ( ) . unwrap ( ) ;
362366 // Flush memory
363367 writer. mem . clear ( ) ;
364368 // Drop schema -> disk writer mapping, triggers flush to disk
365- writer. disk . drain ( ) ;
369+ writer. disk . retain ( |_ , w| !forced && w . is_current ( ) ) ;
366370 }
367371
368372 fn parquet_writer_props (
@@ -662,7 +666,7 @@ impl Stream {
662666
663667 /// First flushes arrows onto disk and then converts the arrow into parquet
664668 pub fn flush_and_convert ( & self , shutdown_signal : bool ) -> Result < ( ) , StagingError > {
665- self . flush ( ) ;
669+ self . flush ( shutdown_signal ) ;
666670
667671 self . prepare_parquet ( shutdown_signal)
668672 }
@@ -974,7 +978,7 @@ mod tests {
974978 StreamType :: UserDefined ,
975979 )
976980 . unwrap ( ) ;
977- staging. flush ( ) ;
981+ staging. flush ( true ) ;
978982 }
979983
980984 #[ test]
0 commit comments