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, seecrate::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 defaultShardCodecreads the shard from the id’s high bits (encoded-id, no lookup); swap inHashLocatororSlotLocatorfor 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: LImplementations§
Source§impl ShardingSettings<ShardCodec>
impl ShardingSettings<ShardCodec>
Sourcepub fn encoded(family: impl Into<String>, codec: ShardCodec) -> Self
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>
impl<L: ShardLocator + Clone> ShardingSettings<L>
Sourcepub fn with_locator(
family: impl Into<String>,
codec: ShardCodec,
locator: L,
) -> Self
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.
Sourcepub fn executor<C: ShardCatalog>(&self, catalog: C) -> ShardedExecutor<C, L>
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.
Sourcepub fn mint(&self, allocator: &IdAllocator, shard: ShardId) -> u64
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.