Skip to main content

ShardEngine

Struct ShardEngine 

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

The shard engine coordinates N worker threads, each owning a ShardStore.

Commands are routed to the appropriate worker based on key hash.

Implementations§

Source§

impl ShardEngine

Source

pub fn new(shard_count: usize) -> Self

Create a new ShardEngine with the given number of worker threads.

Source

pub fn new_with_storage( shard_count: usize, wal_writers: Vec<Option<Box<dyn WalWriter>>>, ) -> Self

Create a new ShardEngine with per-shard WAL writers.

Each element in wal_writers corresponds to one shard. The WAL writer is moved into the shard’s worker thread and called after every mutation.

Source

pub fn new_with_recovery( shard_count: usize, wal_writers: Vec<Option<Box<dyn WalWriter>>>, recovery_fns: Option<Vec<Box<dyn FnOnce(usize, &mut ShardStore) + Send>>>, ) -> Self

Create a new ShardEngine with per-shard WAL writers and optional per-shard recovery callbacks.

Each recovery callback receives the shard index and a mutable reference to the freshly created ShardStore, allowing callers to replay RDB snapshots and WAL entries before the worker starts accepting commands.

Source

pub fn shard_count(&self) -> usize

Get the number of shards.

Source

pub fn dispatch(&self, cmd: Command) -> ResponseReceiver

Dispatch a command and return a receiver for the response.

Source

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

Dispatch a command and block until the response is received.

Source

pub fn dispatch_batch_blocking( &self, commands: Vec<Command>, ) -> Vec<CommandResponse>

Dispatch a batch of commands and block until all responses are received.

Commands that target a single key are grouped per shard and executed in-order, reducing response-channel overhead for pipelined workloads.

Trait Implementations§

Source§

impl Drop for ShardEngine

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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.