Documentation ¶
Overview ¶
Package shardutil provides some sdk/db primitives for dealing with (manually) sharded postgres databases.
Index ¶
- func Hash(value []byte) int
- func HashString(value string) int
- type InvocationOption
- type Shards
- func (s Shards) InvokeAll(ctx context.Context, action func(int, *db.Invocation) error, ...) error
- func (s Shards) InvokeOne(ctx context.Context, hashCode int, opts ...InvocationOption) *db.Invocation
- func (s Shards) PartitionIndex(hashCode int) int
- func (s Shards) PartitionOptions(partitionIndex int, opts ...InvocationOption) []db.InvocationOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type InvocationOption ¶
type InvocationOption func(partitionIndex int) db.InvocationOption
InvocationOption is an option that returns an invocation option based on a partition index.
func OptPartitionLabel ¶
func OptPartitionLabel(label string) InvocationOption
OptPartitionLabel sets a label for invocations.
func OptTxs ¶
func OptTxs(txns ...*sql.Tx) InvocationOption
OptTxs returns a base manager invocation option that parameterizes the transaction per invocation based on an array of transactions.
type Shards ¶
type Shards struct { Connections []*db.Connection Opts []InvocationOption }
Shards handles communicating with many underlying databases at once.
func (Shards) InvokeAll ¶
func (s Shards) InvokeAll(ctx context.Context, action func(int, *db.Invocation) error, opts ...InvocationOption) error
InvokeAll invokes a given function asynchronously for each connection in the manager.
func (Shards) InvokeOne ¶
func (s Shards) InvokeOne(ctx context.Context, hashCode int, opts ...InvocationOption) *db.Invocation
InvokeOne creates a new db invocation routed to an underlying connection mapped by a given hashcode. The underlying connection is determined by `PartitionIndex(hashCode)`. The options are special parameterized versions of normal `db.InvocationOptions` that also take a partition index. The returned invocation will map to only (1) underlying connection.
func (Shards) PartitionIndex ¶
PartitionIndex returns a partition index for a given hashCode.
func (Shards) PartitionOptions ¶
func (s Shards) PartitionOptions(partitionIndex int, opts ...InvocationOption) []db.InvocationOption
PartitionOptions returns db.InvocationOptions for a given partition.