This commit is contained in:
Yuriy Dupyn 2024-02-05 03:29:42 +01:00
parent c0a3ee08b8
commit 1618bffb85
6 changed files with 22 additions and 152 deletions

View file

@ -9,7 +9,7 @@ mod store_header;
use crate::entry::{Entry, EntryDetailed};
use crate::storage_engine::{Store, FilePosition};
use crate::cursor::{ReadCursor, WriteCursor, CursorWithStoreHeader, CursorWithWriteStoreHeader, CursorWithWriteAccessToIndex, CursorWithAccessToIndex};
use crate::cursor::{ReadCursor, WriteCursor, CursorWithStoreHeader, CursorWithWriteAccessToIndex};
type Data = u32;
@ -18,7 +18,7 @@ const TABLE_PATH: &'static str = "test_table";
type Result<T> = std::result::Result<T, std::io::Error>;
async fn create_store() -> Result<Store<Data>> {
let mut store: Store<Data> = Store::new(TABLE_PATH, 5, 0).await.map_err(|e| e.to_io_or_panic())?;
let store: Store<Data> = Store::new(TABLE_PATH, 5, 0).await.map_err(|e| e.to_io_or_panic())?;
println!("CREATED");
// println!("THE STORE: {:?}", store);
// println!("THE BYTES: {:?}", store.read_all_bytes().await?);
@ -27,7 +27,7 @@ async fn create_store() -> Result<Store<Data>> {
}
async fn connect_store() -> Result<Store<Data>> {
let mut store: Store<Data> = Store::connect(TABLE_PATH).await.map_err(|e| e.to_io_or_panic())?;
let store: Store<Data> = Store::connect(TABLE_PATH).await.map_err(|e| e.to_io_or_panic())?;
println!("CONNECTED");
// println!("THE STORE: {:?}", store);
// println!("THE BYTES: {:?}", store.read_all_bytes().await?);
@ -56,10 +56,9 @@ async fn append_entry(cursor: &mut WriteCursor<'_, Data>, entry: Entry<Data>) ->
async fn read_entry(cursor: &mut ReadCursor<'_, Data>, file_position: FilePosition) -> Result<Option<EntryDetailed<Data>>> {
println!("READING ENTRY at file_position={}", file_position);
// let entry = cursor.read_entry_at(file_position).await.map_err(|e| e.to_io_or_panic())?;
// println!("ENTRY: {:?}", entry);
// Ok(entry)
todo!()
let entry = cursor.read_entry_at(file_position).await.map_err(|e| e.to_io_or_panic())?;
println!("ENTRY: {:?}", entry);
Ok(entry)
}
async fn append_bunch_of_entries(store: &mut Store<Data>) -> Result<()> {
@ -88,7 +87,7 @@ async fn test_garbage_collection(store: &mut Store<Data>) -> Result<()> {
// 1. mark a bunch of entries as deleted
let column = 0;
let value = 1;
// cursor.delete_entries_where_eq(column, &value, true).await.map_err(|e| e.to_io_or_panic())?;
cursor.delete_entries_where_eq(column, &value, true).await.map_err(|e| e.to_io_or_panic())?;
// let value = 50;
// cursor.delete_entries_where_eq(column, &value).await.map_err(|e| e.to_io_or_panic())?;
@ -133,10 +132,10 @@ async fn main() -> Result<()> {
test_garbage_collection(&mut store).await?;
{
let mut cursor = store.read_cursor().await.map_err(|e| e.to_io_or_panic())?;
cursor.read_entries().await.map_err(|e| e.to_io_or_panic())?;
}
// {
// let mut cursor = store.read_cursor().await.map_err(|e| e.to_io_or_panic())?;
// cursor.read_entries().await.map_err(|e| e.to_io_or_panic())?;
// }
// {