Skip to main content

uni_store/
compaction.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2024-2026 Dragonscale Team
3
4use std::time::{Duration, SystemTime};
5
6/// Trigger strategy for a compaction run.
7#[derive(Debug, Clone, Copy)]
8pub enum CompactionTask {
9    /// Compact when the number of L1 runs exceeds a threshold.
10    ByRunCount,
11    /// Compact when the total L1 size exceeds a byte threshold.
12    BySize,
13    /// Compact when the oldest L1 run exceeds an age threshold.
14    ByAge,
15}
16
17/// Statistics produced by a single compaction run.
18#[derive(Debug, Clone, Default)]
19pub struct CompactionStats {
20    pub files_compacted: usize,
21    pub bytes_before: u64,
22    pub bytes_after: u64,
23    pub duration: Duration,
24    pub crdt_merges: usize,
25}
26
27/// Snapshot of the current compaction state for observability.
28#[derive(Debug, Clone, Default)]
29pub struct CompactionStatus {
30    pub l1_runs: usize,
31    pub l1_size_bytes: u64,
32    pub oldest_l1_age: Duration,
33    pub compaction_in_progress: bool,
34    pub compaction_pending: usize,
35    pub last_compaction: Option<SystemTime>,
36    pub total_compactions: u64,
37    pub total_bytes_compacted: u64,
38}