diff --git a/storage_engine/src/cursor.rs b/storage_engine/src/cursor.rs index 8e0efe0..72a6a4c 100644 --- a/storage_engine/src/cursor.rs +++ b/storage_engine/src/cursor.rs @@ -518,18 +518,37 @@ impl <'cursor, T> WriteCursor<'cursor, T> where T: Send + Decode + Encode { 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> = BTreeMap::new(); // We'll dump all alive entries into a new file. - while let Some(live_entry) = self.next_alive().await? { - let file_position = cursor_to_intermediate.append_entry(&live_entry.forget()).await?; - // TODO: Start indexing all of the indexable columns from scratch. + let mut entries_deleted = 0; + { + 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. - 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>