feat(code): add block cache

Signed-off-by: Alex Chi <iskyzh@gmail.com>
This commit is contained in:
Alex Chi
2022-12-24 18:07:18 -05:00
parent 86503ac58d
commit 51e075c1ed
10 changed files with 173 additions and 41 deletions

View File

@@ -13,6 +13,7 @@ use bytes::{Buf, Bytes};
pub use iterator::SsTableIterator;
use crate::block::Block;
use crate::lsm_storage::BlockCache;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct BlockMeta {
@@ -50,6 +51,7 @@ impl FileObject {
self.0.len() as u64
}
/// Create a new file object (day 2) and write the file to the disk (day 4).
pub fn create(path: &Path, data: Vec<u8>) -> Result<Self> {
unimplemented!()
}
@@ -66,8 +68,13 @@ pub struct SsTable {
}
impl SsTable {
#[cfg(test)]
pub(crate) fn open_for_test(file: FileObject) -> Result<Self> {
Self::open(0, None, file)
}
/// Open SSTable from a file.
pub fn open(file: FileObject) -> Result<Self> {
pub fn open(id: usize, block_cache: Option<Arc<BlockCache>>, file: FileObject) -> Result<Self> {
unimplemented!()
}
@@ -76,6 +83,11 @@ impl SsTable {
unimplemented!()
}
/// Read a block from disk, with block cache. (Day 4)
pub fn read_block_cached(&self, block_idx: usize) -> Result<Arc<Block>> {
unimplemented!()
}
/// Find the block that may contain `key`.
pub fn find_block_idx(&self, key: &[u8]) -> usize {
unimplemented!()