@@ -84,7 +84,6 @@ pub async fn handler(mut cancel_rx: oneshot::Receiver<()>) -> anyhow::Result<()>
84
84
loop {
85
85
select ! {
86
86
_ = & mut cancel_rx => {
87
- // actix server finished .. stop other threads and stop the server
88
87
remote_sync_inbox. send( ( ) ) . unwrap_or( ( ) ) ;
89
88
localsync_inbox. send( ( ) ) . unwrap_or( ( ) ) ;
90
89
if let Err ( e) = localsync_handler. await {
@@ -96,12 +95,9 @@ pub async fn handler(mut cancel_rx: oneshot::Receiver<()>) -> anyhow::Result<()>
96
95
return Ok ( ( ) ) ;
97
96
} ,
98
97
_ = & mut localsync_outbox => {
99
- // crash the server if localsync fails for any reason
100
- // panic!("Local Sync thread died. Server will fail now!")
101
98
return Err ( anyhow:: Error :: msg( "Failed to sync local data to drive. Please restart the Parseable server.\n \n Join us on Parseable Slack if the issue persists after restart : https://launchpass.com/parseable" ) )
102
99
} ,
103
100
_ = & mut remote_sync_outbox => {
104
- // remote_sync failed, this is recoverable by just starting remote_sync thread again
105
101
if let Err ( e) = remote_sync_handler. await {
106
102
error!( "Error joining remote_sync_handler: {e:?}" ) ;
107
103
}
@@ -125,16 +121,26 @@ pub fn object_store_sync() -> (
125
121
126
122
let result = std:: panic:: catch_unwind ( AssertUnwindSafe ( || async move {
127
123
let mut sync_interval = interval_at ( next_minute ( ) , STORAGE_UPLOAD_INTERVAL ) ;
128
- let mut joinset = JoinSet :: new ( ) ;
129
124
130
125
loop {
131
126
select ! {
132
127
_ = sync_interval. tick( ) => {
133
128
trace!( "Syncing Parquets to Object Store... " ) ;
134
- sync_all_streams( & mut joinset)
135
- } ,
136
- Some ( res) = joinset. join_next( ) , if !joinset. is_empty( ) => {
137
- log_join_result( res, "object store sync" ) ;
129
+
130
+ // Monitor the duration of sync_all_streams execution
131
+ monitor_task_duration(
132
+ "object_store_sync_all_streams" ,
133
+ Duration :: from_secs( 15 ) ,
134
+ || async {
135
+ let mut joinset = JoinSet :: new( ) ;
136
+ sync_all_streams( & mut joinset) ;
137
+
138
+ // Wait for all spawned tasks to complete
139
+ while let Some ( res) = joinset. join_next( ) . await {
140
+ log_join_result( res, "object store sync" ) ;
141
+ }
142
+ }
143
+ ) . await ;
138
144
} ,
139
145
res = & mut inbox_rx => {
140
146
match res {
@@ -147,10 +153,6 @@ pub fn object_store_sync() -> (
147
153
}
148
154
}
149
155
}
150
- // Drain remaining joinset tasks
151
- while let Some ( res) = joinset. join_next ( ) . await {
152
- log_join_result ( res, "object store sync" ) ;
153
- }
154
156
} ) ) ;
155
157
156
158
match result {
@@ -184,32 +186,37 @@ pub fn local_sync() -> (
184
186
185
187
let result = std:: panic:: catch_unwind ( AssertUnwindSafe ( || async move {
186
188
let mut sync_interval = interval_at ( next_minute ( ) , LOCAL_SYNC_INTERVAL ) ;
187
- let mut joinset = JoinSet :: new ( ) ;
188
189
189
190
loop {
190
191
select ! {
191
192
// Spawns a flush+conversion task every `LOCAL_SYNC_INTERVAL` seconds
192
193
_ = sync_interval. tick( ) => {
193
- PARSEABLE . streams. flush_and_convert( & mut joinset, false , false )
194
+ // Monitor the duration of flush_and_convert execution
195
+ monitor_task_duration(
196
+ "local_sync_flush_and_convert" ,
197
+ Duration :: from_secs( 15 ) ,
198
+ || async {
199
+ let mut joinset = JoinSet :: new( ) ;
200
+ PARSEABLE . streams. flush_and_convert( & mut joinset, false , false ) ;
201
+
202
+ // Wait for all spawned tasks to complete
203
+ while let Some ( res) = joinset. join_next( ) . await {
204
+ log_join_result( res, "flush and convert" ) ;
205
+ }
206
+ }
207
+ ) . await ;
194
208
} ,
195
- // Joins and logs errors in spawned tasks
196
- Some ( res) = joinset. join_next( ) , if !joinset. is_empty( ) => {
197
- log_join_result( res, "flush and convert" ) ;
198
- }
199
- res = & mut inbox_rx => { match res{
200
- Ok ( _) => break ,
201
- Err ( _) => {
202
- warn!( "Inbox channel closed unexpectedly" ) ;
203
- break ;
204
- } }
209
+ res = & mut inbox_rx => {
210
+ match res {
211
+ Ok ( _) => break ,
212
+ Err ( _) => {
213
+ warn!( "Inbox channel closed unexpectedly" ) ;
214
+ break ;
215
+ }
216
+ }
205
217
}
206
218
}
207
219
}
208
-
209
- // Drain remaining joinset tasks
210
- while let Some ( res) = joinset. join_next ( ) . await {
211
- log_join_result ( res, "flush and convert" ) ;
212
- }
213
220
} ) ) ;
214
221
215
222
match result {
@@ -228,21 +235,34 @@ pub fn local_sync() -> (
228
235
( handle, outbox_rx, inbox_tx)
229
236
}
230
237
231
- // local sync at the start of the server
238
+ // local and object store sync at the start of the server
232
239
pub async fn sync_start ( ) -> anyhow:: Result < ( ) > {
233
- let mut local_sync_joinset = JoinSet :: new ( ) ;
234
- PARSEABLE
235
- . streams
236
- . flush_and_convert ( & mut local_sync_joinset, true , false ) ;
237
- while let Some ( res) = local_sync_joinset. join_next ( ) . await {
238
- log_join_result ( res, "flush and convert" ) ;
239
- }
240
+ // Monitor local sync duration at startup
241
+ monitor_task_duration ( "startup_local_sync" , Duration :: from_secs ( 15 ) , || async {
242
+ let mut local_sync_joinset = JoinSet :: new ( ) ;
243
+ PARSEABLE
244
+ . streams
245
+ . flush_and_convert ( & mut local_sync_joinset, true , false ) ;
246
+ while let Some ( res) = local_sync_joinset. join_next ( ) . await {
247
+ log_join_result ( res, "flush and convert" ) ;
248
+ }
249
+ } )
250
+ . await ;
251
+
252
+ // Monitor object store sync duration at startup
253
+ monitor_task_duration (
254
+ "startup_object_store_sync" ,
255
+ Duration :: from_secs ( 15 ) ,
256
+ || async {
257
+ let mut object_store_joinset = JoinSet :: new ( ) ;
258
+ sync_all_streams ( & mut object_store_joinset) ;
259
+ while let Some ( res) = object_store_joinset. join_next ( ) . await {
260
+ log_join_result ( res, "object store sync" ) ;
261
+ }
262
+ } ,
263
+ )
264
+ . await ;
240
265
241
- let mut object_store_joinset = JoinSet :: new ( ) ;
242
- sync_all_streams ( & mut object_store_joinset) ;
243
- while let Some ( res) = object_store_joinset. join_next ( ) . await {
244
- log_join_result ( res, "object store sync" ) ;
245
- }
246
266
Ok ( ( ) )
247
267
}
248
268
0 commit comments