@@ -26,8 +26,7 @@ use tracing::{error, info, trace, warn};
2626
2727use crate :: alerts:: { alerts_utils, AlertConfig , AlertError } ;
2828use crate :: parseable:: PARSEABLE ;
29- use crate :: storage:: LOCAL_SYNC_INTERVAL ;
30- use crate :: { STORAGE_CONVERSION_INTERVAL , STORAGE_UPLOAD_INTERVAL } ;
29+ use crate :: { LOCAL_SYNC_INTERVAL , STORAGE_UPLOAD_INTERVAL } ;
3130
3231// Calculates the instant that is the start of the next minute
3332fn next_minute ( ) -> Instant {
@@ -76,27 +75,21 @@ where
7675/// `STORAGE_CONVERSION_INTERVAL` secondsand uploads them every `STORAGE_UPLOAD_INTERVAL` seconds.
7776#[ tokio:: main( flavor = "current_thread" ) ]
7877pub async fn handler ( mut cancel_rx : oneshot:: Receiver < ( ) > ) -> anyhow:: Result < ( ) > {
79- let ( localsync_handler, mut localsync_outbox, localsync_inbox) = run_local_sync ( ) ;
78+ let ( localsync_handler, mut localsync_outbox, localsync_inbox) = local_sync ( ) ;
8079 let ( mut remote_sync_handler, mut remote_sync_outbox, mut remote_sync_inbox) =
8180 object_store_sync ( ) ;
82- let ( mut remote_conversion_handler, mut remote_conversion_outbox, mut remote_conversion_inbox) =
83- arrow_conversion ( ) ;
8481 loop {
8582 select ! {
8683 _ = & mut cancel_rx => {
8784 // actix server finished .. stop other threads and stop the server
8885 remote_sync_inbox. send( ( ) ) . unwrap_or( ( ) ) ;
8986 localsync_inbox. send( ( ) ) . unwrap_or( ( ) ) ;
90- remote_conversion_inbox. send( ( ) ) . unwrap_or( ( ) ) ;
9187 if let Err ( e) = localsync_handler. await {
9288 error!( "Error joining remote_sync_handler: {:?}" , e) ;
9389 }
9490 if let Err ( e) = remote_sync_handler. await {
9591 error!( "Error joining remote_sync_handler: {:?}" , e) ;
9692 }
97- if let Err ( e) = remote_conversion_handler. await {
98- error!( "Error joining remote_conversion_handler: {:?}" , e) ;
99- }
10093 return Ok ( ( ) ) ;
10194 } ,
10295 _ = & mut localsync_outbox => {
@@ -111,13 +104,6 @@ pub async fn handler(mut cancel_rx: oneshot::Receiver<()>) -> anyhow::Result<()>
111104 }
112105 ( remote_sync_handler, remote_sync_outbox, remote_sync_inbox) = object_store_sync( ) ;
113106 } ,
114- _ = & mut remote_conversion_outbox => {
115- // remote_conversion failed, this is recoverable by just starting remote_conversion thread again
116- if let Err ( e) = remote_conversion_handler. await {
117- error!( "Error joining remote_conversion_handler: {:?}" , e) ;
118- }
119- ( remote_conversion_handler, remote_conversion_outbox, remote_conversion_inbox) = arrow_conversion( ) ;
120- } ,
121107 }
122108 }
123109}
@@ -132,8 +118,7 @@ pub fn object_store_sync() -> (
132118
133119 let handle = task:: spawn ( async move {
134120 let result = std:: panic:: catch_unwind ( AssertUnwindSafe ( || async move {
135- let mut sync_interval =
136- interval_at ( next_minute ( ) , Duration :: from_secs ( STORAGE_UPLOAD_INTERVAL ) ) ;
121+ let mut sync_interval = interval_at ( next_minute ( ) , STORAGE_UPLOAD_INTERVAL ) ;
137122
138123 let mut inbox_rx = AssertUnwindSafe ( inbox_rx) ;
139124
@@ -183,7 +168,8 @@ pub fn object_store_sync() -> (
183168 ( handle, outbox_rx, inbox_tx)
184169}
185170
186- pub fn arrow_conversion ( ) -> (
171+ /// Flush arrows onto disk and convert them into parquet files
172+ pub fn local_sync ( ) -> (
187173 task:: JoinHandle < ( ) > ,
188174 oneshot:: Receiver < ( ) > ,
189175 oneshot:: Sender < ( ) > ,
@@ -192,17 +178,18 @@ pub fn arrow_conversion() -> (
192178 let ( inbox_tx, inbox_rx) = oneshot:: channel :: < ( ) > ( ) ;
193179
194180 let handle = task:: spawn ( async move {
195- let result = std:: panic:: catch_unwind ( AssertUnwindSafe ( || async move {
196- let mut sync_interval = interval_at (
197- next_minute ( ) + Duration :: from_secs ( 5 ) , // 5 second delay
198- Duration :: from_secs ( STORAGE_CONVERSION_INTERVAL ) ,
199- ) ;
181+ info ! ( "Local sync task started" ) ;
182+ let mut inbox_rx = inbox_rx;
200183
201- let mut inbox_rx = AssertUnwindSafe ( inbox_rx) ;
184+ let result = std:: panic:: catch_unwind ( AssertUnwindSafe ( || async move {
185+ let mut sync_interval = interval_at ( next_minute ( ) , LOCAL_SYNC_INTERVAL ) ;
202186
203187 loop {
204188 select ! {
205189 _ = sync_interval. tick( ) => {
190+ trace!( "Flushing Arrows to disk..." ) ;
191+ PARSEABLE . flush_all_streams( ) ;
192+
206193 trace!( "Converting Arrow to Parquet... " ) ;
207194 if let Err ( e) = monitor_task_duration(
208195 "arrow_conversion" ,
@@ -224,55 +211,6 @@ pub fn arrow_conversion() -> (
224211 }
225212 } ) ) ;
226213
227- match result {
228- Ok ( future) => {
229- future. await ;
230- }
231- Err ( panic_error) => {
232- error ! ( "Panic in object store sync task: {panic_error:?}" ) ;
233- let _ = outbox_tx. send ( ( ) ) ;
234- }
235- }
236-
237- info ! ( "Object store sync task ended" ) ;
238- } ) ;
239-
240- ( handle, outbox_rx, inbox_tx)
241- }
242-
243- pub fn run_local_sync ( ) -> (
244- task:: JoinHandle < ( ) > ,
245- oneshot:: Receiver < ( ) > ,
246- oneshot:: Sender < ( ) > ,
247- ) {
248- let ( outbox_tx, outbox_rx) = oneshot:: channel :: < ( ) > ( ) ;
249- let ( inbox_tx, inbox_rx) = oneshot:: channel :: < ( ) > ( ) ;
250-
251- let handle = task:: spawn ( async move {
252- info ! ( "Local sync task started" ) ;
253- let mut inbox_rx = inbox_rx;
254-
255- let result = std:: panic:: catch_unwind ( AssertUnwindSafe ( || async move {
256- let mut sync_interval =
257- interval_at ( next_minute ( ) , Duration :: from_secs ( LOCAL_SYNC_INTERVAL ) ) ;
258-
259- loop {
260- select ! {
261- _ = sync_interval. tick( ) => {
262- trace!( "Flushing Arrows to disk..." ) ;
263- PARSEABLE . flush_all_streams( ) ;
264- } ,
265- res = & mut inbox_rx => { match res{
266- Ok ( _) => break ,
267- Err ( _) => {
268- warn!( "Inbox channel closed unexpectedly" ) ;
269- break ;
270- } }
271- }
272- }
273- }
274- } ) ) ;
275-
276214 match result {
277215 Ok ( future) => {
278216 future. await ;
0 commit comments