Skip to main content

RocksDBProviderFactory

Trait RocksDBProviderFactory 

Source
pub trait RocksDBProviderFactory {
    // Required methods
    fn rocksdb_provider(&self) -> RocksDBProvider;
    fn set_pending_rocksdb_batch(&self, batch: WriteBatchWithTransaction<true>);
    fn commit_pending_rocksdb_batches(&self) -> Result<(), ProviderError>;

    // Provided methods
    fn with_rocksdb_snapshot<F, R>(&self, f: F) -> Result<R, ProviderError>
       where Self: StorageSettingsCache,
             F: FnOnce(Option<RocksReadSnapshot<'_>>) -> Result<R, ProviderError> { ... }
    fn with_rocksdb_batch<F, R>(&self, f: F) -> Result<R, ProviderError>
       where F: FnOnce(RocksDBBatch<'_>) -> Result<(R, Option<WriteBatchWithTransaction<true>>), ProviderError> { ... }
    fn with_rocksdb_batch_auto_commit<F, R>(
        &self,
        f: F,
    ) -> Result<R, ProviderError>
       where F: FnOnce(RocksDBBatch<'_>) -> Result<(R, Option<WriteBatchWithTransaction<true>>), ProviderError> { ... }
}
Available on crate feature provider only.
Expand description

RocksDB provider factory.

This trait provides access to the RocksDB provider

Required Methods§

Source

fn rocksdb_provider(&self) -> RocksDBProvider

Returns the RocksDB provider.

Source

fn set_pending_rocksdb_batch(&self, batch: WriteBatchWithTransaction<true>)

Adds a pending RocksDB batch to be committed when this provider is committed.

This allows deferring RocksDB commits to happen at the same time as MDBX and static file commits, ensuring atomicity across all storage backends.

Source

fn commit_pending_rocksdb_batches(&self) -> Result<(), ProviderError>

Takes all pending RocksDB batches and commits them.

This drains the pending batches from the lock and commits each one using the RocksDB provider. Can be called before flush to persist RocksDB writes independently of the full commit path.

Provided Methods§

Source

fn with_rocksdb_snapshot<F, R>(&self, f: F) -> Result<R, ProviderError>

Executes a closure with a RocksDB point-in-time snapshot for consistent reads.

This helper encapsulates RocksDB access for read operations. On legacy MDBX-only nodes (where storage_v2 is false), this skips creating the RocksDB snapshot entirely, avoiding unnecessary overhead.

Unlike a transaction-based approach, this works in both read-only and read-write modes since the snapshot provides a consistent view of the data at the time it was created.

Source

fn with_rocksdb_batch<F, R>(&self, f: F) -> Result<R, ProviderError>
where F: FnOnce(RocksDBBatch<'_>) -> Result<(R, Option<WriteBatchWithTransaction<true>>), ProviderError>,

Executes a closure with a RocksDB batch, automatically registering it for commit.

This helper encapsulates all the cfg-gated RocksDB batch handling.

Source

fn with_rocksdb_batch_auto_commit<F, R>(&self, f: F) -> Result<R, ProviderError>
where F: FnOnce(RocksDBBatch<'_>) -> Result<(R, Option<WriteBatchWithTransaction<true>>), ProviderError>,

Executes a closure with a RocksDB batch that auto-commits on threshold.

Unlike Self::with_rocksdb_batch, this uses a batch that automatically commits when it exceeds the size threshold, preventing OOM during large bulk writes. The consistency check on startup heals any crash between auto-commits.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§