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
impl ShardEngine
Sourcepub fn new(shard_count: usize) -> Self
pub fn new(shard_count: usize) -> Self
Create a new ShardEngine with the given number of worker threads.
Sourcepub fn new_with_storage(
shard_count: usize,
wal_writers: Vec<Option<Box<dyn WalWriter>>>,
) -> Self
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.
Sourcepub 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
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.
Sourcepub fn shard_count(&self) -> usize
pub fn shard_count(&self) -> usize
Get the number of shards.
Sourcepub fn dispatch(&self, cmd: Command) -> ResponseReceiver
pub fn dispatch(&self, cmd: Command) -> ResponseReceiver
Dispatch a command and return a receiver for the response.
Sourcepub fn dispatch_blocking(&self, cmd: Command) -> CommandResponse
pub fn dispatch_blocking(&self, cmd: Command) -> CommandResponse
Dispatch a command and block until the response is received.
Sourcepub fn dispatch_batch_blocking(
&self,
commands: Vec<Command>,
) -> Vec<CommandResponse>
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.