2022-12-24 14:48:57 -05:00
|
|
|
#![allow(unused_variables)] // TODO(you): remove this lint after implementing this mod
|
|
|
|
|
#![allow(dead_code)] // TODO(you): remove this lint after implementing this mod
|
|
|
|
|
|
2022-12-24 10:11:06 -05:00
|
|
|
use std::ops::Bound;
|
|
|
|
|
use std::path::Path;
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
use arc_swap::ArcSwap;
|
|
|
|
|
use bytes::Bytes;
|
|
|
|
|
|
2022-12-24 18:07:18 -05:00
|
|
|
use crate::block::Block;
|
2022-12-24 14:48:57 -05:00
|
|
|
use crate::lsm_iterator::{FusedIterator, LsmIterator};
|
2022-12-24 10:11:06 -05:00
|
|
|
use crate::mem_table::MemTable;
|
2022-12-24 14:48:57 -05:00
|
|
|
use crate::table::SsTable;
|
2022-12-24 10:11:06 -05:00
|
|
|
|
2022-12-24 18:07:18 -05:00
|
|
|
pub type BlockCache = moka::sync::Cache<(usize, usize), Arc<Block>>;
|
|
|
|
|
|
2022-12-24 14:48:57 -05:00
|
|
|
#[derive(Clone)]
|
2022-12-24 10:11:06 -05:00
|
|
|
pub struct LsmStorageInner {
|
2022-12-24 14:48:57 -05:00
|
|
|
/// MemTables, from oldest to earliest.
|
2022-12-24 10:11:06 -05:00
|
|
|
memtables: Vec<Arc<MemTable>>,
|
2022-12-24 14:48:57 -05:00
|
|
|
/// L0 SsTables, from oldest to earliest.
|
|
|
|
|
l0_sstables: Vec<Arc<SsTable>>,
|
2022-12-24 10:11:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl LsmStorageInner {
|
|
|
|
|
fn create() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
memtables: vec![Arc::new(MemTable::create())],
|
2022-12-24 14:48:57 -05:00
|
|
|
l0_sstables: vec![],
|
2022-12-24 10:11:06 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The storage interface of the LSM tree.
|
|
|
|
|
pub struct LsmStorage {
|
|
|
|
|
inner: ArcSwap<LsmStorageInner>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl LsmStorage {
|
2022-12-24 18:12:57 -05:00
|
|
|
pub fn open(path: impl AsRef<Path>) -> Result<Self> {
|
2022-12-24 10:11:06 -05:00
|
|
|
Ok(Self {
|
|
|
|
|
inner: ArcSwap::from_pointee(LsmStorageInner::create()),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn get(&self, key: &[u8]) -> Result<Option<Bytes>> {
|
2022-12-24 14:48:57 -05:00
|
|
|
unimplemented!()
|
2022-12-24 10:11:06 -05:00
|
|
|
}
|
|
|
|
|
|
2022-12-24 18:12:57 -05:00
|
|
|
pub fn put(&self, key: &[u8], value: &[u8]) -> Result<()> {
|
2022-12-24 10:11:06 -05:00
|
|
|
assert!(!value.is_empty(), "value cannot be empty");
|
|
|
|
|
assert!(!key.is_empty(), "key cannot be empty");
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-24 18:12:57 -05:00
|
|
|
pub fn delete(&self, _key: &[u8]) -> Result<()> {
|
2022-12-24 10:11:06 -05:00
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-24 18:12:57 -05:00
|
|
|
pub fn sync(&self) -> Result<()> {
|
2022-12-24 10:11:06 -05:00
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-24 14:48:57 -05:00
|
|
|
pub fn scan(
|
|
|
|
|
&self,
|
|
|
|
|
_lower: Bound<&[u8]>,
|
|
|
|
|
_upper: Bound<&[u8]>,
|
|
|
|
|
) -> Result<FusedIterator<LsmIterator>> {
|
2022-12-24 10:11:06 -05:00
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
}
|