Implement garbage collection without indexes

This commit is contained in:
Yuriy Dupyn 2024-02-04 21:52:48 +01:00
parent 3a50328e51
commit 2357ea8230

View file

@ -518,18 +518,37 @@ impl <'cursor, T> WriteCursor<'cursor, T>
where T: Send + Decode + Encode where T: Send + Decode + Encode
{ {
let mut cursor_to_intermediate = self.spawn_cursor_to_intermediate_file().await?; let mut cursor_to_intermediate = self.spawn_cursor_to_intermediate_file().await?;
// This will be a vector of such BTree maps...
let in_memory_index: BTreeMap<T, HashSet<FilePosition>> = BTreeMap::new(); let in_memory_index: BTreeMap<T, HashSet<FilePosition>> = BTreeMap::new();
// We'll dump all alive entries into a new file. // We'll dump all alive entries into a new file.
while let Some(live_entry) = self.next_alive().await? { let mut entries_deleted = 0;
let file_position = cursor_to_intermediate.append_entry(&live_entry.forget()).await?; {
// TODO: Start indexing all of the indexable columns from scratch. while let Some(live_entry) = self.next_alive().await? {
entries_deleted += 1;
let file_position = cursor_to_intermediate.append_entry(&live_entry.forget()).await?;
// TODO: Start indexing all of the indexable columns from scratch.
}
} }
// In it there will be only the alive rows. // TODO: Create a new indexes from in_memory_index.
// Afterwards we swap the files, and delete the garbage. // Afterwards we swap the files, and delete the garbage.
todo!() // TODO:
// What needs to be done?
// 1. We take self cursor and mutate it
// swapping headers
self.header.deleted_count = 0;
self.header.total_count = cursor_to_intermediate.header.total_count;
// TODO: We'll actually have to iterate through all the indexes and swap each of them.
self.indexes = todo!();
self.file = cursor_to_intermediate.file;
self.eof_file_position = cursor_to_intermediate.eof_file_position;
Ok(entries_deleted)
} }
async fn spawn_cursor_to_intermediate_file(&self) -> Result<AppendOnlyCursor<T>> async fn spawn_cursor_to_intermediate_file(&self) -> Result<AppendOnlyCursor<T>>