Skip to content

Commit

Permalink
check compaction converge for simple leveled
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Chi Z <[email protected]>
  • Loading branch information
skyzh committed Jan 17, 2024
1 parent 6649111 commit e622bee
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion mini-lsm-starter/src/block/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ impl BlockIterator {
}

/// Seek to the first key that >= `key`.
/// Note: You should assume the key-value pairs in the block are sorted when being added by callers.
/// Note: You should assume the key-value pairs in the block are sorted when being added by
/// callers.
pub fn seek_to_key(&mut self, key: &[u8]) {
unimplemented!()
}
Expand Down
6 changes: 4 additions & 2 deletions mini-lsm-starter/src/table/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ impl SsTableBuilder {
}

/// Adds a key-value pair to SSTable.
/// Note: You should split a new block when the current block is full.(`std::mem::replace` may be of help here)
/// Note: You should split a new block when the current block is full.(`std::mem::replace` may
/// be of help here)
pub fn add(&mut self, key: &[u8], value: &[u8]) {
unimplemented!()
}

/// Get the estimated size of the SSTable.
/// Since the data blocks contain much more data than meta blocks, just return the size of data blocks here.
/// Since the data blocks contain much more data than meta blocks, just return the size of data
/// blocks here.
pub fn estimated_size(&self) -> usize {
unimplemented!()
}
Expand Down
3 changes: 2 additions & 1 deletion mini-lsm-starter/src/table/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ impl SsTableIterator {
}

/// Seek to the first key-value pair which >= `key`.
/// Note: You probably want to review the handout for detailed explanation when implementing this function.
/// Note: You probably want to review the handout for detailed explanation when implementing
/// this function.
pub fn seek_to_key(&mut self, key: &[u8]) -> Result<()> {
unimplemented!()
}
Expand Down
2 changes: 1 addition & 1 deletion mini-lsm-week-1/src/block/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl BlockBuilder {

fn estimated_size(&self) -> usize {
SIZEOF_U16 /* number of key-value pairs in the block */ + self.offsets.len() * SIZEOF_U16 /* offsets */ + self.data.len()
/* key-value pairs */
// key-value pairs
}

/// Adds a key-value pair to the block. Returns false when the block is full.
Expand Down
3 changes: 2 additions & 1 deletion mini-lsm-week-1/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ impl BlockMeta {
// The size of actual key
estimated_size += meta.first_key.len();
}
// Reserve the space to improve performance, especially when the size of incoming data is large
// Reserve the space to improve performance, especially when the size of incoming data is
// large
buf.reserve(estimated_size);
let original_len = buf.len();
for meta in block_meta {
Expand Down
5 changes: 4 additions & 1 deletion mini-lsm/src/bin/compaction_simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ fn main() {
}
let mut num_compactions = 0;
while let Some(task) = controller.generate_compaction_task(&storage.snapshot) {
num_compactions += 1;
println!("--- Compaction Task ---");
let mut sst_ids = Vec::new();
for file in task
Expand Down Expand Up @@ -194,6 +193,10 @@ fn main() {
} else {
storage.dump_original_id(true);
}
num_compactions += 1;
if num_compactions >= max_levels * 2 {
panic!("compaction does not converge?");
}
}
if num_compactions == 0 {
println!("no compaction triggered");
Expand Down

0 comments on commit e622bee

Please sign in to comment.