pub struct BufferedRaftLog<T>where
T: TypeConfig,{ /* private fields */ }Expand description
High-performance buffered Raft log with event-driven architecture
This implementation provides in-memory first access with configurable persistence strategies while ensuring thread safety and avoiding deadlocks.
Key design principles:
- Lock-free reads for 99% of operations
- Event-driven asynchronous processing
- Deadlock prevention through proper error handling
- Memory-efficient batch operations
Implementations§
Source§impl<T> BufferedRaftLog<T>where
T: TypeConfig,
impl<T> BufferedRaftLog<T>where
T: TypeConfig,
Sourcepub fn start(
self,
receiver: UnboundedReceiver<LogCommand>,
) -> Arc<BufferedRaftLog<T>>
pub fn start( self, receiver: UnboundedReceiver<LogCommand>, ) -> Arc<BufferedRaftLog<T>>
Start the command processor and return an Arc-wrapped instance
Sourcepub async fn process_flush(&self, indexes: &[u64]) -> Result<(), Error>
pub async fn process_flush(&self, indexes: &[u64]) -> Result<(), Error>
Process entries for flush operation Separated to make error handling clearer
Sourcepub fn remove_range(&self, range: RangeInclusive<u64>)
pub fn remove_range(&self, range: RangeInclusive<u64>)
Efficient range removal with targeted term index updates O(k + t) where k = number of entries removed, t = number of affected terms
Trait Implementations§
Source§impl<T> Debug for BufferedRaftLog<T>where
T: TypeConfig,
impl<T> Debug for BufferedRaftLog<T>where
T: TypeConfig,
Source§impl<T> Drop for BufferedRaftLog<T>where
T: TypeConfig,
impl<T> Drop for BufferedRaftLog<T>where
T: TypeConfig,
Source§impl<T> RaftLog for BufferedRaftLog<T>where
T: TypeConfig,
impl<T> RaftLog for BufferedRaftLog<T>where
T: TypeConfig,
Source§fn entry(&self, index: u64) -> Result<Option<Entry>, Error>
fn entry(&self, index: u64) -> Result<Option<Entry>, Error>
TODO: not considered the order of configured storage rule also should we remove Result<>?
Source§fn first_entry_id(&self) -> u64
fn first_entry_id(&self) -> u64
Returns the smallest log index (inclusive). Read more
Source§fn last_entry_id(&self) -> u64
fn last_entry_id(&self) -> u64
Returns the largest log index (inclusive). Read more
Source§fn last_log_id(&self) -> Option<LogId>
fn last_log_id(&self) -> Option<LogId>
Returns the LogId (term + index) of the last entry. Read more
Source§fn entry_term(&self, entry_id: u64) -> Option<u64>
fn entry_term(&self, entry_id: u64) -> Option<u64>
Returns the term of a specific entry. Read more
Source§fn first_index_for_term(&self, term: u64) -> Option<u64>
fn first_index_for_term(&self, term: u64) -> Option<u64>
Finds the first index belonging to a specific term. Read more
Source§fn last_index_for_term(&self, term: u64) -> Option<u64>
fn last_index_for_term(&self, term: u64) -> Option<u64>
Finds the last index belonging to a specific term. Read more
Source§fn pre_allocate_raft_logs_next_index(&self) -> u64
fn pre_allocate_raft_logs_next_index(&self) -> u64
Pre-allocates the next log index atomically. Read more
Source§fn pre_allocate_id_range(&self, count: u64) -> RangeInclusive<u64>
fn pre_allocate_id_range(&self, count: u64) -> RangeInclusive<u64>
Pre-allocates a contiguous range of log indices atomically. Read more
Source§fn get_entries_range(
&self,
range: RangeInclusive<u64>,
) -> Result<Vec<Entry>, Error>
fn get_entries_range( &self, range: RangeInclusive<u64>, ) -> Result<Vec<Entry>, Error>
Retrieves a contiguous range of log entries. Read more
Source§fn append_entries<'life0, 'async_trait>(
&'life0 self,
entries: Vec<Entry>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
BufferedRaftLog<T>: 'async_trait,
fn append_entries<'life0, 'async_trait>(
&'life0 self,
entries: Vec<Entry>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
BufferedRaftLog<T>: 'async_trait,
Appends new entries to the log. Read more
Source§fn wait_durable<'life0, 'async_trait>(
&'life0 self,
index: u64,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
BufferedRaftLog<T>: 'async_trait,
fn wait_durable<'life0, 'async_trait>(
&'life0 self,
index: u64,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
BufferedRaftLog<T>: 'async_trait,
Waits for a specific log index to become durable. Read more
Source§fn insert_batch<'life0, 'async_trait>(
&'life0 self,
logs: Vec<Entry>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
BufferedRaftLog<T>: 'async_trait,
fn insert_batch<'life0, 'async_trait>(
&'life0 self,
logs: Vec<Entry>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
BufferedRaftLog<T>: 'async_trait,
Alias for append_entries (for backward compatibility). Read more
Source§fn filter_out_conflicts_and_append<'life0, 'async_trait>(
&'life0 self,
prev_log_index: u64,
prev_log_term: u64,
new_entries: Vec<Entry>,
) -> Pin<Box<dyn Future<Output = Result<Option<LogId>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
BufferedRaftLog<T>: 'async_trait,
fn filter_out_conflicts_and_append<'life0, 'async_trait>(
&'life0 self,
prev_log_index: u64,
prev_log_term: u64,
new_entries: Vec<Entry>,
) -> Pin<Box<dyn Future<Output = Result<Option<LogId>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
BufferedRaftLog<T>: 'async_trait,
Resolves log conflicts and appends new entries atomically. Read more
Source§fn calculate_majority_matched_index(
&self,
current_term: u64,
commit_index: u64,
peer_matched_ids: Vec<u64>,
) -> Option<u64>
fn calculate_majority_matched_index( &self, current_term: u64, commit_index: u64, peer_matched_ids: Vec<u64>, ) -> Option<u64>
Calculates the majority-matched index for commit advancement. Read more
Source§fn purge_logs_up_to<'life0, 'async_trait>(
&'life0 self,
cutoff_index: LogId,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
BufferedRaftLog<T>: 'async_trait,
fn purge_logs_up_to<'life0, 'async_trait>(
&'life0 self,
cutoff_index: LogId,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
BufferedRaftLog<T>: 'async_trait,
Purges committed log entries up to cutoff_index (log compaction). Read more
Source§fn flush<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
BufferedRaftLog<T>: 'async_trait,
fn flush<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
BufferedRaftLog<T>: 'async_trait,
Forces all pending writes to durable storage. Read more
Source§fn reset<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
BufferedRaftLog<T>: 'async_trait,
fn reset<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
BufferedRaftLog<T>: 'async_trait,
Resets the entire log storage (destructive operation). Read more
Auto Trait Implementations§
impl<T> !Freeze for BufferedRaftLog<T>
impl<T> !RefUnwindSafe for BufferedRaftLog<T>
impl<T> Send for BufferedRaftLog<T>
impl<T> Sync for BufferedRaftLog<T>
impl<T> Unpin for BufferedRaftLog<T>
impl<T> !UnwindSafe for BufferedRaftLog<T>
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
Mutably borrows from an owned value. Read more
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request