Documentation ¶
Index ¶
- Variables
- type AliveNodes
- type Cluster
- func (cl *Cluster) Alive() Node
- func (cl *Cluster) Node(criteria NodeStateCriteria) Node
- func (cl *Cluster) Primary() Node
- func (cl *Cluster) PrimaryPreferred() Node
- func (cl *Cluster) Standby() Node
- func (cl *Cluster) StandbyPreferred() Node
- func (cl *Cluster) WaitForAlive(ctx context.Context) (Node, error)
- func (cl *Cluster) WaitForNode(ctx context.Context, criteria NodeStateCriteria) (Node, error)
- func (cl *Cluster) WaitForPrimary(ctx context.Context) (Node, error)
- func (cl *Cluster) WaitForPrimaryPreferred(ctx context.Context) (Node, error)
- func (cl *Cluster) WaitForStandby(ctx context.Context) (Node, error)
- func (cl *Cluster) WaitForStandbyPreferred(ctx context.Context) (Node, error)
- type ClusterOption
- type Node
- type NodeChecker
- type NodePicker
- type NodeStateCriteria
- type Tracer
Constants ¶
This section is empty.
Variables ¶
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 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) Node ¶
func (cl *Cluster) Node(criteria NodeStateCriteria) Node
Node returns cluster node with specified status.
func (*Cluster) Primary ¶
Primary returns first available node that is considered alive and is primary (able to execute write operations)
func (*Cluster) PrimaryPreferred ¶
PrimaryPreferred returns primary node if possible, standby otherwise
func (*Cluster) Standby ¶
Standby returns node that is considered alive and is standby (unable to execute write operations)
func (*Cluster) StandbyPreferred ¶
StandbyPreferred returns standby node if possible, primary otherwise
func (*Cluster) WaitForAlive ¶
WaitForAlive node to appear or until context is canceled
func (*Cluster) WaitForNode ¶
WaitForNode with specified status to appear or until context is canceled
func (*Cluster) WaitForPrimary ¶
WaitForPrimary node to appear or until context is canceled
func (*Cluster) WaitForPrimaryPreferred ¶
WaitForPrimaryPreferred node to appear or until context is canceled
func (*Cluster) WaitForStandby ¶
WaitForStandby node to appear or until context is canceled
type ClusterOption ¶
type ClusterOption = hasql.ClusterOption
ClusterOption is a functional option type for Cluster constructor
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