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]

Instantiate a new PageCache.

Return the configuration used by the underlying system.

Read updates from the log, apply them to our pagecache.

Create a new page, trying to reuse old freed pages if possible to maximize underlying Radix pointer density.

Free a particular page.

Try to retrieve a page by its logical ID.

Replace an existing page with a different set of PartialPages.

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]

A method called when the value goes out of scope. Read more

impl<PM, L, P, R> Send for PageCache<PM, L, P, R> where
    PM: Send,
    L: Send,
    R: Send
[src]

impl<PM, L, P, R> Sync for PageCache<PM, L, P, R> where
    PM: Sync,
    L: Sync
[src]

impl<PM, L, P, R> Debug for PageCache<PM, L, P, R>
[src]

Formats the value using the given formatter.