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>
impl<T: BlockMetadata> BlockManager<T>
Sourcepub fn builder() -> BlockManagerConfigBuilder<T>
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()?;Sourcepub fn allocate_blocks(&self, count: usize) -> Option<Vec<MutableBlock<T>>>
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.
Sourcepub fn allocate_blocks_with_evictions(
&self,
count: usize,
) -> Option<(Vec<MutableBlock<T>>, Vec<SequenceHash>)>
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.
Sourcepub fn reset_inactive_pool(&self) -> Result<(), BlockManagerResetError>
pub fn reset_inactive_pool(&self) -> Result<(), BlockManagerResetError>
Drain the inactive pool, returning all blocks to the reset pool.
- Acquires the inactive pool lock and allocates all blocks.
- Releases the lock.
- Drops the allocated blocks (RAII returns them to reset).
- Verifies the reset pool contains the expected total.
Returns an error under contention when blocks are in active use.
Sourcepub fn register_blocks(
&self,
blocks: Vec<CompleteBlock<T>>,
) -> Vec<ImmutableBlock<T>>
pub fn register_blocks( &self, blocks: Vec<CompleteBlock<T>>, ) -> Vec<ImmutableBlock<T>>
Register a batch of completed blocks, returning immutable handles.
Sourcepub fn register_block(&self, block: CompleteBlock<T>) -> ImmutableBlock<T>
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.
Sourcepub fn match_blocks(&self, seq_hash: &[SequenceHash]) -> Vec<ImmutableBlock<T>>
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.
Sourcepub fn scan_matches(
&self,
seq_hashes: &[SequenceHash],
touch: bool,
) -> HashMap<SequenceHash, ImmutableBlock<T>>
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.
Sourcepub fn total_blocks(&self) -> usize
pub fn total_blocks(&self) -> usize
Total number of blocks managed (constant after construction).
Sourcepub fn available_blocks(&self) -> usize
pub fn available_blocks(&self) -> usize
Blocks available for allocation (reset + inactive pools).
Sourcepub fn block_size(&self) -> usize
pub fn block_size(&self) -> usize
Tokens per block (constant after construction).
Sourcepub fn duplication_policy(&self) -> &BlockDuplicationPolicy
pub fn duplication_policy(&self) -> &BlockDuplicationPolicy
Current duplication policy.
Sourcepub fn block_registry(&self) -> &BlockRegistry
pub fn block_registry(&self) -> &BlockRegistry
Reference to the shared block registry.
Sourcepub fn metrics(&self) -> &Arc<BlockPoolMetrics> ⓘ
pub fn metrics(&self) -> &Arc<BlockPoolMetrics> ⓘ
Reference to the block pool metrics.