Skip to main content

RocksDBStateMachine

Struct RocksDBStateMachine 

Source
pub struct RocksDBStateMachine { /* private fields */ }
Expand description

RocksDB-based state machine implementation with lease support

Implementations§

Source§

impl RocksDBStateMachine

Source

pub fn new<P>(path: P) -> Result<RocksDBStateMachine, Error>
where P: AsRef<Path>,

Opens (or creates) a dedicated RocksDB instance for state machine storage.

Used when unified_db = false (default): each engine owns its own DB instance.

Source

pub fn set_lease(&mut self, lease: Arc<DefaultLease>)

Sets the lease manager for this state machine.

This is an internal method called by NodeBuilder during initialization. The lease will also be restored from snapshot during apply_snapshot_from_file(). Also available for testing and benchmarks.

Source

pub async fn load_lease_data(&self) -> Result<(), Error>

Loads TTL state from RocksDB metadata after lease injection.

Called after NodeBuilder injects the lease. Also available for testing and benchmarks.

Source

pub fn scan_prefix(&self, prefix: &[u8]) -> Result<ScanResult, Error>

Scans all entries whose key starts with prefix.

Uses set_iterate_upper_bound(prefix_successor) so RocksDB stops at the block level — O(results), not O(total keys). No prefix_extractor needed. revision in the result equals last_applied_index — the watch-filter anchor.

Trait Implementations§

Source§

impl Debug for RocksDBStateMachine

Source§

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

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

impl Drop for RocksDBStateMachine

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl StateMachine for RocksDBStateMachine

Source§

fn apply_chunk<'life0, 'life1, 'async_trait>( &'life0 self, chunk: &'life1 [ApplyEntry], ) -> Pin<Box<dyn Future<Output = Result<Vec<ApplyResult>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, RocksDBStateMachine: 'async_trait,

Thread-safe: called serially by single-task CommitHandler

Source§

fn start<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, RocksDBStateMachine: 'async_trait,

Starts the state machine service. Read more
Source§

fn stop(&self) -> Result<(), Error>

Stops the state machine service gracefully. This is typically a sync operation for state management.
Source§

fn is_running(&self) -> bool

Checks if the state machine is currently running. Sync operation as it just checks an atomic boolean.
Source§

fn get(&self, key_buffer: &[u8]) -> Result<Option<Bytes>, Error>

Retrieves a value by key from the state machine. Sync operation as it accesses in-memory data structures.
Source§

fn entry_term(&self, _entry_id: u64) -> Option<u64>

Returns the term of a specific log entry by its ID. Sync operation as it queries in-memory data.
Source§

fn len(&self) -> usize

Returns the number of entries in the state machine. NOTE: This may be expensive for some implementations. Sync operation but should be used cautiously.
Source§

fn update_last_applied(&self, last_applied: LogId)

Updates the last applied index in memory. Sync operation as it just updates atomic variables.
Source§

fn last_applied(&self) -> LogId

Gets the last applied log index and term. Sync operation as it reads from atomic variables.
Source§

fn persist_last_applied(&self, last_applied: LogId) -> Result<(), Error>

Persists the last applied index to durable storage. Should be async as it involves disk I/O.
Source§

fn update_last_snapshot_metadata( &self, snapshot_metadata: &SnapshotMetadata, ) -> Result<(), Error>

Updates snapshot metadata in memory. Sync operation as it updates in-memory structures.
Source§

fn snapshot_metadata(&self) -> Option<SnapshotMetadata>

Retrieves the current snapshot metadata. Sync operation as it reads from in-memory structures.
Source§

fn persist_last_snapshot_metadata( &self, snapshot_metadata: &SnapshotMetadata, ) -> Result<(), Error>

Persists snapshot metadata to durable storage. Should be async as it involves disk I/O.
Source§

fn apply_snapshot_from_file<'life0, 'life1, 'async_trait>( &'life0 self, metadata: &'life1 SnapshotMetadata, snapshot_dir: PathBuf, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, RocksDBStateMachine: 'async_trait,

Applies a snapshot received from the Raft leader to the local state machine Read more
Source§

fn generate_snapshot_data<'life0, 'async_trait>( &'life0 self, new_snapshot_dir: PathBuf, last_included: LogId, ) -> Pin<Box<dyn Future<Output = Result<Bytes, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, RocksDBStateMachine: 'async_trait,

Generates a snapshot of the state machine’s current key-value entries up to the specified last_included_index. Read more
Source§

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

Saves the hard state of the state machine. Sync operation as it typically just delegates to other persistence methods.
Source§

fn flush(&self) -> Result<(), Error>

Flushes any pending writes to durable storage. Sync operation that may block but provides a synchronous interface.
Source§

fn flush_async<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, RocksDBStateMachine: 'async_trait,

Flushes any pending writes to durable storage. Async operation as it involves disk I/O.
Source§

fn reset<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, RocksDBStateMachine: 'async_trait,

Resets the state machine to its initial state. Async operation as it may involve cleaning up files and data.
Source§

fn lease_background_cleanup<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<Bytes>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, RocksDBStateMachine: 'async_trait,

Background lease cleanup hook. Read more
Source§

fn scan_prefix(&self, prefix: &[u8]) -> Result<ScanResult, Error>

Returns all (key, value) pairs whose key starts with prefix, plus the last_applied_index at the time of the scan. Read more
Source§

fn is_empty(&self) -> bool

Checks if the state machine is empty. Sync operation that typically delegates to len().

Auto Trait Implementations§

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<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
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