Struct rsdb::PageCache
[−]
[src]
pub struct PageCache<PM, L, P, R> { /* fields omitted */ }
A lock-free pagecache which supports fragmented pages for dramatically improving write throughput.
Working with the PageCache
extern crate rsdb; use rsdb::Materializer; pub struct TestMaterializer; impl Materializer for TestMaterializer { type MaterializedPage = String; type PartialPage = String; type Recovery = (); fn materialize(&self, frags: &[String]) -> String { self.consolidate(frags).pop().unwrap() } fn consolidate(&self, frags: &[String]) -> Vec<String> { let mut consolidated = String::new(); for frag in frags.into_iter() { consolidated.push_str(&*frag); } vec![consolidated] } fn recover(&self, _: &String) -> Option<()> { None } } fn main() { let path = "test_pagecache_doc.log"; let conf = rsdb::Config::default().path(Some(path.to_owned())); let pc = rsdb::PageCache::new(TestMaterializer, conf.clone()); let (id, key) = pc.allocate(); // The first item in a page should be set using replace, which // signals that this is the beginning of a new page history, and // that any previous items associated with this page should be // forgotten. let key = pc.replace(id, key, vec!["a".to_owned()]).unwrap(); let key = pc.prepend(id, key, "b".to_owned()).unwrap(); let _key = pc.prepend(id, key, "c".to_owned()).unwrap(); let (consolidated, _key) = pc.get(id).unwrap(); assert_eq!(consolidated, "abc".to_owned()); drop(pc); std::fs::remove_file(path).unwrap(); }
Methods
impl<PM, P, R> PageCache<PM, LockFreeLog, P, R> where
PM: Materializer<PartialPage = P, Recovery = R>,
PM: Send + Sync,
P: Debug + PartialEq + Clone + Serialize + DeserializeOwned + Send,
R: Debug + PartialEq + Clone + Serialize + DeserializeOwned,
PM::MaterializedPage: Debug,
[src]
PM: Materializer<PartialPage = P, Recovery = R>,
PM: Send + Sync,
P: Debug + PartialEq + Clone + Serialize + DeserializeOwned + Send,
R: Debug + PartialEq + Clone + Serialize + DeserializeOwned,
PM::MaterializedPage: Debug,
fn new(pm: PM, config: Config) -> PageCache<PM, LockFreeLog, P, R>
Instantiate a new PageCache
.
fn config(&self) -> &Config
Return the configuration used by the underlying system.
fn recover(&mut self) -> Option<R>
Read updates from the log, apply them to our pagecache.
fn allocate(&self) -> (usize, CasKey<P>)
Create a new page, trying to reuse old freed pages if possible
to maximize underlying Radix
pointer density.
fn free(&self, pid: usize)
Free a particular page.
fn get(&self, pid: usize) -> Option<(PM::MaterializedPage, CasKey<P>)>
Try to retrieve a page by its logical ID.
fn replace(
&self,
pid: usize,
old: CasKey<P>,
new: Vec<P>
) -> Result<CasKey<P>, CasKey<P>>
&self,
pid: usize,
old: CasKey<P>,
new: Vec<P>
) -> Result<CasKey<P>, CasKey<P>>
Replace an existing page with a different set of PartialPage
s.
fn prepend(
&self,
pid: usize,
old: CasKey<P>,
new: P
) -> Result<CasKey<P>, CasKey<P>>
&self,
pid: usize,
old: CasKey<P>,
new: P
) -> Result<CasKey<P>, CasKey<P>>
Try to atomically prepend a Materializer::PartialPage
to the page.
Trait Implementations
impl<PM, L, P, R> Drop for PageCache<PM, L, P, R>
[src]
impl<PM, L, P, R> Send for PageCache<PM, L, P, R> where
PM: Send,
L: Send,
R: Send,
[src]
PM: Send,
L: Send,
R: Send,
impl<PM, L, P, R> Sync for PageCache<PM, L, P, R> where
PM: Sync,
L: Sync,
[src]
PM: Sync,
L: Sync,