pub struct Compactor {
pub base_path: PathBuf,
pub write_budget_bytes: u64,
pub cohort_window_secs: u64,
}Expand description
Drives deathtime-cohort compaction for an EdgeStore database.
The compactor groups segments by their cohort bucket, waits until all records in a cohort are past their death time, then rewrites only the live records into new segments (removing dead ones). No in-place writes are performed; all output is append-oriented.
Fields§
§base_path: PathBufBase directory of the EdgeStore database being compacted.
write_budget_bytes: u64Maximum bytes the compactor may write per compact_cycle call.
cohort_window_secs: u64Cohort window width in seconds (matches EdgestoreConfig::cohort_window_secs).
Implementations§
Source§impl Compactor
impl Compactor
Sourcepub fn new(
base_path: PathBuf,
write_budget_bytes: u64,
cohort_window_secs: u64,
) -> Self
pub fn new( base_path: PathBuf, write_budget_bytes: u64, cohort_window_secs: u64, ) -> Self
Create a new Compactor.
base_path — database directory.
write_budget_bytes— write-amplification cap per compaction pass.
cohort_window_secs— must match the value used when segments were written.
Sourcepub fn identify_cohorts(
segments: &[SegmentMeta],
now_nanos: i64,
) -> Vec<CohortInfo>
pub fn identify_cohorts( segments: &[SegmentMeta], now_nanos: i64, ) -> Vec<CohortInfo>
Group segments into cohorts and sort them for compaction priority.
Fully-expired cohorts (now_nanos > max_death_time_nanos) come first, ordered by lowest max_death_time_nanos. Partially-expired cohorts follow.
Sourcepub fn collect_expired_cohort(
&self,
manifest: &mut Manifest,
cohort: &CohortInfo,
stats: &mut CompactionStats,
) -> Result<(), EdgestoreError>
pub fn collect_expired_cohort( &self, manifest: &mut Manifest, cohort: &CohortInfo, stats: &mut CompactionStats, ) -> Result<(), EdgestoreError>
Remove all segment files and manifest entries for a fully-expired cohort.
Zero live records are relocated (all were expired). Missing files are logged and skipped — not treated as errors. Caller is responsible for ensuring no pinned segments are in the cohort. Delete all files belonging to an expired cohort.
Sourcepub fn compact_partial_cohort(
&self,
manifest: &mut Manifest,
cohort: &CohortInfo,
now_nanos: i64,
next_segment_id: SegmentId,
stats: &mut CompactionStats,
) -> Result<(), EdgestoreError>
pub fn compact_partial_cohort( &self, manifest: &mut Manifest, cohort: &CohortInfo, now_nanos: i64, next_segment_id: SegmentId, stats: &mut CompactionStats, ) -> Result<(), EdgestoreError>
Compact a partially-expired cohort: read all entries, filter dead ones, write survivors to a new segment, remove old segments.
If no entries survive, the cohort is treated as fully expired (files deleted, no output segment written). Rewrite a partially-expired cohort, keeping only live entries.
Sourcepub fn compact_cycle(
&self,
manifest: &mut Manifest,
now_nanos: i64,
pinned_segment_ids: &HashSet<SegmentId>,
) -> Result<CompactionStats, EdgestoreError>
pub fn compact_cycle( &self, manifest: &mut Manifest, now_nanos: i64, pinned_segment_ids: &HashSet<SegmentId>, ) -> Result<CompactionStats, EdgestoreError>
Run one full compaction cycle against the manifest.
- Fully-expired cohorts are collected first (zero live relocation).
- Partially-expired cohorts are compacted by removing dead records.
- Stops when
bytes_written >= write_budget_bytes. - Segments in
pinned_segment_idsare never removed or rewritten.
Run a full compaction cycle over all cohorts.