cluster

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 9 Imported by: 0

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

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 New

func New(shards map[string]*migro.DB, route Router) (*Cluster, error)

New builds a cluster from already-open shards.

func Open

func Open(ctx context.Context, cfgs map[string]migro.Config, route Router) (*Cluster, error)

Open connects every shard; if one fails, the ones already opened are closed.

func (*Cluster) Close

func (c *Cluster) Close() error

Close closes every shard.

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.

func (*Cluster) For

func (c *Cluster) For(key any) (*migro.DB, error)

For returns the shard owning key.

func (*Cluster) Migrate

func (c *Cluster) Migrate(ctx context.Context, ms []migrate.Migration) (map[string]migrate.Result, error)

Migrate applies the same migrations to every shard and returns each shard's result.

func (*Cluster) Names

func (c *Cluster) Names() []string

func (*Cluster) Shard

func (c *Cluster) Shard(name string) (*migro.DB, error)

type Router

type Router func(key any) (string, error)

Router maps a shard key (tenant id, user id, ...) to a shard name.

func HashRouter

func HashRouter(shardNames []string) Router

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL