pub struct RedbLogStore { /* private fields */ }Expand description
redb-backed Raft log storage
This is a pure Rust implementation that:
- Has zero C/C++ dependencies
- Compiles for any target (including musl)
- Provides ACID transactions
- Uses B-tree for efficient ordered access
§Performance Characteristics
- Write: O(log n) per entry, batched for throughput
- Read: O(log n) point lookup, O(k) range scan for k entries
- Space: ~1.5x raw data size (B-tree overhead)
For Raft workloads (append-heavy with sequential reads), this provides excellent performance with the benefit of pure Rust simplicity.
Implementations§
Source§impl RedbLogStore
impl RedbLogStore
Sourcepub fn new(path: impl AsRef<Path>) -> Result<Self>
pub fn new(path: impl AsRef<Path>) -> Result<Self>
Create new redb log storage at the given path
Creates the directory if it doesn’t exist.
Sourcepub fn is_cache_stale(&self) -> bool
pub fn is_cache_stale(&self) -> bool
Check whether this instance’s cached metadata is still current.
Returns true when the shared write-version counter has advanced
past the version observed at clone-time, indicating that the
parent store has been mutated (vote, committed, purge, etc.).
The primary store (snapshot_version == None) is always authoritative.
Sourcepub async fn refresh_cache_if_stale(&self)
pub async fn refresh_cache_if_stale(&self)
Reload cached metadata (vote, last_purged, committed) from the database if the cache is stale. No-op on the primary store.
Trait Implementations§
Source§impl RaftLogReader<TypeConfig> for RedbLogStore
impl RaftLogReader<TypeConfig> for RedbLogStore
Source§async fn try_get_log_entries<RB: RangeBounds<u64> + Clone + Debug + Send>(
&mut self,
range: RB,
) -> Result<Vec<RaftEntry>, StorageError<NodeId>>
async fn try_get_log_entries<RB: RangeBounds<u64> + Clone + Debug + Send>( &mut self, range: RB, ) -> Result<Vec<RaftEntry>, StorageError<NodeId>>
Use a single read transaction with range iteration instead
of opening a separate transaction per entry via get_log().
Source§fn limited_get_log_entries(
&mut self,
start: u64,
end: u64,
) -> impl Future<Output = Result<Vec<<C as RaftTypeConfig>::Entry>, StorageError<<C as RaftTypeConfig>::NodeId>>> + Send
fn limited_get_log_entries( &mut self, start: u64, end: u64, ) -> impl Future<Output = Result<Vec<<C as RaftTypeConfig>::Entry>, StorageError<<C as RaftTypeConfig>::NodeId>>> + Send
[start, end), end is exclusive,
potentially limited by implementation-defined constraints. Read moreSource§impl RaftLogStorage<TypeConfig> for RedbLogStore
impl RaftLogStorage<TypeConfig> for RedbLogStore
Source§type LogReader = RedbLogStore
type LogReader = RedbLogStore
Source§async fn get_log_state(
&mut self,
) -> Result<LogState<TypeConfig>, StorageError<NodeId>>
async fn get_log_state( &mut self, ) -> Result<LogState<TypeConfig>, StorageError<NodeId>>
Source§async fn get_log_reader(&mut self) -> Self::LogReader
async fn get_log_reader(&mut self) -> Self::LogReader
Source§async fn save_vote(
&mut self,
vote: &RaftVote,
) -> Result<(), StorageError<NodeId>>
async fn save_vote( &mut self, vote: &RaftVote, ) -> Result<(), StorageError<NodeId>>
Source§async fn read_vote(&mut self) -> Result<Option<RaftVote>, StorageError<NodeId>>
async fn read_vote(&mut self) -> Result<Option<RaftVote>, StorageError<NodeId>>
Self::save_vote.Source§async fn save_committed(
&mut self,
committed: Option<RaftLogId>,
) -> Result<(), StorageError<NodeId>>
async fn save_committed( &mut self, committed: Option<RaftLogId>, ) -> Result<(), StorageError<NodeId>>
Source§async fn read_committed(
&mut self,
) -> Result<Option<RaftLogId>, StorageError<NodeId>>
async fn read_committed( &mut self, ) -> Result<Option<RaftLogId>, StorageError<NodeId>>
Self::save_committed.Source§async fn append<I>(
&mut self,
entries: I,
callback: LogFlushed<TypeConfig>,
) -> Result<(), StorageError<NodeId>>
async fn append<I>( &mut self, entries: I, callback: LogFlushed<TypeConfig>, ) -> Result<(), StorageError<NodeId>>
callback once logs are persisted on disk. Read moreAuto Trait Implementations§
impl !Freeze for RedbLogStore
impl !RefUnwindSafe for RedbLogStore
impl Send for RedbLogStore
impl Sync for RedbLogStore
impl Unpin for RedbLogStore
impl UnsafeUnpin for RedbLogStore
impl !UnwindSafe for RedbLogStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<C, LR> RaftLogReaderExt<C> for LRwhere
C: RaftTypeConfig,
LR: RaftLogReader<C>,
impl<C, LR> RaftLogReaderExt<C> for LRwhere
C: RaftTypeConfig,
LR: RaftLogReader<C>,
Source§fn try_get_log_entry(
&mut self,
log_index: u64,
) -> impl Future<Output = Result<Option<<C as RaftTypeConfig>::Entry>, StorageError<<C as RaftTypeConfig>::NodeId>>> + Send
fn try_get_log_entry( &mut self, log_index: u64, ) -> impl Future<Output = Result<Option<<C as RaftTypeConfig>::Entry>, StorageError<<C as RaftTypeConfig>::NodeId>>> + Send
Source§fn get_log_entries<RB>(
&mut self,
range: RB,
) -> impl Future<Output = Result<Vec<<C as RaftTypeConfig>::Entry>, StorageError<<C as RaftTypeConfig>::NodeId>>> + Send
fn get_log_entries<RB>( &mut self, range: RB, ) -> impl Future<Output = Result<Vec<<C as RaftTypeConfig>::Entry>, StorageError<<C as RaftTypeConfig>::NodeId>>> + Send
Source§fn get_log_id(
&mut self,
log_index: u64,
) -> impl Future<Output = Result<LogId<<C as RaftTypeConfig>::NodeId>, StorageError<<C as RaftTypeConfig>::NodeId>>> + Send
fn get_log_id( &mut self, log_index: u64, ) -> impl Future<Output = Result<LogId<<C as RaftTypeConfig>::NodeId>, StorageError<<C as RaftTypeConfig>::NodeId>>> + Send
index.