Struct PageCache

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

lock-free pagecache 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 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 = 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.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();
}

Implementations§

Source§

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

Source

pub fn new(pm: PM, config: Config) -> PageCache<PM, P, R>

Instantiate a new PageCache.

Source

pub fn config(&self) -> &Config

Return the configuration used by the underlying system.

Source

pub fn recover(&mut self) -> Option<R>

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

Source

pub fn allocate(&self) -> (usize, CasKey<P>)

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

Source

pub fn free(&self, pid: usize)

Free a particular page.

Source

pub fn get(&self, pid: usize) -> Option<(PM::PageFrag, CasKey<P>)>

Try to retrieve a page by its logical ID.

Source

pub fn set( &self, pid: usize, old: CasKey<P>, new: P, ) -> Result<CasKey<P>, Option<CasKey<P>>>

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.

Source

pub fn merge( &self, pid: usize, old: CasKey<P>, new: P, ) -> Result<CasKey<P>, Option<CasKey<P>>>

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§

Source§

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

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

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

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

Source§

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

Auto Trait Implementations§

§

impl<PM, P, R> !Freeze for PageCache<PM, P, R>

§

impl<PM, P, R> !RefUnwindSafe for PageCache<PM, P, R>

§

impl<PM, P, R> Unpin for PageCache<PM, P, R>
where PM: Unpin,

§

impl<PM, P, R> !UnwindSafe for PageCache<PM, P, R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.