Skip to content

Commit

Permalink
Merge pull request #5 from Gifted-s/index_cleanup
Browse files Browse the repository at this point in the history
Index cleanup and test revamp
  • Loading branch information
Gifted-s authored Mar 14, 2024
2 parents 0489637 + 0aeef6f commit 5a35c05
Show file tree
Hide file tree
Showing 15 changed files with 201 additions and 134 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed bump_test/v_log/val_log.bin
Binary file not shown.
13 changes: 3 additions & 10 deletions src/block/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
//! | Block |
//! +----------------------------------+
//! | - data: Vec<u8> | // Data entries within the block
//! | - index: HashMap<Arc<Vec<u8>>, usize> | // Index for key-based lookups
//! | - entry_count: usize | // Number of entries in the block
//! | |
//! | - entry_count: usize | // Number of entries in the block
//! +----------------------------------+
//! | Block Data |
//! | Block Data |
//! | +------------------------+ |
//! | | Entry 1 | |
//! | | +-------------------+ | |
Expand Down Expand Up @@ -129,8 +129,6 @@ impl Block {
}

pub async fn write_to_file(&self, file: &mut File) -> Result<(), StorageEngineError> {
//println!("here is offset we are looking for {} 222", offset.len());

for entry in &self.data {
let entry_len = entry.key.len() + SIZE_OF_U32 + SIZE_OF_U32 + SIZE_OF_U64 + SIZE_OF_U8;
let mut entry_vec = Vec::with_capacity(entry_len);
Expand All @@ -157,11 +155,6 @@ impl Block {
file.write_all(&entry_vec)
.await
.map_err(|err| SSTableWriteError { error: err })?;



//let offset = file.seek(tokio::io::SeekFrom::Current(0)).await.unwrap();
//println!("Writing this offset {}", 0);
}

Ok(())
Expand Down
1 change: 0 additions & 1 deletion src/compaction/compactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ impl Compactor {
for entry in m.sstable.index.iter() {
if self.tombstones.contains_key(entry.key()) {
let tombstone_timestamp = *self.tombstones.get(entry.key()).unwrap();
//println!("found a key in ton=bstine {:?} tombstone t_timestamp: {} normal creation time {:?}", entry.key(),tombstone_timestamp,entry.value().1);
if tombstone_timestamp < entry.value().1 {
new_index.insert(
entry.key().to_vec(),
Expand Down
8 changes: 1 addition & 7 deletions src/sparse_index/sparse_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tokio::{
};

use crate::{
consts::{EOF, SIZE_OF_U32, SIZE_OF_U64, SIZE_OF_U8},
consts::{EOF, SIZE_OF_U32},
err::StorageEngineError,
};
use StorageEngineError::*;
Expand Down Expand Up @@ -95,7 +95,6 @@ impl SparseIndex {
if sstable_file_offset ==-1{
return Ok(None);
}
println!("RETURNEDE HERE");
return Ok(Some(sstable_file_offset as u32));
}
let key_len = u32::from_le_bytes(key_len_bytes);
Expand Down Expand Up @@ -126,21 +125,16 @@ impl SparseIndex {
}

let offset = u32::from_le_bytes(key_offset_bytes);
println!("ggg {} ", offset);
match key.cmp(&searched_key.to_vec()) {
std::cmp::Ordering::Less => sstable_file_offset = offset as i32,
std::cmp::Ordering::Equal => {
println!("KEY {}, SEARCHED {}", String::from_utf8_lossy(&key), String::from_utf8_lossy(&searched_key) );
println!("RETURNEDE HERE 2");
return Ok(Some(offset));
}
std::cmp::Ordering::Greater => {
// if all index keys are greater than the searched key then return none
if sstable_file_offset ==-1{
println!("RETURNEDE HERE 3");
return Ok(None);
}
println!("RETURNEDE HERE");
return Ok(Some(sstable_file_offset as u32));
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/sstable/sst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,8 @@ impl SSTable {
.await
.map_err(|err| GetFileMetaDataError(err))?
.len();
// println!("here is offset we are looking for {}", offset);
let first_entry = block.get_first_entry();
// println!("here is offset we are looking for {}", offset);
// Store initial entry key and its sstable file offset in sparse index
println!("OFFSET {:?}, {:?}",String::from_utf8_lossy( &first_entry.key), offset);
sparse_index.insert(first_entry.key_prefix, first_entry.key, offset as u32);
block.write_to_file(file).await?;
Ok(())
Expand Down Expand Up @@ -245,7 +242,6 @@ impl SSTable {
return Ok(None);
}
let key_len = u32::from_le_bytes(key_len_bytes);
println!("KEY LENGTH {}", key_len);
let mut key = vec![0; key_len as usize];
bytes_read = file
.read(&mut key)
Expand Down Expand Up @@ -307,7 +303,6 @@ impl SSTable {
let created_at = u64::from_le_bytes(created_at_bytes);
let value_offset = u32::from_le_bytes(val_offset_bytes);
let is_tombstone = is_tombstone_byte[0] == 1;
println!("This is the key {:?}", String::from_utf8(key.clone()));
if key == searched_key {
return Ok(Some((value_offset as usize, created_at, is_tombstone)));
}
Expand Down
Loading

0 comments on commit 5a35c05

Please sign in to comment.