add week 2 day 5 + 6 tests

Signed-off-by: Alex Chi <iskyzh@gmail.com>
This commit is contained in:
Alex Chi
2024-01-26 15:19:56 +08:00
parent 595016f2b6
commit 14c3be390c
12 changed files with 206 additions and 27 deletions

View File

@@ -253,6 +253,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,23 +265,26 @@ impl LsmStorageInner {
l0_sstables: l0_sstables.clone(),
l1_sstables: l1_sstables.clone(),
};
println!("force full compaction: {:?}", compaction_task);
let sstables = self.compact(&compaction_task)?;
let mut ids = Vec::with_capacity(sstables.len());
{
let _state_lock = self.state_lock.lock();
let state_lock = self.state_lock.lock();
let mut state = self.state.read().as_ref().clone();
for sst in l0_sstables.iter().chain(l1_sstables.iter()) {
let result = state.sstables.remove(sst);
assert!(result.is_some());
}
let mut ids = Vec::with_capacity(sstables.len());
for new_sst in sstables {
ids.push(new_sst.sst_id());
let result = state.sstables.insert(new_sst.sst_id(), new_sst);
assert!(result.is_none());
}
assert_eq!(l1_sstables, state.levels[0].1);
state.levels[0].1 = ids;
state.levels[0].1 = ids.clone();
let mut l0_sstables_map = l0_sstables.iter().copied().collect::<HashSet<_>>();
state.l0_sstables = state
.l0_sstables
@@ -290,10 +294,18 @@ impl LsmStorageInner {
.collect::<Vec<_>>();
assert!(l0_sstables_map.is_empty());
*self.state.write() = Arc::new(state);
self.sync_dir()?;
self.manifest.as_ref().unwrap().add_record(
&state_lock,
ManifestRecord::Compaction(compaction_task, ids.clone()),
)?;
}
for sst in l0_sstables.iter().chain(l1_sstables.iter()) {
std::fs::remove_file(self.path_of_sst(*sst))?;
}
println!("force full compaction done, new SSTs: {:?}", ids);
Ok(())
}
@@ -308,6 +320,7 @@ impl LsmStorageInner {
let Some(task) = task else {
return Ok(());
};
self.dump_structure();
println!("running compaction task: {:?}", task);
let sstables = self.compact(&task)?;
let output = sstables.iter().map(|x| x.sst_id()).collect::<Vec<_>>();