56 个版本 (16 个重大更改)

0.19.4 2019年9月10日
0.19.1 2019年8月27日
0.17.0 2019年5月12日
0.13.1 2019年3月31日
0.4.2 2018年3月9日

#114数据库实现

Download history 142/week @ 2024-03-11 98/week @ 2024-03-18 76/week @ 2024-03-25 374/week @ 2024-04-01 96/week @ 2024-04-08 99/week @ 2024-04-15 78/week @ 2024-04-22 77/week @ 2024-04-29 60/week @ 2024-05-06 80/week @ 2024-05-13 140/week @ 2024-05-20 90/week @ 2024-05-27 91/week @ 2024-06-03 70/week @ 2024-06-10 137/week @ 2024-06-17 76/week @ 2024-06-24

每月386次下载
14 个crate中使用(通过 索引

MIT/Apache

315KB
7.5K SLoC

pagecache

Build Status documentation

数据库构建工具包。提供无锁日志存储和页缓存。

参考资料

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());
    }
}

依赖项

~2–4.5MB
~82K SLoC