Skip to main content

BlockStoreSharding

Struct BlockStoreSharding 

Source
pub struct BlockStoreSharding {
    pub config: ShardingConfig,
    pub total_insertions: u64,
    pub total_lookups: u64,
    pub total_bytes: u64,
    /* private fields */
}
Expand description

A sharded, content-addressed block store.

Distributes blocks across num_shards logical shards using FNV-1a hashing of the CID. Provides per-shard metrics, rebalancing, and LRU eviction.

Fields§

§config: ShardingConfig

Runtime configuration.

§total_insertions: u64

Total insertions since creation (new + replaced).

§total_lookups: u64

Total get calls since creation.

§total_bytes: u64

Total bytes currently stored.

Implementations§

Source§

impl BlockStoreSharding

Source

pub fn new(config: ShardingConfig) -> Self

Creates a new BlockStoreSharding with the given configuration.

Panics if config.num_shards == 0.

Source

pub fn shard_for_cid(&self, cid: &str) -> ShardKey

Deterministically maps a CID string to a shard using FNV-1a % num_shards.

Source

pub fn put( &mut self, cid: String, data: Vec<u8>, now: u64, ) -> Result<bool, ShardingError>

Inserts or replaces a block.

Returns Ok(true) if the block was newly inserted, Ok(false) if an existing block for the same CID was replaced. Returns Err(ShardingError::ShardFull) if the shard is at capacity and there is no existing entry for the CID to replace.

Source

pub fn get(&mut self, cid: &str) -> Option<&BlockRecord>

Looks up a block by CID.

Updates the shard’s hit_count / miss_count and, on hit, increments the record’s access_count. Returns None if not found.

Source

pub fn get_mut(&mut self, cid: &str) -> Option<&mut BlockRecord>

Returns a mutable reference to a block record (no metrics update).

Source

pub fn contains(&self, cid: &str) -> bool

Returns true if the CID is present in the store.

Source

pub fn remove(&mut self, cid: &str) -> bool

Removes a block by CID.

Returns true if the block existed and was removed, false otherwise.

Source

pub fn shard_metrics(&self, shard: ShardKey) -> Option<&ShardMetrics>

Returns metrics for a specific shard, or None if the shard id is out of range.

Source

pub fn all_shard_metrics(&self) -> &[ShardMetrics]

Returns a slice of per-shard metrics.

Source

pub fn needs_rebalance(&self) -> bool

Returns true when at least one shard exceeds avg * (1 + threshold).

Returns false when no blocks are stored.

Source

pub fn rebalance(&mut self, now: u64) -> usize

Rebalances the store by moving blocks from over-loaded shards to under-loaded shards.

For each shard that exceeds the average by more than the threshold, the function removes the surplus blocks (those with the lowest access_count) and re-inserts them using their natural shard_for_cid routing. This is a no-op if the shard they naturally belong to has not changed (e.g. due to the same num_shards); however the inserted_at timestamp is refreshed to now.

Returns the total number of blocks moved.

Source

pub fn evict_lru(&mut self, shard: ShardKey, count: usize) -> usize

Evicts up to count blocks from the given shard, preferring blocks with the lowest access_count (LRU approximation).

Returns the number of blocks actually evicted (may be less than count if the shard has fewer blocks).

Source

pub fn cids_in_shard(&self, shard: ShardKey) -> Vec<&str>

Returns all CIDs stored in the given shard.

Source

pub fn total_block_count(&self) -> usize

Returns the total number of blocks across all shards.

Source

pub fn total_bytes(&self) -> u64

Returns the total bytes stored across all shards.

Source

pub fn global_stats(&self) -> BlockStoreGlobalStats

Returns a snapshot of global statistics.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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