@@ -26,8 +26,7 @@ use tracing::{error, info, trace, warn};
26
26
27
27
use crate :: alerts:: { alerts_utils, AlertConfig , AlertError } ;
28
28
use 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 } ;
31
30
32
31
// Calculates the instant that is the start of the next minute
33
32
fn next_minute ( ) -> Instant {
@@ -76,27 +75,21 @@ where
76
75
/// `STORAGE_CONVERSION_INTERVAL` secondsand uploads them every `STORAGE_UPLOAD_INTERVAL` seconds.
77
76
#[ tokio:: main( flavor = "current_thread" ) ]
78
77
pub 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 ( ) ;
80
79
let ( mut remote_sync_handler, mut remote_sync_outbox, mut remote_sync_inbox) =
81
80
object_store_sync ( ) ;
82
- let ( mut remote_conversion_handler, mut remote_conversion_outbox, mut remote_conversion_inbox) =
83
- arrow_conversion ( ) ;
84
81
loop {
85
82
select ! {
86
83
_ = & mut cancel_rx => {
87
84
// actix server finished .. stop other threads and stop the server
88
85
remote_sync_inbox. send( ( ) ) . unwrap_or( ( ) ) ;
89
86
localsync_inbox. send( ( ) ) . unwrap_or( ( ) ) ;
90
- remote_conversion_inbox. send( ( ) ) . unwrap_or( ( ) ) ;
91
87
if let Err ( e) = localsync_handler. await {
92
88
error!( "Error joining remote_sync_handler: {:?}" , e) ;
93
89
}
94
90
if let Err ( e) = remote_sync_handler. await {
95
91
error!( "Error joining remote_sync_handler: {:?}" , e) ;
96
92
}
97
- if let Err ( e) = remote_conversion_handler. await {
98
- error!( "Error joining remote_conversion_handler: {:?}" , e) ;
99
- }
100
93
return Ok ( ( ) ) ;
101
94
} ,
102
95
_ = & mut localsync_outbox => {
@@ -111,13 +104,6 @@ pub async fn handler(mut cancel_rx: oneshot::Receiver<()>) -> anyhow::Result<()>
111
104
}
112
105
( remote_sync_handler, remote_sync_outbox, remote_sync_inbox) = object_store_sync( ) ;
113
106
} ,
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
- } ,
121
107
}
122
108
}
123
109
}
@@ -132,8 +118,7 @@ pub fn object_store_sync() -> (
132
118
133
119
let handle = task:: spawn ( async move {
134
120
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 ) ;
137
122
138
123
let mut inbox_rx = AssertUnwindSafe ( inbox_rx) ;
139
124
@@ -183,7 +168,8 @@ pub fn object_store_sync() -> (
183
168
( handle, outbox_rx, inbox_tx)
184
169
}
185
170
186
- pub fn arrow_conversion ( ) -> (
171
+ /// Flush arrows onto disk and convert them into parquet files
172
+ pub fn local_sync ( ) -> (
187
173
task:: JoinHandle < ( ) > ,
188
174
oneshot:: Receiver < ( ) > ,
189
175
oneshot:: Sender < ( ) > ,
@@ -192,17 +178,18 @@ pub fn arrow_conversion() -> (
192
178
let ( inbox_tx, inbox_rx) = oneshot:: channel :: < ( ) > ( ) ;
193
179
194
180
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;
200
183
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 ) ;
202
186
203
187
loop {
204
188
select ! {
205
189
_ = sync_interval. tick( ) => {
190
+ trace!( "Flushing Arrows to disk..." ) ;
191
+ PARSEABLE . flush_all_streams( ) ;
192
+
206
193
trace!( "Converting Arrow to Parquet... " ) ;
207
194
if let Err ( e) = monitor_task_duration(
208
195
"arrow_conversion" ,
@@ -224,55 +211,6 @@ pub fn arrow_conversion() -> (
224
211
}
225
212
} ) ) ;
226
213
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
-
276
214
match result {
277
215
Ok ( future) => {
278
216
future. await ;
0 commit comments