Struct sled::PageCache [] [src]

pub struct PageCache<PM, P, R> where
    PM: Materializer<PageFrag = P, Recovery = R>,
    PM: Send + Sync,
    P: 'static + Debug + PartialEq + Clone + Serialize + DeserializeOwned + Send + Sync,
    R: Debug + PartialEq + Clone + Serialize + DeserializeOwned + Send
{ /* fields omitted */ }

A lock-free pagecache which supports fragmented pages for dramatically improving write throughput.

Working with the PageCache

extern crate sled;

use sled::Materializer;

pub struct TestMaterializer;

impl Materializer for TestMaterializer {
    type PageFrag = String;
    type Recovery = ();

    fn merge(&self, frags: &[&String]) -> String {
        let mut consolidated = String::new();
        for frag in frags.into_iter() {
            consolidated.push_str(&*frag);
        }

        consolidated
    }

    fn recover(&self, _: &String) -> Option<()> {
        None
    }
}

fn main() {
    let path = "test_pagecache_doc.log";
    let conf = sled::Config::default().path(path.to_owned());
    let pc = sled::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.set(id, key, "a".to_owned()).unwrap();
    let key = pc.merge(id, key, "b".to_owned()).unwrap();
    let _key = pc.merge(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, P, R> where
    PM: Materializer<PageFrag = P, Recovery = R>,
    PM: Send + Sync,
    P: 'static + Debug + PartialEq + Clone + Serialize + DeserializeOwned + Send + Sync,
    R: Debug + PartialEq + Clone + Serialize + DeserializeOwned + Send
[src]

[src]

Instantiate a new PageCache.

[src]

Return the configuration used by the underlying system.

[src]

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

[src]

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

[src]

Free a particular page.

[src]

Try to retrieve a page by its logical ID.

[src]

Replace an existing page with a different set of PageFrags. Returns Ok(new_key) if the operation was successful. Returns Err(None) if the page no longer exists. Returns Err(Some(actual_key)) if the page has changed since the provided CasKey was created.

[src]

Try to atomically add a PageFrag to the page. Returns Ok(new_key) if the operation was successful. Returns Err(None) if the page no longer exists. Returns Err(Some(actual_key)) if the page has changed since the provided CasKey was created.

Trait Implementations

impl<PM, P, R> Drop for PageCache<PM, P, R> where
    PM: Materializer<PageFrag = P, Recovery = R>,
    PM: Send + Sync,
    P: 'static + Debug + PartialEq + Clone + Serialize + DeserializeOwned + Send + Sync,
    R: Debug + PartialEq + Clone + Serialize + DeserializeOwned + Send
[src]

[src]

Executes the destructor for this type. Read more

impl<PM, P, R> Send for PageCache<PM, P, R> where
    PM: Materializer<PageFrag = P, Recovery = R>,
    PM: Send + Sync,
    P: 'static + Debug + PartialEq + Clone + Serialize + DeserializeOwned + Send + Sync,
    R: Debug + PartialEq + Clone + Serialize + DeserializeOwned + Send
[src]

impl<PM, P, R> Sync for PageCache<PM, P, R> where
    PM: Materializer<PageFrag = P, Recovery = R>,
    PM: Send + Sync,
    P: 'static + Debug + PartialEq + Clone + Serialize + DeserializeOwned + Send + Sync,
    R: Debug + PartialEq + Clone + Serialize + DeserializeOwned + Send
[src]

impl<PM, P, R> Debug for PageCache<PM, P, R> where
    PM: Materializer<PageFrag = P, Recovery = R>,
    PM: Send + Sync,
    P: 'static + Debug + PartialEq + Clone + Serialize + DeserializeOwned + Send + Sync,
    R: Debug + PartialEq + Clone + Serialize + DeserializeOwned + Send
[src]

[src]

Formats the value using the given formatter.