shardutil

package
v1.20220411.3 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package shardutil provides some sdk/db primitives for dealing with (manually) sharded postgres databases.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

func Hash(value []byte) int

Hash hashes a given string as an integer.

func HashString

func HashString(value string) int

HashString hashes a given string as an integer.

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 OptLabel

func OptLabel(label string) InvocationOption

OptLabel sets a label for invocations.

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

func (s Shards) PartitionIndex(hashCode int) int

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.

Jump to

Keyboard shortcuts

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