hasql

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Alive for choosing any alive node
	Alive = hasql.Alive
	// Primary for choosing primary node
	Primary = hasql.Primary
	// Standby for choosing standby node
	Standby = hasql.Standby
	// PreferPrimary for choosing primary or any alive node
	PreferPrimary = hasql.PreferPrimary
	// PreferStandby for choosing standby or any alive node
	PreferStandby = hasql.PreferStandby

	// WithUpdateInterval sets interval between cluster node updates
	WithUpdateInterval = hasql.WithUpdateInterval
	// WithUpdateTimeout sets ping timeout for update of each node in cluster
	WithUpdateTimeout = hasql.WithUpdateTimeout
	// WithNodePicker sets algorithm for node selection (e.g. random, round robin etc)
	WithNodePicker = hasql.WithNodePicker
	// WithTracer sets tracer for actions happening in the background
	WithTracer = hasql.WithTracer

	// PickNodeRandom returns random node from nodes set
	PickNodeRandom = hasql.PickNodeRandom
	// PickNodeRoundRobin returns next node based on Round Robin algorithm
	PickNodeRoundRobin = hasql.PickNodeRoundRobin
	// PickNodeClosest returns node with least latency
	PickNodeClosest = hasql.PickNodeClosest
)

Functions

This section is empty.

Types

type AliveNodes added in v0.9.1

type AliveNodes = hasql.AliveNodes

AliveNodes of Cluster

type Cluster

type Cluster struct {
	*hasql.Cluster
}

Cluster consists of number of 'nodes' of a single SQL database. Background goroutine periodically checks nodes and updates their status.

func NewCluster

func NewCluster(nodes []Node, checker NodeChecker, opts ...ClusterOption) (*Cluster, error)

NewCluster constructs cluster object representing a single 'cluster' of SQL database. Close function must be called when cluster is not needed anymore.

func (*Cluster) Alive

func (cl *Cluster) Alive() Node

Alive returns node that is considered alive

func (*Cluster) Node

func (cl *Cluster) Node(criteria NodeStateCriteria) Node

Node returns cluster node with specified status.

func (*Cluster) Primary

func (cl *Cluster) Primary() Node

Primary returns first available node that is considered alive and is primary (able to execute write operations)

func (*Cluster) PrimaryPreferred

func (cl *Cluster) PrimaryPreferred() Node

PrimaryPreferred returns primary node if possible, standby otherwise

func (*Cluster) Standby

func (cl *Cluster) Standby() Node

Standby returns node that is considered alive and is standby (unable to execute write operations)

func (*Cluster) StandbyPreferred

func (cl *Cluster) StandbyPreferred() Node

StandbyPreferred returns standby node if possible, primary otherwise

func (*Cluster) WaitForAlive

func (cl *Cluster) WaitForAlive(ctx context.Context) (Node, error)

WaitForAlive node to appear or until context is canceled

func (*Cluster) WaitForNode

func (cl *Cluster) WaitForNode(ctx context.Context, criteria NodeStateCriteria) (Node, error)

WaitForNode with specified status to appear or until context is canceled

func (*Cluster) WaitForPrimary

func (cl *Cluster) WaitForPrimary(ctx context.Context) (Node, error)

WaitForPrimary node to appear or until context is canceled

func (*Cluster) WaitForPrimaryPreferred

func (cl *Cluster) WaitForPrimaryPreferred(ctx context.Context) (Node, error)

WaitForPrimaryPreferred node to appear or until context is canceled

func (*Cluster) WaitForStandby

func (cl *Cluster) WaitForStandby(ctx context.Context) (Node, error)

WaitForStandby node to appear or until context is canceled

func (*Cluster) WaitForStandbyPreferred

func (cl *Cluster) WaitForStandbyPreferred(ctx context.Context) (Node, error)

WaitForStandbyPreferred node to appear or until context is canceled

type ClusterOption

type ClusterOption = hasql.ClusterOption

ClusterOption is a functional option type for Cluster constructor

type Node

type Node interface {
	hasql.Node

	DBx() *sqlx.DB
}

Node of single cluster

func NewNode

func NewNode(addr string, db *sqlx.DB) Node

NewNode constructs node from sqlx.DB

type NodeChecker

type NodeChecker = hasql.NodeChecker

NodeChecker is a signature for functions that check if specific node is alive and is primary. Returns true for primary and false if not. If error is returned, node is considered dead. Check function can be used to perform a query returning single boolean value that signals if node is primary or not.

type NodePicker

type NodePicker = hasql.NodePicker

NodePicker is a signature for functions that determine how to pick single node from set of nodes. Nodes passed to the picker function are sorted according to latency (from lowest to greatest).

type NodeStateCriteria added in v0.9.1

type NodeStateCriteria = hasql.NodeStateCriteria

NodeStateCriteria for choosing a node

type Tracer

type Tracer = hasql.Tracer

Tracer is a set of hooks to run at various stages of background nodes status update. Any particular hook may be nil. Functions may be called concurrently from different goroutines.

Jump to

Keyboard shortcuts

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