Documentation
¶
Overview ¶
Package cluster routes work across several independent databases (application-level sharding).
Each shard is a full migro.DB, so replicas, pools and events work per shard. Cross-shard transactions are not supported: Each runs shards independently and reports per-shard failures, but shards that succeeded stay committed.
Index ¶
- type Cluster
- func (c *Cluster) Close() error
- func (c *Cluster) Each(ctx context.Context, ...) error
- func (c *Cluster) For(key any) (*migro.DB, error)
- func (c *Cluster) Migrate(ctx context.Context, ms []migrate.Migration) (map[string]migrate.Result, error)
- func (c *Cluster) Names() []string
- func (c *Cluster) Shard(name string) (*migro.DB, error)
- type Router
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cluster ¶
type Cluster struct {
// contains filtered or unexported fields
}
func (*Cluster) Each ¶
func (c *Cluster) Each(ctx context.Context, fn func(ctx context.Context, name string, db *migro.DB) error) error
Each runs fn on every shard concurrently. Failures are collected as SHARD_FAILED, naming each shard.
type Router ¶
Router maps a shard key (tenant id, user id, ...) to a shard name.
func HashRouter ¶
HashRouter spreads keys over shards by FNV hash of the key's printed value. Adding or removing a shard changes the mapping for most keys; migrate data before doing so.