Skip to content

Commit

Permalink
feat: compaction trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
KKould committed Jul 30, 2024
1 parent 8598e6c commit 7c9a926
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 53 deletions.
11 changes: 10 additions & 1 deletion src/compaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ use crate::{
},
DbOption, Schema,
};
use crate::inmem::mutable::Mutable;

#[derive(Debug)]
pub(crate) enum CompactTask {
Flush,
Freeze,
}

pub(crate) struct Compactor<R, FP>
Expand Down Expand Up @@ -67,6 +68,14 @@ where
) -> Result<(), CompactionError<R>> {
let mut guard = self.schema.write().await;

if guard.mutable.is_empty() {
println!("WWWWWW");
return Ok(())
}
let mutable = mem::replace(&mut guard.mutable, Mutable::new(&self.option).await?);
let (file_id, immutable) = mutable.to_immutable().await?;

guard.immutables.push_front((file_id, immutable));
if guard.immutables.len() > self.option.immutable_chunk_num {
let excess = guard.immutables.split_off(self.option.immutable_chunk_num);

Expand Down
1 change: 1 addition & 0 deletions src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub mod tokio {

use super::Executor;

#[derive(Debug)]
pub struct TokioExecutor {
handle: Handle,
}
Expand Down
4 changes: 4 additions & 0 deletions src/inmem/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ where
self.data.range((lower, upper))
}

pub(crate) fn is_empty(&self) -> bool {
self.data.is_empty()
}

pub(crate) fn check_conflict(&self, key: &R::Key, ts: Timestamp) -> bool {
self.data
.range::<TimestampedRef<<R as Record>::Key>, _>((
Expand Down
Loading

0 comments on commit 7c9a926

Please sign in to comment.