#logging #raft

bin+lib raft-log

Raft log implementation

13 releases

0.2.11 Oct 19, 2025
0.2.10 May 17, 2025
0.2.7 Feb 21, 2025
0.2.6 Dec 12, 2024
0.1.0 Oct 31, 2024

#259 in Data structures

Download history 560/week @ 2025-07-29 527/week @ 2025-08-05 704/week @ 2025-08-12 736/week @ 2025-08-19 1155/week @ 2025-08-26 613/week @ 2025-09-02 995/week @ 2025-09-09 608/week @ 2025-09-16 584/week @ 2025-09-23 334/week @ 2025-09-30 229/week @ 2025-10-07 710/week @ 2025-10-14 418/week @ 2025-10-21 544/week @ 2025-10-28 672/week @ 2025-11-04 497/week @ 2025-11-11

2,305 downloads per month

MIT/Apache

190KB
4.5K SLoC

raft-log

Log Storage for raft

A high-performance, reliable local disk-based log storage implementation for the raft consensus protocol.

Features

  • Type-safe API with generic types for log entries, vote information, and user data
  • Asynchronous write operations with callback support
  • Efficient batch processing and disk I/O
  • Core raft operations support:
    • Vote persistence for election safety
    • Log entry append for replication
    • Commit index management
    • Log entry reads for state machine application

Example

See basic usage example for a complete demonstration of core functionality, including:

  • Creating and opening a raft log store
  • Saving vote information during elections
  • Appending log entries (as a leader or follower)
  • Updating commit index
  • Reading committed entries
  • Getting current log state
  • Using asynchronous flush with callbacks

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.

License

This project is licensed under the Apache License, Version 2.0.

Dependencies

~11MB
~139K SLoC