@@ -21,7 +21,7 @@ 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 ,
24+ CatalogOp , SnapshotDetails , WalContents , WalFileNotifier , WalFileSequenceNumber ,
2525 WalOp , WriteBatch ,
2626} ;
2727use iox_query:: QueryChunk ;
@@ -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,11 @@ 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 ( Arc :: clone ( & catalog) , buffer_chunk_interval) ) ) ;
9392 let ( persisted_snapshot_notify_tx, persisted_snapshot_notify_rx) =
9493 tokio:: sync:: watch:: channel ( None ) ;
9594 Self {
@@ -103,8 +102,8 @@ impl QueryableBuffer {
103102 parquet_cache,
104103 persisted_snapshot_notify_rx,
105104 persisted_snapshot_notify_tx,
106- gen1_duration,
107105 max_size_per_parquet_file_bytes,
106+ buffer_chunk_interval,
108107 }
109108 }
110109
@@ -268,8 +267,8 @@ impl QueryableBuffer {
268267 let catalog = Arc :: clone ( & self . catalog ) ;
269268 let notify_snapshot_tx = self . persisted_snapshot_notify_tx . clone ( ) ;
270269 let parquet_cache = self . parquet_cache . clone ( ) ;
271- let gen1_duration = self . gen1_duration ;
272270 let max_size_per_parquet_file = self . max_size_per_parquet_file_bytes ;
271+ let chunk_interval = self . num_chunk_intervals_in_10m ( ) ;
273272
274273 tokio:: spawn ( async move {
275274 // persist the catalog if it has been updated
@@ -321,7 +320,7 @@ impl QueryableBuffer {
321320 Arc :: from ( persister. node_identifier_prefix ( ) ) ,
322321 wal_file_number,
323322 Arc :: clone ( & catalog) ,
324- gen1_duration . as_10m ( ) as usize ,
323+ chunk_interval ,
325324 Some ( max_size_per_parquet_file) ,
326325 ) ;
327326
@@ -351,7 +350,7 @@ impl QueryableBuffer {
351350 Arc :: from ( persister. node_identifier_prefix ( ) ) ,
352351 wal_file_number,
353352 Arc :: clone ( & catalog) ,
354- gen1_duration . as_10m ( ) as usize ,
353+ chunk_interval ,
355354 None ,
356355 ) ;
357356
@@ -453,6 +452,16 @@ impl QueryableBuffer {
453452 let buffer = self . buffer . read ( ) ;
454453 buffer. find_overall_buffer_size_bytes ( )
455454 }
455+
456+ fn num_chunk_intervals_in_10m ( & self ) -> usize {
457+ let ten_mins_secs = 600 ;
458+ let chunk_interval_secs = self . buffer_chunk_interval . as_secs ( ) ;
459+ if chunk_interval_secs >= ten_mins_secs {
460+ return 1 ;
461+ }
462+ let num_chunks_in_ten_mins = ten_mins_secs / self . buffer_chunk_interval . as_secs ( ) ;
463+ num_chunks_in_ten_mins as usize
464+ }
456465}
457466
458467async fn sort_dedupe_parallel < I : Iterator < Item = PersistJob > > (
@@ -619,15 +628,17 @@ impl WalFileNotifier for QueryableBuffer {
619628pub struct BufferState {
620629 pub db_to_table : HashMap < DbId , TableIdToBufferMap > ,
621630 catalog : Arc < Catalog > ,
631+ chunk_interval : Duration ,
622632}
623633
624634type TableIdToBufferMap = HashMap < TableId , TableBuffer > ;
625635
626636impl BufferState {
627- pub fn new ( catalog : Arc < Catalog > ) -> Self {
637+ pub fn new ( catalog : Arc < Catalog > , chunk_interval : Duration ) -> Self {
628638 Self {
629639 db_to_table : HashMap :: new ( ) ,
630640 catalog,
641+ chunk_interval,
631642 }
632643 }
633644
@@ -741,14 +752,14 @@ impl BufferState {
741752
742753 let database_buffer = self . db_to_table . entry ( write_batch. database_id ) . or_default ( ) ;
743754 // keep internal query buffer chunks divided by 1m
744- let one_min_ns = Duration :: from_secs ( 60 ) . as_nanos ( ) as i64 ;
755+ let one_min_ns = self . chunk_interval . as_nanos ( ) as i64 ;
745756
746757 for ( table_id, table_chunks) in & write_batch. table_chunks {
747758 let table_buffer = database_buffer. entry ( * table_id) . or_insert_with ( || {
748759 let table_def = db_schema
749760 . table_definition_by_id ( table_id)
750761 . expect ( "table should exist" ) ;
751- TableBuffer :: new ( table_def. sort_key ( ) )
762+ TableBuffer :: new ( table_def. sort_key ( ) , self . chunk_interval )
752763 } ) ;
753764
754765 let mut one_min_groups = HashMap :: new ( ) ;
@@ -1127,7 +1138,6 @@ mod tests {
11271138 . unwrap ( ) ,
11281139 persisted_files : Arc :: new ( PersistedFiles :: new ( ) ) ,
11291140 parquet_cache : None ,
1130- gen1_duration : Gen1Duration :: new_1m ( ) ,
11311141 max_size_per_parquet_file_bytes : 4_000 ,
11321142 } ;
11331143 let queryable_buffer = QueryableBuffer :: new ( queryable_buffer_args) ;
@@ -1281,7 +1291,6 @@ mod tests {
12811291 . unwrap ( ) ,
12821292 persisted_files : Arc :: new ( PersistedFiles :: new ( ) ) ,
12831293 parquet_cache : None ,
1284- gen1_duration : Gen1Duration :: new_1m ( ) ,
12851294 max_size_per_parquet_file_bytes : 50_000 ,
12861295 } ;
12871296 let queryable_buffer = QueryableBuffer :: new ( queryable_buffer_args) ;
@@ -1410,7 +1419,6 @@ mod tests {
14101419 . unwrap ( ) ,
14111420 persisted_files : Arc :: new ( PersistedFiles :: new ( ) ) ,
14121421 parquet_cache : None ,
1413- gen1_duration : Gen1Duration :: new_1m ( ) ,
14141422 max_size_per_parquet_file_bytes : 2_000 ,
14151423 } ;
14161424 let queryable_buffer = QueryableBuffer :: new ( queryable_buffer_args) ;
@@ -1544,7 +1552,6 @@ mod tests {
15441552 . unwrap ( ) ,
15451553 persisted_files : Arc :: new ( PersistedFiles :: new ( ) ) ,
15461554 parquet_cache : None ,
1547- gen1_duration : Gen1Duration :: new_1m ( ) ,
15481555 max_size_per_parquet_file_bytes : 150_000 ,
15491556 } ;
15501557 let queryable_buffer = QueryableBuffer :: new ( queryable_buffer_args) ;
0 commit comments