Skip to main content

BlockManager

Struct BlockManager 

Source
pub struct BlockManager<T: BlockMetadata> { /* private fields */ }
Expand description

Manages the full block lifecycle across three pool tiers: reset (free), active (in-use), and inactive (cached, evictable).

Thread-safe: allocation is serialised via an internal Mutex; individual pools use their own internal locking.

Construct via BlockManager::builder().

Implementations§

Source§

impl<T: BlockMetadata> BlockManager<T>

Source

pub fn builder() -> BlockManagerConfigBuilder<T>

Create a new builder for BlockManager.

§Example
let tracker = FrequencyTrackingCapacity::Medium.create_tracker();
let registry = BlockRegistry::builder().frequency_tracker(tracker).build();

let manager = BlockManager::builder()
    .block_count(1000)
    .registry(registry)
    .with_multi_lru_backend()
    .build()?;
Source

pub fn allocate_blocks(&self, count: usize) -> Option<Vec<MutableBlock<T>>>

Allocate count mutable blocks, drawing first from the reset pool then evicting from the inactive pool if needed.

Returns None if fewer than count blocks are available across both pools.

Source

pub fn allocate_blocks_with_evictions( &self, count: usize, ) -> Option<(Vec<MutableBlock<T>>, Vec<SequenceHash>)>

Like allocate_blocks but also reports the SequenceHash of each block evicted from the inactive pool to satisfy the allocation. Callers maintaining a shadow view of which registrations are alive (e.g. the mocker’s router-event bridge) can translate these hashes into cache-invalidation events directly, avoiding an O(N) presence scan over the registry.

Source

pub fn reset_inactive_pool(&self) -> Result<(), BlockManagerResetError>

Drain the inactive pool, returning all blocks to the reset pool.

  1. Acquires the inactive pool lock and allocates all blocks.
  2. Releases the lock.
  3. Drops the allocated blocks (RAII returns them to reset).
  4. Verifies the reset pool contains the expected total.

Returns an error under contention when blocks are in active use.

Source

pub fn register_blocks( &self, blocks: Vec<CompleteBlock<T>>, ) -> Vec<ImmutableBlock<T>>

Register a batch of completed blocks, returning immutable handles.

Source

pub fn register_block(&self, block: CompleteBlock<T>) -> ImmutableBlock<T>

Register a single completed block and return an immutable handle.

Deduplication is governed by the configured BlockDuplicationPolicy.

Source

pub fn match_blocks(&self, seq_hash: &[SequenceHash]) -> Vec<ImmutableBlock<T>>

Linear prefix match: walks seq_hash left-to-right, stopping on first miss.

Checks the active pool first, then the inactive pool for remaining hashes.

Source

pub fn scan_matches( &self, seq_hashes: &[SequenceHash], touch: bool, ) -> HashMap<SequenceHash, ImmutableBlock<T>>

Scatter-gather scan: finds all blocks matching any hash, without stopping on misses.

Returns a map of found hashes to immutable handles.

Source

pub fn total_blocks(&self) -> usize

Total number of blocks managed (constant after construction).

Source

pub fn available_blocks(&self) -> usize

Blocks available for allocation (reset + inactive pools).

Source

pub fn block_size(&self) -> usize

Tokens per block (constant after construction).

Source

pub fn duplication_policy(&self) -> &BlockDuplicationPolicy

Current duplication policy.

Source

pub fn block_registry(&self) -> &BlockRegistry

Reference to the shared block registry.

Source

pub fn metrics(&self) -> &Arc<BlockPoolMetrics>

Reference to the block pool metrics.

Auto Trait Implementations§

§

impl<T> !Freeze for BlockManager<T>

§

impl<T> !RefUnwindSafe for BlockManager<T>

§

impl<T> !UnwindSafe for BlockManager<T>

§

impl<T> Send for BlockManager<T>

§

impl<T> Sync for BlockManager<T>

§

impl<T> Unpin for BlockManager<T>

§

impl<T> UnsafeUnpin for BlockManager<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, 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<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