@@ -130,19 +130,39 @@ fn gc_sweep<'a>(
130
130
} )
131
131
}
132
132
133
+ /// Configuration for garbage collection.
133
134
#[ derive( derive_more:: Debug , Clone ) ]
134
135
pub struct GcConfig {
136
+ /// Interval in which to run garbage collection.
135
137
pub interval : std:: time:: Duration ,
138
+ /// Optional callback to manually add protected blobs.
139
+ ///
140
+ /// The callback is called before each garbage collection run. It gets a `&mut HashSet<Hash>`
141
+ /// and returns a future that returns [`ProtectOutcome`]. All hashes that are added to the
142
+ /// [`HashSet`] will be protected from garbage collection during this run.
143
+ ///
144
+ /// In normal operation, return [`ProtectOutcome::Continue`] from the callback. If you return
145
+ /// [`ProtectOutcome::Abort`], the garbage collection run will be aborted.Use this if your
146
+ /// source of hashes to protect returned an error, and thus garbage collection should be skipped
147
+ /// completely to not unintentionally delete blobs that should be protected.
136
148
#[ debug( "ProtectCallback" ) ]
137
149
pub add_protected : Option < ProtectCb > ,
138
150
}
139
151
152
+ /// Returned from [`ProtectCb`].
153
+ ///
154
+ /// See [`GcConfig::add_protected] for details.
140
155
#[ derive( Debug ) ]
141
156
pub enum ProtectOutcome {
157
+ /// Continue with the garbage collection run.
142
158
Continue ,
143
- Skip ,
159
+ /// Abort the garbage collection run.
160
+ Abort ,
144
161
}
145
162
163
+ /// The type of the garbage collection callback.
164
+ ///
165
+ /// See [`GcConfig::add_protected] for details.
146
166
pub type ProtectCb = Arc <
147
167
dyn for < ' a > Fn (
148
168
& ' a mut HashSet < Hash > ,
@@ -205,8 +225,8 @@ pub async fn run_gc(store: Store, config: GcConfig) {
205
225
if let Some ( ref cb) = config. add_protected {
206
226
match ( cb) ( & mut live) . await {
207
227
ProtectOutcome :: Continue => { }
208
- ProtectOutcome :: Skip => {
209
- info ! ( "Skip gc run: protect callback indicated skip " ) ;
228
+ ProtectOutcome :: Abort => {
229
+ info ! ( "abort gc run: protect callback indicated abort " ) ;
210
230
continue ;
211
231
}
212
232
}
0 commit comments