Skip to content

Commit

Permalink
ensure sync
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Chi <[email protected]>
  • Loading branch information
skyzh committed Jan 20, 2024
1 parent b1458a6 commit 4928ece
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
17 changes: 17 additions & 0 deletions mini-lsm-starter/src/debug.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use crate::lsm_storage::MiniLsm;

impl MiniLsm {
pub fn dump_structure(&self) {
let snapshot = self.inner.state.read();
if !snapshot.l0_sstables.is_empty() {
println!(
"L0 ({}): {:?}",
snapshot.l0_sstables.len(),
snapshot.l0_sstables,
);
}
for (level, files) in &snapshot.levels {
println!("L{level} ({}): {:?}", files.len(), files);
}
}
}
1 change: 1 addition & 0 deletions mini-lsm-starter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod block;
pub mod compact;
pub mod debug;
pub mod iterators;
pub mod lsm_iterator;
pub mod lsm_storage;
Expand Down
22 changes: 20 additions & 2 deletions mini-lsm-starter/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ use crate::lsm_storage::BlockCache;
pub struct BlockMeta {
/// Offset of this data block.
pub offset: usize,
/// The first key of the data block, mainly used for index purpose.
/// The first key of the data block.
pub first_key: Bytes,
/// The last key of the data block.
pub last_key: Bytes,
}

impl BlockMeta {
Expand Down Expand Up @@ -138,7 +140,23 @@ impl SsTable {

/// Get number of data blocks.
pub fn num_of_blocks(&self) -> usize {
unimplemented!()
self.block_metas.len()
}

pub fn first_key(&self) -> &Bytes {
&self.first_key
}

pub fn last_key(&self) -> &Bytes {
&self.last_key
}

pub fn table_size(&self) -> u64 {
self.file.1
}

pub fn sst_id(&self) -> usize {
self.id
}
}

Expand Down
2 changes: 1 addition & 1 deletion mini-lsm/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub use builder::BlockBuilder;
use bytes::{Buf, BufMut, Bytes};
pub use iterator::BlockIterator;

pub const SIZEOF_U16: usize = std::mem::size_of::<u16>();
pub(crate) const SIZEOF_U16: usize = std::mem::size_of::<u16>();

/// A block is the smallest unit of read and caching in LSM tree. It is a collection of sorted
/// key-value pairs.
Expand Down

0 comments on commit 4928ece

Please sign in to comment.