BufferedRaftLog

Struct BufferedRaftLog 

Source
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,

Source

pub fn new( node_id: u32, persistence_config: PersistenceConfig, storage: Arc<<T as TypeConfig>::SE>, ) -> (BufferedRaftLog<T>, UnboundedReceiver<LogCommand>)

Source

pub fn start( self, receiver: UnboundedReceiver<LogCommand>, ) -> Arc<BufferedRaftLog<T>>

Start the command processor and return an Arc-wrapped instance

Source

pub async fn process_flush(&self, indexes: &[u64]) -> Result<(), Error>

Process entries for flush operation Separated to make error handling clearer

Source

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,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for BufferedRaftLog<T>
where T: TypeConfig,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> RaftLog for BufferedRaftLog<T>
where T: TypeConfig,

Source§

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

Returns the smallest log index (inclusive). Read more
Source§

fn last_entry_id(&self) -> u64

Returns the largest log index (inclusive). Read more
Source§

fn last_entry(&self) -> Option<Entry>

Returns the last log entry. Read more
Source§

fn last_log_id(&self) -> Option<LogId>

Returns the LogId (term + index) of the last entry. Read more
Source§

fn is_empty(&self) -> bool

Checks if log is empty. Read more
Source§

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>

Finds the first index belonging to a specific term. Read more
Source§

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

Pre-allocates the next log index atomically. Read more
Source§

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>

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,

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,

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,

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,

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>

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,

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,

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,

Resets the entire log storage (destructive operation). Read more
Source§

fn load_hard_state(&self) -> Result<Option<HardState>, Error>

Loads persistent state (currentTerm, votedFor). Read more
Source§

fn save_hard_state(&self, hard_state: &HardState) -> Result<(), Error>

Saves persistent state (currentTerm, votedFor). 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more