pgcluster

package
v0.0.0-...-cab2697 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2016 License: GPL-3.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDublicatedDataSource means that connStrings contains duplicated items
	ErrDublicatedDataSource = errors.New("duplicated data source")
	// ErrZeroDataSource means that an empty connStrings was passed
	ErrZeroDataSource = errors.New("data source must contain at least one item")
)

Functions

This section is empty.

Types

type Cluster

type Cluster struct {
	// contains filtered or unexported fields
}

Cluster represents a PostgreSQL cluster keeping track of a current master

func NewPostgreSQLCluster

func NewPostgreSQLCluster(drivername string, connStrings []string) (*Cluster, error)

NewPostgreSQLCluster creates Cluster. Drivername can be specified, but must point to a PostgreSQL driver.

func (*Cluster) Close

func (c *Cluster) Close() error

Close closes connections per each db contained in Cluster. An error fron each Close is collected.

func (*Cluster) DB

func (c *Cluster) DB(role Role) *sql.DB

DB returns *sql.DB suggested to be a master in the cluster. Current implementation checks master every 5 seconds. However the proper approach is to reelect a master after disconnection error.

func (*Cluster) ReElect

func (c *Cluster) ReElect()

ReElect verifies if the current master is really master. New master will be elected if needed. This can be called after connections errors detection.

func (*Cluster) SetConnMaxLifetime

func (c *Cluster) SetConnMaxLifetime(d time.Duration)

SetConnMaxLifetime sets the maximum amount of time a connection may be reused for each memeber of a cluster

func (*Cluster) SetMaxIdleConns

func (c *Cluster) SetMaxIdleConns(n int)

SetMaxIdleConns sets the maximum number of connections in the idle connection pool for each memeber of a cluster

func (*Cluster) SetMaxOpenConns

func (c *Cluster) SetMaxOpenConns(n int)

SetMaxOpenConns sets the maximum number of open connections to the database for each memeber of a cluster

type Role

type Role int

Role is a role in the cluster of requested node

const (
	// MASTER is the master one in a cluster
	MASTER Role = iota
	// SLAVE is a replication node in a cluster
	SLAVE
)

Jump to

Keyboard shortcuts

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