Crates.io | raft-log |
lib.rs | raft-log |
version | 0.2.10 |
created_at | 2024-10-31 01:36:47.298877+00 |
updated_at | 2025-05-17 13:44:50.764503+00 |
description | Raft log implementation |
homepage | https://github.com/drmingdrmer/raft-log |
repository | https://github.com/drmingdrmer/raft-log |
max_upload_size | |
id | 1429500 |
size | 343,710 |
Log Storage for raft
A high-performance, reliable local disk-based log storage implementation for the raft consensus protocol.
See basic usage example for a complete demonstration of core functionality, including:
Basic usage:
use raft_log::{RaftLog, Config};
// Define your application-specific types
impl Types for MyTypes {
type LogId = (u64, u64); // (term, index)
type LogPayload = String; // Log entry data
type Vote = (u64, u64); // (term, voted_for)
type UserData = String; // Custom user data
type Callback = SyncSender<io::Result<()>>;
}
// Open a RaftLog instance
let config = Arc::new(Config::default());
let mut raft_log = RaftLog::<MyTypes>::open(config)?;
// Save vote information
raft_log.save_vote((1, 2))?; // Voted for node-2 in term 1
// Append log entries
let entries = vec![
((1, 1), "first entry".to_string()),
((1, 2), "second entry".to_string()),
];
raft_log.append(entries)?;
// Update commit index
raft_log.commit((1, 2))?;
// Flush changes to disk with callback
let (tx, rx) = sync_channel(1);
raft_log.flush(tx)?;
rx.recv().unwrap()?;
For more examples and detailed documentation, see the examples directory.
This project is licensed under the Apache License, Version 2.0.