Skip to main content

ShardingSettings

Struct ShardingSettings 

Source
pub struct ShardingSettings<L = ShardCodec> {
    pub family: String,
    pub codec: ShardCodec,
    pub locator: L,
}
Expand description

The sharding configuration a surface hands its connector — everything the ORM needs to route and mint, in one struct, so a deployment declares its policy explicitly in one place rather than threading three loose values.

  • family — the shard family: the naming prefix for shard databases ({family}_shard_0001, see crate::shard_db_name) and the family this connector routes within (Executor::shard_family).
  • codec — the id layout: how the shard is packed into a shard-encoded id. Drives id minting (mint) and decoding a row’s owning shard from its key (shard_of).
  • locator — the routing model (the “key/hashing”): how a routed key maps to a physical shard. The default ShardCodec reads the shard from the id’s high bits (encoded-id, no lookup); swap in HashLocator or SlotLocator for a tier whose key isn’t shard-encoded (e.g. a hashed directory).

Build the connector’s ShardedExecutor with executor and mint ids with mint; the codec and locator stay consistent because they come from the one settings value.

Fields§

§family: String§codec: ShardCodec§locator: L

Implementations§

Source§

impl ShardingSettings<ShardCodec>

Source

pub fn encoded(family: impl Into<String>, codec: ShardCodec) -> Self

Encoded-id routing — the common case: the shard lives in the id’s high bits, so the ShardCodec is both the id layout and the locator.

Source§

impl<L: ShardLocator + Clone> ShardingSettings<L>

Source

pub fn with_locator( family: impl Into<String>, codec: ShardCodec, locator: L, ) -> Self

A custom routing model (hash / slot / …): the codec still defines the id layout for minting, while locator decides where each routed key lands.

Source

pub fn executor<C: ShardCatalog>(&self, catalog: C) -> ShardedExecutor<C, L>

Build the routed ShardedExecutor over catalog with this policy — the connector the generic services run on.

Source

pub fn mint(&self, allocator: &IdAllocator, shard: ShardId) -> u64

Mint a shard-encoded id on shard, using allocator for the monotonic sequence and this settings’ codec for the layout.

Source

pub fn shard_of(&self, key: u64) -> ShardId

The shard that owns key, decoded from a shard-encoded id’s high bits — used to mint a child row on its parent’s shard. (Routing an arbitrary, non-encoded key is the locator’s job, applied inside the executor.)

Trait Implementations§

Source§

impl<L: Clone> Clone for ShardingSettings<L>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<L: Debug> Debug for ShardingSettings<L>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<L> Freeze for ShardingSettings<L>
where L: Freeze,

§

impl<L> RefUnwindSafe for ShardingSettings<L>
where L: RefUnwindSafe,

§

impl<L> Send for ShardingSettings<L>
where L: Send,

§

impl<L> Sync for ShardingSettings<L>
where L: Sync,

§

impl<L> Unpin for ShardingSettings<L>
where L: Unpin,

§

impl<L> UnsafeUnpin for ShardingSettings<L>
where L: UnsafeUnpin,

§

impl<L> UnwindSafe for ShardingSettings<L>
where L: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.