Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lore-storage/src/maintenance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ pub async fn gc(
max_capacity: usize,
sync_data: bool,
sink: Option<GcEventSinkRef>,
) {
grace_period: Option<Duration>,
) -> Result<(), crate::gc::GcError> {
let mut at = store.clone().compact_resume_at().await;

if max_size > 0 {
Expand All @@ -146,17 +147,24 @@ pub async fn gc(
}
Err(err) => {
lore_base::lore_warn!("Store compactor failed: {err}");
break;
return Err(crate::gc::GcError::CompactionFailed(err.to_string()));
}
}
}
lore_base::lore_debug!("Store compactor done");
}

if max_capacity > 0 {
let _ = store.evict(max_capacity, sync_data, sink).await;
// Enforce staging leases and grace period timestamp checking for atomic rollbacks
let _transaction = crate::gc_lease::acquire_exclusive_sweep()
.map_err(|e| crate::gc::GcError::LeaseDenied(e.to_string()))?;

store.evict_with_grace(max_capacity, sync_data, sink, grace_period).await
.map_err(|e| crate::gc::GcError::EvictionFailed(e.to_string()))?;
lore_base::lore_debug!("Store evictor done");
}

Ok(())
}

/// Per-store running totals, collected purely as a byproduct of LOADING data from
Expand Down
7 changes: 6 additions & 1 deletion lore/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,12 @@ async fn flush_local(
#[repr(C)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, LoreArgs)]
#[handler(gc_local)]
pub struct LoreRepositoryGcArgs {}
pub struct LoreRepositoryGcArgs {
/// Grace period (in seconds) to spare newly created fragments from premature pruning
pub grace_period_sec: u64,
/// Minimum size threshold (in bytes) to trigger pruning
pub prune_threshold: u64,
}

/// Runs garbage collection on the local repository store to reclaim space from unreferenced data.
///
Expand Down
Loading