add compaction thread to lsm storage
Signed-off-by: Alex Chi <iskyzh@gmail.com>
This commit is contained in:
@@ -13,21 +13,50 @@ pub use tiered::{TieredCompactionController, TieredCompactionOptions, TieredComp
|
||||
|
||||
use crate::iterators::merge_iterator::MergeIterator;
|
||||
use crate::iterators::StorageIterator;
|
||||
use crate::lsm_storage::LsmStorage;
|
||||
use crate::lsm_storage::LsmStorageInner;
|
||||
use crate::table::{SsTable, SsTableBuilder, SsTableIterator};
|
||||
|
||||
pub enum CompactionTask {
|
||||
pub(crate) enum CompactionTask {
|
||||
Leveled(LeveledCompactionTask),
|
||||
Tiered(TieredCompactionTask),
|
||||
Simple(SimpleLeveledCompactionTask),
|
||||
}
|
||||
|
||||
struct CompactOptions {
|
||||
block_size: usize,
|
||||
target_sst_size: usize,
|
||||
compact_to_bottom_level: bool,
|
||||
}
|
||||
|
||||
impl LsmStorage {
|
||||
pub(crate) enum CompactionController {
|
||||
Leveled(LeveledCompactionController),
|
||||
Tiered(TieredCompactionController),
|
||||
Simple(SimpleLeveledCompactionController),
|
||||
NoCompaction,
|
||||
}
|
||||
|
||||
impl CompactionController {
|
||||
pub fn flush_to_l0(&self) -> bool {
|
||||
if let Self::Leveled(_) | Self::Simple(_) | Self::NoCompaction = self {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum CompactionOptions {
|
||||
/// Leveled compaction with partial compaction + dynamic level support (= RocksDB's Leveled
|
||||
/// Compaction)
|
||||
Leveled(LeveledCompactionOptions),
|
||||
/// Tiered compaction (= RocksDB's universal compaction)
|
||||
Tiered(TieredCompactionOptions),
|
||||
/// Simple leveled compaction
|
||||
Simple(SimpleLeveledCompactionOptions),
|
||||
/// In no compaction mode (week 1), always flush to L0
|
||||
NoCompaction,
|
||||
}
|
||||
|
||||
impl LsmStorageInner {
|
||||
#[allow(dead_code)]
|
||||
fn compact(
|
||||
&self,
|
||||
@@ -46,12 +75,14 @@ impl LsmStorage {
|
||||
let mut builder = None;
|
||||
let mut new_sst = vec![];
|
||||
|
||||
let compact_to_bottom_level = false;
|
||||
|
||||
while iter.is_valid() {
|
||||
if builder.is_none() {
|
||||
builder = Some(SsTableBuilder::new(options.block_size));
|
||||
}
|
||||
let builder_inner = builder.as_mut().unwrap();
|
||||
if options.compact_to_bottom_level {
|
||||
if compact_to_bottom_level {
|
||||
if !iter.value().is_empty() {
|
||||
builder_inner.add(iter.key(), iter.value());
|
||||
}
|
||||
@@ -82,4 +113,11 @@ impl LsmStorage {
|
||||
}
|
||||
Ok(new_sst)
|
||||
}
|
||||
|
||||
pub(crate) fn spawn_compaction_thread(
|
||||
self: &Arc<Self>,
|
||||
rx: std::sync::mpsc::Receiver<()>,
|
||||
) -> Result<Option<std::thread::JoinHandle<()>>> {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user