Skip to main content

ShardStore

Struct ShardStore 

Source
pub struct ShardStore { /* private fields */ }
Expand description

A single shard’s key-value store.

Each worker thread owns exactly one ShardStore. All operations on it are single-threaded — no locking required.

Implementations§

Source§

impl ShardStore

Source

pub fn new(shard_id: u16) -> Self

Create a new empty shard store.

Source

pub fn shard_id(&self) -> u16

Get the shard ID.

Source

pub fn len(&self) -> usize

Get the number of keys in this shard.

Source

pub fn is_empty(&self) -> bool

Check if the shard is empty.

Source

pub fn set_max_memory(&mut self, bytes: usize)

Set the maximum memory limit for this shard (0 = unlimited).

Source

pub fn max_memory(&self) -> usize

Get the maximum memory limit for this shard.

Source

pub fn entries_iter(&self) -> impl Iterator<Item = (&CompactKey, &KeyEntry)>

Iterate over all entries in this shard.

Source

pub fn get_entry(&self, key: &CompactKey) -> Option<&KeyEntry>

Get a reference to a key entry.

Source

pub fn get_bytes(&mut self, key: &[u8]) -> CommandResponse

Execute a GET operation against a borrowed key.

Source

pub fn set_bytes( &mut self, key: &[u8], value: &[u8], ex: Option<u64>, px: Option<u64>, nx: bool, xx: bool, ) -> CommandResponse

Execute a SET-like operation against borrowed key and value bytes.

Source

pub fn incr_by_bytes(&mut self, key: &[u8], delta: i64) -> CommandResponse

Execute INCRBY/DECRBY style mutation against a borrowed key.

Source

pub fn get_entry_mut(&mut self, key: &CompactKey) -> Option<&mut KeyEntry>

Get a mutable reference to a key entry.

Source

pub fn insert_entry(&mut self, key: CompactKey, entry: KeyEntry)

Insert a key entry directly (used by migration and restore paths).

Source

pub fn mark_demoted(&mut self, key: &CompactKey, tier: u8, ref_hash: u64)

Replace a key’s value with a tier reference after demotion.

Source

pub fn promote(&mut self, key: &CompactKey, value: Value)

Promote a key back to the hot tier with the given value.

Source

pub fn evict_expired(&mut self) -> usize

Remove all expired keys, returning the count removed.

Source

pub fn evict_expired_sample(&mut self, sample_size: usize) -> usize

Remove expired keys by scanning a bounded sample of entries.

This avoids latency spikes from full-map sweeps on the hot path.

Source

pub fn flush(&mut self)

Remove all keys from this shard.

Source

pub fn execute(&mut self, cmd: Command) -> CommandResponse

Execute a command on this shard and return the response.

Auto Trait Implementations§

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, 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.