fjall/compaction/
mod.rs

1// Copyright (c) 2024-present, fjall-rs
2// This source code is licensed under both the Apache 2.0 and MIT License
3// (found in the LICENSE-* files in the repository)
4
5pub(crate) mod manager;
6pub(crate) mod worker;
7
8use std::sync::Arc;
9
10pub use lsm_tree::compaction::{Fifo, Leveled, Levelled, SizeTiered};
11
12/// Compaction strategy
13#[derive(Clone)]
14#[allow(clippy::module_name_repetitions)]
15pub enum Strategy {
16    /// Leveled compaction
17    Leveled(crate::compaction::Leveled),
18
19    /// Size-tiered compaction
20    SizeTiered(crate::compaction::SizeTiered),
21
22    /// FIFO compaction
23    Fifo(crate::compaction::Fifo),
24}
25
26impl std::fmt::Debug for Strategy {
27    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28        write!(
29            f,
30            "{}",
31            match self {
32                Self::SizeTiered(_) => "SizeTieredStrategy",
33                Self::Leveled(_) => "LeveledStrategy",
34                Self::Fifo(_) => "FifoStrategy",
35            }
36        )
37    }
38}
39
40impl Default for Strategy {
41    fn default() -> Self {
42        Self::Leveled(crate::compaction::Leveled::default())
43    }
44}
45
46impl Strategy {
47    pub(crate) fn inner(&self) -> Arc<dyn lsm_tree::compaction::CompactionStrategy + Send + Sync> {
48        match self {
49            Self::Leveled(s) => Arc::new(s.clone()),
50            Self::SizeTiered(s) => Arc::new(s.clone()),
51            Self::Fifo(s) => Arc::new(s.clone()),
52        }
53    }
54}