21个版本
0.3.1 | 2024年2月6日 |
---|---|
0.3.0 | 2022年10月17日 |
0.2.5 | 2022年9月21日 |
0.2.4 | 2022年6月29日 |
0.1.3 | 2020年6月18日 |
#1018 在 数据库接口
用于 cordwood
57KB
1.5K SLoC
lib.rs
:
简单且模块化的预写日志实现。
示例
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(())}, 0)).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(())
}, 0)).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, 0)).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(())
}, 0)).unwrap();
// After each recovery, the ./walfiles is empty.
依赖项
~7–14MB
~164K SLoC