#wal #db #futures

growth-ring

Simple and modular write-ahead-logging implementation

17 releases

new 0.2.3 Jan 19, 2021
0.2.2 Jan 13, 2021
0.1.12 Jan 8, 2021
0.1.10 Dec 31, 2020
0.1.3 Jun 18, 2020

#214 in Database interfaces

Download history 6/week @ 2020-10-01 18/week @ 2020-10-08 9/week @ 2020-10-15 12/week @ 2020-10-22 25/week @ 2020-10-29 24/week @ 2020-11-05 1/week @ 2020-11-19 13/week @ 2020-11-26 10/week @ 2020-12-03 4/week @ 2020-12-10 33/week @ 2020-12-24 58/week @ 2020-12-31 83/week @ 2021-01-07 72/week @ 2021-01-14

105 downloads per month

MIT license

39KB
936 lines

growth-ring

https://travis-ci.com/ava-labs/growth-ring.svg?token=EbLxqxy3qxjHrZKkyoP4&branch=master

Documentation


lib.rs:

Simple and modular write-ahead-logging implementation.

Examples

use growthring::{WALStoreAIO, wal::WALLoader};
use futures::executor::block_on;
let mut loader = WALLoader::new();
loader.file_nbit(9).block_nbit(8);


// Start with empty WAL (truncate = true).
let store = WALStoreAIO::new("./walfiles", true, None, None).unwrap();
let mut wal = block_on(loader.load(store, |_, _| {Ok(())})).unwrap();
// Write a vector of records to WAL.
for f in wal.grow(vec!["record1(foo)", "record2(bar)", "record3(foobar)"]).into_iter() {
    let ring_id = block_on(f).unwrap().1;
    println!("WAL recorded record to {:?}", ring_id);
}


// Load from WAL (truncate = false).
let store = WALStoreAIO::new("./walfiles", false, None, None).unwrap();
let mut wal = block_on(loader.load(store, |payload, ringid| {
    // redo the operations in your application
    println!("recover(payload={}, ringid={:?})",
             std::str::from_utf8(&payload).unwrap(),
             ringid);
    Ok(())
})).unwrap();
// We saw some log playback, even there is no failure.
// Let's try to grow the WAL to create many files.
let ring_ids = wal.grow((1..100).into_iter().map(|i| "a".repeat(i)).collect::<Vec<_>>())
                  .into_iter().map(|f| block_on(f).unwrap().1).collect::<Vec<_>>();
// Then assume all these records are not longer needed. We can tell WALWriter by the `peel`
// method.
block_on(wal.peel(ring_ids)).unwrap();
// There will only be one remaining file in ./walfiles.

let store = WALStoreAIO::new("./walfiles", false, None, None).unwrap();
let wal = block_on(loader.load(store, |payload, _| {
    println!("payload.len() = {}", payload.len());
    Ok(())
})).unwrap();
// After each recovery, the ./walfiles is empty.

Dependencies

~5.5MB
~123K SLoC