From b6aeb632e3cf39ea1dd3fedfaf8628e5edcdd10d Mon Sep 17 00:00:00 2001 From: Seph Gentle Date: Thu, 12 Sep 2024 10:59:30 +1000 Subject: [PATCH] wip storage --- src/storage/mod.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/storage/mod.rs b/src/storage/mod.rs index dfb30fb..f4ab735 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -381,19 +381,18 @@ impl StorageEngine { let total_len = file.stream_len()?; // let (header_fields, next_free_page, data_chunks) = Self::read_or_initialize_header(&mut file, total_len)?; - - // Gross! - const HACK_NONE: Option> = None; - + if total_len == 0 { println!("Initializing headers"); // Presumably a new file. Initialize it using the default options. let header_fields = StorageHeaderFields::default(); - // TODO: Consider just leaving header_dirty=true here and not writing the inital header. + // TODO: Consider just leaving header_dirty=true here and not writing the initial header. HeaderPage::encode_and_bake(&header_fields) .write(&mut file, 0)?; + // Gross! + const HACK_NONE: Option> = None; Ok(Self { file, header_dirty: false, @@ -766,7 +765,7 @@ mod test { // let mut se = StorageEngine::from_file(TestFile::new()).unwrap(); let mut se = StorageEngine::open("foo.dts").unwrap(); - for i in 0..4000 { + for i in 0..40 { // for i in 0..20 { se.append_chunk(DataPageType::AgentNames, "yo dawg", &(i as usize)).unwrap(); // push_usize(&mut se.write_to(DataPageType::AgentNames), i).unwrap(); @@ -777,11 +776,15 @@ mod test { se.fsync().unwrap(); // for page in se.iter_data_pages(DataPageType::AgentNames) { - // let mut page = page.unwrap(); - // dbg!(page.read_fields().unwrap()); - // dbg!(page.get_content().len()); + // dbg!(page.unwrap()); // } + for page in se.iter_data_pages(DataPageType::AgentNames) { + let mut page = page.unwrap(); + dbg!(page.read_fields().unwrap()); + dbg!(page.get_content().len()); + } + // se.make_data(DataPageType::AgentNames).unwrap(); // se.append_bytes_to(DataPageType::AgentNames).unwrap(); // se.fsync().unwrap();