@@ -21,8 +21,8 @@ use influxdb3_cache::{distinct_cache::DistinctCacheProvider, last_cache::LastCac
2121use influxdb3_catalog:: catalog:: { Catalog , DatabaseSchema , TableDefinition } ;
2222use influxdb3_id:: { DbId , TableId } ;
2323use influxdb3_wal:: {
24- CatalogOp , Gen1Duration , SnapshotDetails , WalContents , WalFileNotifier , WalFileSequenceNumber ,
25- WalOp , WriteBatch ,
24+ CatalogOp , SnapshotDetails , WalContents , WalFileNotifier , WalFileSequenceNumber , WalOp ,
25+ WriteBatch ,
2626} ;
2727use iox_query:: QueryChunk ;
2828use iox_query:: chunk_statistics:: { NoColumnRanges , create_chunk_statistics} ;
@@ -58,7 +58,7 @@ pub struct QueryableBuffer {
5858 /// Sends a notification to this watch channel whenever a snapshot info is persisted
5959 persisted_snapshot_notify_rx : tokio:: sync:: watch:: Receiver < Option < PersistedSnapshot > > ,
6060 persisted_snapshot_notify_tx : tokio:: sync:: watch:: Sender < Option < PersistedSnapshot > > ,
61- gen1_duration : Gen1Duration ,
61+ buffer_chunk_interval : Duration ,
6262 max_size_per_parquet_file_bytes : u64 ,
6363}
6464
@@ -71,7 +71,6 @@ pub struct QueryableBufferArgs {
7171 pub distinct_cache_provider : Arc < DistinctCacheProvider > ,
7272 pub persisted_files : Arc < PersistedFiles > ,
7373 pub parquet_cache : Option < Arc < dyn ParquetCacheOracle > > ,
74- pub gen1_duration : Gen1Duration ,
7574 pub max_size_per_parquet_file_bytes : u64 ,
7675}
7776
@@ -85,11 +84,14 @@ impl QueryableBuffer {
8584 distinct_cache_provider,
8685 persisted_files,
8786 parquet_cache,
88- gen1_duration,
8987 max_size_per_parquet_file_bytes,
9088 } : QueryableBufferArgs ,
9189 ) -> Self {
92- let buffer = Arc :: new ( RwLock :: new ( BufferState :: new ( Arc :: clone ( & catalog) ) ) ) ;
90+ let buffer_chunk_interval = Duration :: from_secs ( 60 ) ;
91+ let buffer = Arc :: new ( RwLock :: new ( BufferState :: new (
92+ Arc :: clone ( & catalog) ,
93+ buffer_chunk_interval,
94+ ) ) ) ;
9395 let ( persisted_snapshot_notify_tx, persisted_snapshot_notify_rx) =
9496 tokio:: sync:: watch:: channel ( None ) ;
9597 Self {
@@ -103,8 +105,8 @@ impl QueryableBuffer {
103105 parquet_cache,
104106 persisted_snapshot_notify_rx,
105107 persisted_snapshot_notify_tx,
106- gen1_duration,
107108 max_size_per_parquet_file_bytes,
109+ buffer_chunk_interval,
108110 }
109111 }
110112
@@ -268,8 +270,8 @@ impl QueryableBuffer {
268270 let catalog = Arc :: clone ( & self . catalog ) ;
269271 let notify_snapshot_tx = self . persisted_snapshot_notify_tx . clone ( ) ;
270272 let parquet_cache = self . parquet_cache . clone ( ) ;
271- let gen1_duration = self . gen1_duration ;
272273 let max_size_per_parquet_file = self . max_size_per_parquet_file_bytes ;
274+ let chunk_interval = self . num_chunk_intervals_in_10m ( ) ;
273275
274276 tokio:: spawn ( async move {
275277 // persist the catalog if it has been updated
@@ -321,7 +323,7 @@ impl QueryableBuffer {
321323 Arc :: from ( persister. node_identifier_prefix ( ) ) ,
322324 wal_file_number,
323325 Arc :: clone ( & catalog) ,
324- gen1_duration . as_10m ( ) as usize ,
326+ chunk_interval ,
325327 Some ( max_size_per_parquet_file) ,
326328 ) ;
327329
@@ -351,7 +353,7 @@ impl QueryableBuffer {
351353 Arc :: from ( persister. node_identifier_prefix ( ) ) ,
352354 wal_file_number,
353355 Arc :: clone ( & catalog) ,
354- gen1_duration . as_10m ( ) as usize ,
356+ chunk_interval ,
355357 None ,
356358 ) ;
357359
@@ -453,6 +455,16 @@ impl QueryableBuffer {
453455 let buffer = self . buffer . read ( ) ;
454456 buffer. find_overall_buffer_size_bytes ( )
455457 }
458+
459+ fn num_chunk_intervals_in_10m ( & self ) -> usize {
460+ let ten_mins_secs = 600 ;
461+ let chunk_interval_secs = self . buffer_chunk_interval . as_secs ( ) ;
462+ if chunk_interval_secs >= ten_mins_secs {
463+ return 1 ;
464+ }
465+ let num_chunks_in_ten_mins = ten_mins_secs / self . buffer_chunk_interval . as_secs ( ) ;
466+ num_chunks_in_ten_mins as usize
467+ }
456468}
457469
458470async fn sort_dedupe_parallel < I : Iterator < Item = PersistJob > > (
@@ -619,15 +631,17 @@ impl WalFileNotifier for QueryableBuffer {
619631pub struct BufferState {
620632 pub db_to_table : HashMap < DbId , TableIdToBufferMap > ,
621633 catalog : Arc < Catalog > ,
634+ chunk_interval : Duration ,
622635}
623636
624637type TableIdToBufferMap = HashMap < TableId , TableBuffer > ;
625638
626639impl BufferState {
627- pub fn new ( catalog : Arc < Catalog > ) -> Self {
640+ pub fn new ( catalog : Arc < Catalog > , chunk_interval : Duration ) -> Self {
628641 Self {
629642 db_to_table : HashMap :: new ( ) ,
630643 catalog,
644+ chunk_interval,
631645 }
632646 }
633647
@@ -741,14 +755,14 @@ impl BufferState {
741755
742756 let database_buffer = self . db_to_table . entry ( write_batch. database_id ) . or_default ( ) ;
743757 // keep internal query buffer chunks divided by 1m
744- let one_min_ns = Duration :: from_secs ( 60 ) . as_nanos ( ) as i64 ;
758+ let one_min_ns = self . chunk_interval . as_nanos ( ) as i64 ;
745759
746760 for ( table_id, table_chunks) in & write_batch. table_chunks {
747761 let table_buffer = database_buffer. entry ( * table_id) . or_insert_with ( || {
748762 let table_def = db_schema
749763 . table_definition_by_id ( table_id)
750764 . expect ( "table should exist" ) ;
751- TableBuffer :: new ( table_def. sort_key ( ) )
765+ TableBuffer :: new ( table_def. sort_key ( ) , self . chunk_interval )
752766 } ) ;
753767
754768 let mut one_min_groups = HashMap :: new ( ) ;
@@ -1127,7 +1141,6 @@ mod tests {
11271141 . unwrap ( ) ,
11281142 persisted_files : Arc :: new ( PersistedFiles :: new ( ) ) ,
11291143 parquet_cache : None ,
1130- gen1_duration : Gen1Duration :: new_1m ( ) ,
11311144 max_size_per_parquet_file_bytes : 4_000 ,
11321145 } ;
11331146 let queryable_buffer = QueryableBuffer :: new ( queryable_buffer_args) ;
@@ -1281,7 +1294,6 @@ mod tests {
12811294 . unwrap ( ) ,
12821295 persisted_files : Arc :: new ( PersistedFiles :: new ( ) ) ,
12831296 parquet_cache : None ,
1284- gen1_duration : Gen1Duration :: new_1m ( ) ,
12851297 max_size_per_parquet_file_bytes : 50_000 ,
12861298 } ;
12871299 let queryable_buffer = QueryableBuffer :: new ( queryable_buffer_args) ;
@@ -1410,7 +1422,6 @@ mod tests {
14101422 . unwrap ( ) ,
14111423 persisted_files : Arc :: new ( PersistedFiles :: new ( ) ) ,
14121424 parquet_cache : None ,
1413- gen1_duration : Gen1Duration :: new_1m ( ) ,
14141425 max_size_per_parquet_file_bytes : 2_000 ,
14151426 } ;
14161427 let queryable_buffer = QueryableBuffer :: new ( queryable_buffer_args) ;
@@ -1544,7 +1555,6 @@ mod tests {
15441555 . unwrap ( ) ,
15451556 persisted_files : Arc :: new ( PersistedFiles :: new ( ) ) ,
15461557 parquet_cache : None ,
1547- gen1_duration : Gen1Duration :: new_1m ( ) ,
15481558 max_size_per_parquet_file_bytes : 150_000 ,
15491559 } ;
15501560 let queryable_buffer = QueryableBuffer :: new ( queryable_buffer_args) ;
0 commit comments