consider merge width for tiered trigger + mvcc compaction
Signed-off-by: Alex Chi <iskyzh@gmail.com>
This commit is contained in:
@@ -115,26 +115,22 @@ impl LsmStorageInner {
|
||||
fn compact_generate_sst_from_iter(
|
||||
&self,
|
||||
mut iter: impl for<'a> StorageIterator<KeyType<'a> = KeySlice<'a>>,
|
||||
compact_to_bottom_level: bool,
|
||||
_compact_to_bottom_level: bool,
|
||||
) -> Result<Vec<Arc<SsTable>>> {
|
||||
let mut builder = None;
|
||||
let mut new_sst = Vec::new();
|
||||
|
||||
let mut last_key = Vec::<u8>::new();
|
||||
while iter.is_valid() {
|
||||
if builder.is_none() {
|
||||
builder = Some(SsTableBuilder::new(self.options.block_size));
|
||||
}
|
||||
let builder_inner = builder.as_mut().unwrap();
|
||||
if compact_to_bottom_level {
|
||||
if !iter.value().is_empty() {
|
||||
builder_inner.add(iter.key(), iter.value());
|
||||
}
|
||||
} else {
|
||||
builder_inner.add(iter.key(), iter.value());
|
||||
}
|
||||
iter.next()?;
|
||||
builder_inner.add(iter.key(), iter.value());
|
||||
|
||||
if builder_inner.estimated_size() >= self.options.target_sst_size {
|
||||
let same_as_last_key = iter.key().key_ref() == &last_key;
|
||||
|
||||
if builder_inner.estimated_size() >= self.options.target_sst_size && !same_as_last_key {
|
||||
let sst_id = self.next_sst_id();
|
||||
let builder = builder.take().unwrap();
|
||||
let sst = Arc::new(builder.build(
|
||||
@@ -144,6 +140,12 @@ impl LsmStorageInner {
|
||||
)?);
|
||||
new_sst.push(sst);
|
||||
}
|
||||
|
||||
if !same_as_last_key {
|
||||
last_key.clear();
|
||||
last_key.extend(iter.key().key_ref());
|
||||
}
|
||||
iter.next()?;
|
||||
}
|
||||
if let Some(builder) = builder {
|
||||
let sst_id = self.next_sst_id(); // lock dropped here
|
||||
@@ -253,6 +255,7 @@ impl LsmStorageInner {
|
||||
let CompactionOptions::NoCompaction = self.options.compaction_options else {
|
||||
panic!("full compaction can only be called with compaction is not enabled")
|
||||
};
|
||||
|
||||
let snapshot = {
|
||||
let state = self.state.read();
|
||||
state.clone()
|
||||
@@ -264,6 +267,9 @@ impl LsmStorageInner {
|
||||
l0_sstables: l0_sstables.clone(),
|
||||
l1_sstables: l1_sstables.clone(),
|
||||
};
|
||||
|
||||
println!("force full compaction: {:?}", compaction_task);
|
||||
|
||||
let sstables = self.compact(&compaction_task)?;
|
||||
|
||||
{
|
||||
@@ -294,10 +300,14 @@ impl LsmStorageInner {
|
||||
for sst in l0_sstables.iter().chain(l1_sstables.iter()) {
|
||||
std::fs::remove_file(self.path_of_sst(*sst))?;
|
||||
}
|
||||
|
||||
println!("force full compaction done");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn trigger_compaction(&self) -> Result<()> {
|
||||
self.dump_structure();
|
||||
let snapshot = {
|
||||
let state = self.state.read();
|
||||
state.clone()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::lsm_storage::MiniLsm;
|
||||
use crate::lsm_storage::{LsmStorageInner, MiniLsm};
|
||||
|
||||
impl MiniLsm {
|
||||
impl LsmStorageInner {
|
||||
pub fn dump_structure(&self) {
|
||||
let snapshot = self.inner.state.read();
|
||||
let snapshot = self.state.read();
|
||||
if !snapshot.l0_sstables.is_empty() {
|
||||
println!(
|
||||
"L0 ({}): {:?}",
|
||||
@@ -15,3 +15,9 @@ impl MiniLsm {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MiniLsm {
|
||||
pub fn dump_structure(&self) {
|
||||
self.inner.dump_structure()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ mod week1_day4;
|
||||
mod week1_day5;
|
||||
mod week1_day6;
|
||||
mod week1_day7;
|
||||
// mod week2_day1;
|
||||
// mod week2_day2;
|
||||
// mod week2_day3;
|
||||
// mod week2_day4;
|
||||
mod week2_day1;
|
||||
mod week2_day2;
|
||||
mod week2_day3;
|
||||
mod week2_day4;
|
||||
|
||||
Reference in New Issue
Block a user