17
mini-lsm-starter/src/debug.rs
Normal file
17
mini-lsm-starter/src/debug.rs
Normal file
@@ -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,5 +1,6 @@
|
||||
pub mod block;
|
||||
pub mod compact;
|
||||
pub mod debug;
|
||||
pub mod iterators;
|
||||
pub mod lsm_iterator;
|
||||
pub mod lsm_storage;
|
||||
|
||||
@@ -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 {
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user