Skip to content

Commit efa928e

Browse files
committed
docs: add docs for gc protection
1 parent 38bfa97 commit efa928e

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/store/fs/gc.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,39 @@ fn gc_sweep<'a>(
130130
})
131131
}
132132

133+
/// Configuration for garbage collection.
133134
#[derive(derive_more::Debug, Clone)]
134135
pub struct GcConfig {
136+
/// Interval in which to run garbage collection.
135137
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.
136148
#[debug("ProtectCallback")]
137149
pub add_protected: Option<ProtectCb>,
138150
}
139151

152+
/// Returned from [`ProtectCb`].
153+
///
154+
/// See [`GcConfig::add_protected] for details.
140155
#[derive(Debug)]
141156
pub enum ProtectOutcome {
157+
/// Continue with the garbage collection run.
142158
Continue,
143-
Skip,
159+
/// Abort the garbage collection run.
160+
Abort,
144161
}
145162

163+
/// The type of the garbage collection callback.
164+
///
165+
/// See [`GcConfig::add_protected] for details.
146166
pub type ProtectCb = Arc<
147167
dyn for<'a> Fn(
148168
&'a mut HashSet<Hash>,
@@ -205,8 +225,8 @@ pub async fn run_gc(store: Store, config: GcConfig) {
205225
if let Some(ref cb) = config.add_protected {
206226
match (cb)(&mut live).await {
207227
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");
210230
continue;
211231
}
212232
}

0 commit comments

Comments
 (0)