@@ -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<_>>();
|
||||
|
||||
Reference in New Issue
Block a user