56 releases (16 breaking)

✓ Uses Rust 2018 edition

0.19.4 Sep 10, 2019
0.19.1 Aug 27, 2019
0.17.0 May 12, 2019
0.13.1 Mar 31, 2019
0.4.2 Mar 9, 2018

#4 in Database implementations

Download history 766/week @ 2019-05-28 556/week @ 2019-06-04 349/week @ 2019-06-11 449/week @ 2019-06-18 740/week @ 2019-06-25 533/week @ 2019-07-02 335/week @ 2019-07-09 295/week @ 2019-07-16 271/week @ 2019-07-23 393/week @ 2019-07-30 573/week @ 2019-08-06 495/week @ 2019-08-13 1437/week @ 2019-08-20 624/week @ 2019-08-27 745/week @ 2019-09-03

2,390 downloads per month
Used in 24 crates (2 directly)

MIT/Apache

310KB
7.5K SLoC

pagecache

Build Status crates.io documentation

A construction kit for databases. Provides a lock-free log store and pagecache.

References

use {
    pagecache::{pin, Materializer, Config},
    serde::{Serialize, Deserialize},
};


#[derive(
    Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Serialize, Deserialize,
)]
pub struct TestState(String);

impl Materializer for TestState {
    // Used to merge chains of partial pages into a form
    // that is useful for the `PageCache` owner.
    fn merge(&mut self, other: &TestState) {
        self.0.push_str(&other.0);
    }
}

fn main() {
    let config = pagecache::ConfigBuilder::new().temporary(true).build();
    let pc: pagecache::PageCache<TestState> =
        pagecache::PageCache::start(config).unwrap();
    {
        // We begin by initiating a new transaction, which
        // will prevent any witnessable memory from being
        // reclaimed before we drop this object.
        let tx = pc.begin().unwrap();

        // The first item in a page should be set using allocate,
        // which signals that this is the beginning of a new
        // page history.
        let (id, mut key) = pc.allocate(TestState("a".to_owned()), &tx).unwrap();

        // Subsequent atomic updates should be added with link.
        key = pc.link(id, key, TestState("b".to_owned()), &tx).unwrap().unwrap();
        key = pc.link(id, key, TestState("c".to_owned()), &tx).unwrap().unwrap();

        // When getting a page, the provided `Materializer` is
        // used to merge all pages together.
        let (mut key, page, size_on_disk) = pc.get(id, &tx).unwrap().unwrap();

        assert_eq!(page.0, "abc".to_owned());

        // You can completely rewrite a page by using `replace`:
        key = pc.replace(id, key, TestState("d".into()), &tx).unwrap().unwrap();

        let (key, page, size_on_disk) = pc.get(id, &tx).unwrap().unwrap();

         assert_eq!(page.0, "d".to_owned());
    }
}

Dependencies

~1.9–3.5MB
~71K SLoC