pagecache
A construction kit for databases. Provides a lock-free log store and pagecache.
References
use pagecache::{PagePtr, pin, Materializer};
pub struct TestMaterializer;
impl Materializer for TestMaterializer {
type PageFrag = String;
type Recovery = ();
fn new(last_recovery: &Option<Self::Recovery>) -> Self {
TestMaterializer
}
fn merge(&self, frags: &[&Self::PageFrag]) -> Self::PageFrag {
let mut consolidated = String::new();
for frag in frags.into_iter() {
consolidated.push_str(&*frag);
}
consolidated
}
fn recover(&self, _: &Self::PageFrag) -> Option<Self::Recovery> {
None
}
fn size_in_bytes(&self, frag: &String) -> usize {
std::mem::size_of::<String>() + frag.as_bytes().len()
}
}
fn main() {
let config = pagecache::ConfigBuilder::new().temporary(true);
let pc: pagecache::PageCache<TestMaterializer, _, _> =
pagecache::PageCache::start(config.build());
{
let guard = pin();
let id = pc.allocate(&guard);
let key = pc.replace(id, PagePtr::null(), "a".to_owned(), &guard).unwrap();
let key = pc.link(id, key, "b".to_owned(), &guard).unwrap();
let _key = pc.link(id, key, "c".to_owned(), &guard).unwrap();
let (consolidated, _key) = pc.get(id, &guard).unwrap();
assert_eq!(consolidated, "abc".to_owned());
}
}