pub struct LmdbReadPool { /* private fields */ }Expand description
LMDB Read Transaction Pool
Manages a pool of read-only transaction slots using a semaphore. This limits concurrent read transactions and provides timeout support.
§Example
let pool = LmdbReadPool::new(env.clone(), state_db, ReadPoolConfig::enabled(4));
// Acquire a pooled read transaction
let txn = pool.acquire().await?;
let value = txn.get_state(b"key")?;
// Transaction and permit are released when `txn` is droppedImplementations§
Source§impl LmdbReadPool
impl LmdbReadPool
Sourcepub fn new(
env: Arc<Environment>,
state_db: Database,
config: ReadPoolConfig,
) -> Self
pub fn new( env: Arc<Environment>, state_db: Database, config: ReadPoolConfig, ) -> Self
Create a new read pool with the given configuration
Sourcepub async fn acquire(&self) -> Result<PooledLmdbReadTxn<'_>>
pub async fn acquire(&self) -> Result<PooledLmdbReadTxn<'_>>
Acquire a pooled read-only transaction
Waits up to the configured timeout for a slot to become available. Returns an error if the timeout is exceeded.
Sourcepub fn try_acquire(&self) -> Result<Option<PooledLmdbReadTxn<'_>>>
pub fn try_acquire(&self) -> Result<Option<PooledLmdbReadTxn<'_>>>
Try to acquire a pooled read-only transaction without waiting
Returns None if no slot is immediately available.
Sourcepub fn acquire_blocking(&self) -> Result<PooledLmdbReadTxn<'_>>
pub fn acquire_blocking(&self) -> Result<PooledLmdbReadTxn<'_>>
Acquire a pooled read-only transaction (blocking)
This is a synchronous version that blocks the current thread using
exponential backoff (1ms, 2ms, 4ms, … capped at 32ms) up to the
configured acquire_timeout.
Prefer acquire() in async contexts.
Sourcepub fn available_permits(&self) -> usize
pub fn available_permits(&self) -> usize
Get the number of available slots in the pool
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if pooling is enabled