@@ -23,8 +23,7 @@ use std::sync::Arc;
23
23
use std:: time:: Duration ;
24
24
25
25
use futures:: Future ;
26
- use quickwit_actors:: ActorContext ;
27
- use quickwit_common:: PrettySample ;
26
+ use quickwit_common:: { PrettySample , Progress } ;
28
27
use quickwit_metastore:: {
29
28
ListSplitsQuery , Metastore , MetastoreError , SplitInfo , SplitMetadata , SplitState ,
30
29
} ;
@@ -34,8 +33,6 @@ use thiserror::Error;
34
33
use time:: OffsetDateTime ;
35
34
use tracing:: { error, instrument} ;
36
35
37
- use crate :: actors:: GarbageCollector ;
38
-
39
36
/// The maximum number of splits that the GC should delete per attempt.
40
37
const DELETE_SPLITS_BATCH_SIZE : usize = 1000 ;
41
38
@@ -51,17 +48,14 @@ pub struct DeleteSplitsError {
51
48
metastore_failures : Vec < SplitInfo > ,
52
49
}
53
50
54
- async fn protect_future < Fut , T > (
55
- ctx_opt : Option < & ActorContext < GarbageCollector > > ,
56
- future : Fut ,
57
- ) -> T
58
- where
59
- Fut : Future < Output = T > ,
60
- {
61
- if let Some ( ctx) = ctx_opt {
62
- ctx. protect_future ( future) . await
63
- } else {
64
- future. await
51
+ async fn protect_future < Fut , T > ( progress : Option < & Progress > , future : Fut ) -> T
52
+ where Fut : Future < Output = T > {
53
+ match progress {
54
+ None => future. await ,
55
+ Some ( progress) => {
56
+ let _guard = progress. protect_zone ( ) ;
57
+ future. await
58
+ }
65
59
}
66
60
}
67
61
@@ -83,15 +77,15 @@ pub struct SplitRemovalInfo {
83
77
/// * `deletion_grace_period` - Threshold period after which a marked as deleted split can be
84
78
/// safely deleted.
85
79
/// * `dry_run` - Should this only return a list of affected files without performing deletion.
86
- /// * `ctx_opt ` - A context for reporting progress (only useful within quickwit actor).
80
+ /// * `progress ` - For reporting progress (useful when called from within a quickwit actor).
87
81
pub async fn run_garbage_collect (
88
82
index_uid : IndexUid ,
89
83
storage : Arc < dyn Storage > ,
90
84
metastore : Arc < dyn Metastore > ,
91
85
staged_grace_period : Duration ,
92
86
deletion_grace_period : Duration ,
93
87
dry_run : bool ,
94
- ctx_opt : Option < & ActorContext < GarbageCollector > > ,
88
+ progress_opt : Option < & Progress > ,
95
89
) -> anyhow:: Result < SplitRemovalInfo > {
96
90
// Select staged splits with staging timestamp older than grace period timestamp.
97
91
let grace_period_timestamp =
@@ -102,7 +96,7 @@ pub async fn run_garbage_collect(
102
96
. with_update_timestamp_lte ( grace_period_timestamp) ;
103
97
104
98
let deletable_staged_splits: Vec < SplitMetadata > =
105
- protect_future ( ctx_opt , metastore. list_splits ( query) )
99
+ protect_future ( progress_opt , metastore. list_splits ( query) )
106
100
. await ?
107
101
. into_iter ( )
108
102
. map ( |meta| meta. split_metadata )
@@ -112,11 +106,12 @@ pub async fn run_garbage_collect(
112
106
let query = ListSplitsQuery :: for_index ( index_uid. clone ( ) )
113
107
. with_split_state ( SplitState :: MarkedForDeletion ) ;
114
108
115
- let mut splits_marked_for_deletion = protect_future ( ctx_opt, metastore. list_splits ( query) )
116
- . await ?
117
- . into_iter ( )
118
- . map ( |split| split. split_metadata )
119
- . collect :: < Vec < _ > > ( ) ;
109
+ let mut splits_marked_for_deletion =
110
+ protect_future ( progress_opt, metastore. list_splits ( query) )
111
+ . await ?
112
+ . into_iter ( )
113
+ . map ( |split| split. split_metadata )
114
+ . collect :: < Vec < _ > > ( ) ;
120
115
splits_marked_for_deletion. extend ( deletable_staged_splits) ;
121
116
122
117
let candidate_entries: Vec < SplitInfo > = splits_marked_for_deletion
@@ -136,7 +131,7 @@ pub async fn run_garbage_collect(
136
131
. collect ( ) ;
137
132
if !split_ids. is_empty ( ) {
138
133
protect_future (
139
- ctx_opt ,
134
+ progress_opt ,
140
135
metastore. mark_splits_for_deletion ( index_uid. clone ( ) , & split_ids) ,
141
136
)
142
137
. await ?;
@@ -152,14 +147,13 @@ pub async fn run_garbage_collect(
152
147
updated_before_timestamp,
153
148
storage,
154
149
metastore,
155
- ctx_opt ,
150
+ progress_opt ,
156
151
)
157
152
. await ;
158
153
159
154
Ok ( deleted_splits)
160
155
}
161
-
162
- #[ instrument( skip( storage, metastore, ctx_opt) ) ]
156
+ #[ instrument( skip( storage, metastore, progress_opt) ) ]
163
157
/// Removes any splits marked for deletion which haven't been
164
158
/// updated after `updated_before_timestamp` in batches of 1000 splits.
165
159
///
@@ -170,7 +164,7 @@ async fn delete_splits_marked_for_deletion(
170
164
updated_before_timestamp : i64 ,
171
165
storage : Arc < dyn Storage > ,
172
166
metastore : Arc < dyn Metastore > ,
173
- ctx_opt : Option < & ActorContext < GarbageCollector > > ,
167
+ progress_opt : Option < & Progress > ,
174
168
) -> SplitRemovalInfo {
175
169
let mut removed_splits = Vec :: new ( ) ;
176
170
let mut failed_splits = Vec :: new ( ) ;
@@ -181,7 +175,7 @@ async fn delete_splits_marked_for_deletion(
181
175
. with_update_timestamp_lte ( updated_before_timestamp)
182
176
. with_limit ( DELETE_SPLITS_BATCH_SIZE ) ;
183
177
184
- let list_splits_result = protect_future ( ctx_opt , metastore. list_splits ( query) ) . await ;
178
+ let list_splits_result = protect_future ( progress_opt , metastore. list_splits ( query) ) . await ;
185
179
186
180
let splits_to_delete = match list_splits_result {
187
181
Ok ( splits) => splits,
@@ -205,7 +199,7 @@ async fn delete_splits_marked_for_deletion(
205
199
storage. clone ( ) ,
206
200
metastore. clone ( ) ,
207
201
splits_to_delete,
208
- ctx_opt ,
202
+ progress_opt ,
209
203
)
210
204
. await ;
211
205
@@ -234,13 +228,13 @@ async fn delete_splits_marked_for_deletion(
234
228
/// * `storage - The storage managing the target index.
235
229
/// * `metastore` - The metastore managing the target index.
236
230
/// * `splits` - The list of splits to delete.
237
- /// * `ctx_opt ` - A context for reporting progress (only useful within quickwit actor).
231
+ /// * `progress ` - For reporting progress (useful when called from within a quickwit actor).
238
232
pub async fn delete_splits_from_storage_and_metastore (
239
233
index_uid : IndexUid ,
240
234
storage : Arc < dyn Storage > ,
241
235
metastore : Arc < dyn Metastore > ,
242
236
splits : Vec < SplitMetadata > ,
243
- ctx_opt : Option < & ActorContext < GarbageCollector > > ,
237
+ progress_opt : Option < & Progress > ,
244
238
) -> anyhow:: Result < Vec < SplitInfo > , DeleteSplitsError > {
245
239
let mut split_infos: HashMap < PathBuf , SplitInfo > = HashMap :: with_capacity ( splits. len ( ) ) ;
246
240
@@ -252,10 +246,10 @@ pub async fn delete_splits_from_storage_and_metastore(
252
246
. keys ( )
253
247
. map ( |split_path_buf| split_path_buf. as_path ( ) )
254
248
. collect :: < Vec < & Path > > ( ) ;
255
- let delete_result = protect_future ( ctx_opt , storage. bulk_delete ( & split_paths) ) . await ;
249
+ let delete_result = protect_future ( progress_opt , storage. bulk_delete ( & split_paths) ) . await ;
256
250
257
- if let Some ( ctx ) = ctx_opt {
258
- ctx . record_progress ( ) ;
251
+ if let Some ( progress ) = progress_opt {
252
+ progress . record_progress ( ) ;
259
253
}
260
254
let mut successes = Vec :: with_capacity ( split_infos. len ( ) ) ;
261
255
let mut storage_error: Option < BulkDeleteError > = None ;
@@ -292,7 +286,7 @@ pub async fn delete_splits_from_storage_and_metastore(
292
286
. map ( |split_info| split_info. split_id . as_str ( ) )
293
287
. collect ( ) ;
294
288
let metastore_result = protect_future (
295
- ctx_opt ,
289
+ progress_opt ,
296
290
metastore. delete_splits ( index_uid. clone ( ) , & split_ids) ,
297
291
)
298
292
. await ;
0 commit comments