pub struct ShardRouter { /* private fields */ }Expand description
Maps application keys onto a fixed number of shards with a stable hash.
Implementations§
Source§impl ShardRouter
impl ShardRouter
Sourcepub fn new(shard_count: u32) -> Self
pub fn new(shard_count: u32) -> Self
A router over shard_count shards (clamped to [1, MAX_VIRTUAL_SHARDS]).
Sourcepub fn shard_count(&self) -> u32
pub fn shard_count(&self) -> u32
The number of shards this router partitions keys into.
Sourcepub fn shard_for(&self, key: &[u8]) -> ShardId
pub fn shard_for(&self, key: &[u8]) -> ShardId
The shard owning key, by stable hash modulo the shard count.
Sourcepub fn expand_shard_count(
&mut self,
new_count: u32,
) -> Result<ShardCountExpansionPlan, ShardExpansionError>
pub fn expand_shard_count( &mut self, new_count: u32, ) -> Result<ShardCountExpansionPlan, ShardExpansionError>
Increase the active shard count (operator-driven expansion). Keys remap when the modulus changes — drain clients before applying.
§Errors
Returns an error when new_count shrinks the space or exceeds
MAX_VIRTUAL_SHARDS.
Trait Implementations§
Source§impl Clone for ShardRouter
impl Clone for ShardRouter
Source§fn clone(&self) -> ShardRouter
fn clone(&self) -> ShardRouter
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for ShardRouter
Source§impl Debug for ShardRouter
impl Debug for ShardRouter
impl Eq for ShardRouter
Source§impl PartialEq for ShardRouter
impl PartialEq for ShardRouter
impl StructuralPartialEq for ShardRouter
Auto Trait Implementations§
impl Freeze for ShardRouter
impl RefUnwindSafe for ShardRouter
impl Send for ShardRouter
impl Sync for ShardRouter
impl Unpin for ShardRouter
impl UnsafeUnpin for ShardRouter
impl UnwindSafe for ShardRouter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more