pub struct ShardConfig {
pub name: String,
pub primary_url: String,
pub slots: Option<Vec<SlotSpec>>,
pub replica_url: Option<String>,
pub primary_pool_size: Option<usize>,
pub replica_pool_size: Option<usize>,
pub replica_fallback: Option<ReplicaFallback>,
}Expand description
One horizontal shard of the application’s data, declared via
[[database.shards]] in autumn.toml.
Each shard is a full primary/replica topology of its own, so the
replica story composes with sharding: any shard may have a read
replica, role-specific pool sizes, and its own fallback behavior.
Fields left unset fall back to the corresponding [database] value.
§Routing: keys → logical slots → shards
Routing keys hash onto a fixed set of SLOT_COUNT (16384) logical
slots, and each slot maps to one shard. The key→slot hash is a
permanent contract; the slot→shard map is plain configuration. Growing
from two shards to three means moving whole slots — copy a slot’s rows
to the new shard, flip its slots entry, deploy — without rehashing
any keys.
When every shard declares slots, declaration
order is meaningless and entries can be reordered, renamed, or
removed freely (as long as the map still covers every slot exactly
once). When no shard declares slots, the framework auto-splits
the slot space into contiguous even ranges by declaration order
— convenient to start with, but reordering entries then moves data.
Pin explicit slots before making any topology change.
§Example
[database]
primary_url = "postgres://db-control/app" # control role: jobs, sessions, flags
[[database.shards]]
name = "shard0"
primary_url = "postgres://db-shard0/app"
slots = ["0-8191"]
[[database.shards]]
name = "shard1"
primary_url = "postgres://db-shard1/app"
slots = ["8192-16383"]
replica_url = "postgres://db-shard1-ro/app"
replica_fallback = "primary"Fields§
§name: StringStable shard identity used in logs, metric tags, health component
names (db:shard:<name>), and autumn migrate --shard <name>.
Must be non-empty, unique across shards, and restricted to
[a-z0-9_-] so it can be embedded in metric/health keys.
primary_url: StringPostgres URL for this shard’s primary/write role. Required.
slots: Option<Vec<SlotSpec>>Logical slots this shard owns, as indices and/or "A-B" inclusive
ranges (e.g. slots = ["0-8191", 16000, "16382-16383"]).
All-or-none across shards: either every shard declares slots
(explicit map covering 0..16384 exactly once; an empty list
marks a drained shard being decommissioned) or none does
(contiguous auto-split by declaration order).
replica_url: Option<String>Optional Postgres URL for this shard’s read-replica role.
primary_pool_size: Option<usize>Optional primary pool size override. Falls back to
database.primary_pool_size, then database.pool_size.
replica_pool_size: Option<usize>Optional replica pool size override. Falls back to
database.replica_pool_size, then database.pool_size.
replica_fallback: Option<ReplicaFallback>Optional replica fallback override. Falls back to
database.replica_fallback.
Implementations§
Source§impl ShardConfig
impl ShardConfig
Sourcepub fn effective_primary_pool_size(&self, defaults: &DatabaseConfig) -> usize
pub fn effective_primary_pool_size(&self, defaults: &DatabaseConfig) -> usize
Resolved primary pool size for this shard.
Sourcepub fn effective_replica_pool_size(&self, defaults: &DatabaseConfig) -> usize
pub fn effective_replica_pool_size(&self, defaults: &DatabaseConfig) -> usize
Resolved replica pool size for this shard.
Sourcepub fn effective_replica_fallback(
&self,
defaults: &DatabaseConfig,
) -> ReplicaFallback
pub fn effective_replica_fallback( &self, defaults: &DatabaseConfig, ) -> ReplicaFallback
Resolved replica fallback behavior for this shard.
Trait Implementations§
Source§impl Clone for ShardConfig
impl Clone for ShardConfig
Source§fn clone(&self) -> ShardConfig
fn clone(&self) -> ShardConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ShardConfig
impl Debug for ShardConfig
Source§impl Default for ShardConfig
impl Default for ShardConfig
Source§fn default() -> ShardConfig
fn default() -> ShardConfig
Source§impl<'de> Deserialize<'de> for ShardConfig
impl<'de> Deserialize<'de> for ShardConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ShardConfig
impl RefUnwindSafe for ShardConfig
impl Send for ShardConfig
impl Sync for ShardConfig
impl Unpin for ShardConfig
impl UnsafeUnpin for ShardConfig
impl UnwindSafe for ShardConfig
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
Source§impl<T> AutumnDependents for Twhere
T: ?Sized,
impl<T> AutumnDependents for Twhere
T: ?Sized,
Source§fn dependents() -> &'static [RuntimeDependentSpec]
fn dependents() -> &'static [RuntimeDependentSpec]
#[model] overrides via an inherent shadow when dependents exist.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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self to an expression for Diesel’s query builder. 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,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> RepositoryHooksClone for Twhere
T: Clone,
impl<T> RepositoryHooksClone for Twhere
T: Clone,
Source§fn autumn_clone(&self) -> T
fn autumn_clone(&self) -> T
Source§impl<T> RepositoryHooksDefault for Twhere
T: Default,
impl<T> RepositoryHooksDefault for Twhere
T: Default,
Source§fn autumn_default() -> T
fn autumn_default() -> T
Source§impl<T, Conn> RunQueryDsl<Conn> for T
impl<T, Conn> RunQueryDsl<Conn> for T
Source§fn execute<'conn, 'query>(
self,
conn: &'conn mut Conn,
) -> <Conn as AsyncConnectionCore>::ExecuteFuture<'conn, 'query>
fn execute<'conn, 'query>( self, conn: &'conn mut Conn, ) -> <Conn as AsyncConnectionCore>::ExecuteFuture<'conn, 'query>
Source§fn load<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
fn load<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
Source§fn load_stream<'conn, 'query, U>(
self,
conn: &'conn mut Conn,
) -> Self::LoadFuture<'conn>where
Conn: AsyncConnectionCore,
U: 'conn,
Self: LoadQuery<'query, Conn, U> + 'query,
fn load_stream<'conn, 'query, U>(
self,
conn: &'conn mut Conn,
) -> Self::LoadFuture<'conn>where
Conn: AsyncConnectionCore,
U: 'conn,
Self: LoadQuery<'query, Conn, U> + 'query,
Stream] with the returned rows. Read moreSource§fn get_result<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, LoadNext<Pin<Box<Self::Stream<'conn>>>>>
fn get_result<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, LoadNext<Pin<Box<Self::Stream<'conn>>>>>
Source§fn get_results<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
fn get_results<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
Vec with the affected rows. Read moreSource§impl<T> Scoped for T
impl<T> Scoped for T
Source§fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
ScopeQuery for this type. Resolves the
registered scope at .load() time, not here.