pub struct ModelShardManager { /* private fields */ }Expand description
Partitions embedding tables (entity and relation) by stable hash of the ID.
Implementations§
Source§impl ModelShardManager
impl ModelShardManager
Sourcepub fn new(num_shards: usize, strategy: ShardingStrategy) -> Self
pub fn new(num_shards: usize, strategy: ShardingStrategy) -> Self
Create a new shard manager with num_shards shards.
§Panics
Does not panic. If num_shards == 0 it is silently coerced to 1
(single-shard / no sharding) so the manager is always usable.
Sourcepub fn num_shards(&self) -> usize
pub fn num_shards(&self) -> usize
Number of shards this manager partitions across.
Sourcepub fn strategy(&self) -> ShardingStrategy
pub fn strategy(&self) -> ShardingStrategy
Hashing strategy.
Sourcepub fn shard_for(&self, id: &str) -> usize
pub fn shard_for(&self, id: &str) -> usize
Compute the shard index for id.
Always returns a value in 0..self.num_shards(). Calling this method
repeatedly with the same id and same num_shards always yields the
same answer — it is the basis of the parameter-server routing scheme.
Sourcepub fn partition<I, S>(&mut self, ids: I) -> ShardAssignment
pub fn partition<I, S>(&mut self, ids: I) -> ShardAssignment
Partition a list of IDs into shards in input order.
In EntityHash mode this is equivalent to shard_for on each ID. In
RoundRobin mode it also populates the manager’s internal round-robin
table so that subsequent shard_for calls give consistent answers.
Sourcepub fn reshard(&mut self, prior: &ShardAssignment) -> ShardAssignment
pub fn reshard(&mut self, prior: &ShardAssignment) -> ShardAssignment
Re-shard an existing assignment after num_shards changes.
Returns a fresh ShardAssignment computed by routing every existing
ID through the new manager. Used by elastic scaling tests.
Trait Implementations§
Source§impl Clone for ModelShardManager
impl Clone for ModelShardManager
Source§fn clone(&self) -> ModelShardManager
fn clone(&self) -> ModelShardManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ModelShardManager
impl RefUnwindSafe for ModelShardManager
impl Send for ModelShardManager
impl Sync for ModelShardManager
impl Unpin for ModelShardManager
impl UnsafeUnpin for ModelShardManager
impl UnwindSafe for ModelShardManager
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.