Skip to content

Commit

Permalink
Add feature for SSTable
Browse files Browse the repository at this point in the history
  • Loading branch information
summerxwu committed Aug 25, 2023
1 parent 1bdc4e8 commit a3cadce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/blocks/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ impl BlockBuilder {
pub fn clean_up(&mut self) {
self.data.clear();
self.offsets.clear();
self.amount = 0;
self.amount = 2;
}
pub fn is_empty(&self) ->bool{
self.amount == 2
}
}
9 changes: 7 additions & 2 deletions src/sstable/sstable_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl SSTableBuilder {

pub fn approximate_size_after_add(&self, key: &[u8], value: &[u8]) -> usize {
// TODO(summerxwu): accumulate the data size of current builder memory
1
SSTABLE_SIZE_LIMIT
}

/// [`add`] function append user specified key and value pair to current builder.
Expand All @@ -42,7 +42,12 @@ impl SSTableBuilder {
return Ok(());
}
/// build will return the `SSTable` object and serializable the content to disk file
pub fn build(&self) -> Result<SSTable> {
pub fn build(&mut self) -> Result<SSTable> {
if !self.block_builder.is_empty(){
let data_block_holder = self.block_builder.build();
self.data_blocks.push(data_block_holder);
self.block_builder.clean_up();
}
let seq = get_global_sequence_number();
let mut file_obj = FileObject::create(sstfile_path(seq as usize).as_str())?;

Expand Down

0 comments on commit a3cadce

Please sign in to comment.