Documentation ¶
Overview ¶
Package dbfailover monitors set of DB servers and provides easy access to currently alive server with desired role (master/slave).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoDatabases = errors.New("empty database set provided")
ErrNoDatabases is returned from New() if empty slice of databases are provided. Without any databases to start with we can not guarantee that Master() and Slave() methods will never return nil.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { SkipSlaveCheck bool SkipGaleraCheck bool CheckInterval time.Duration // default 1.5 sec if empty CheckTimeout time.Duration // default 1.5 sec if empty MaxReplicationDelay time.Duration // default 5 min if empty }
Config holds configuration for DB pools.
type DBs ¶
type DBs struct {
// contains filtered or unexported fields
}
DBs holds a list of pools of known DB servers and provides easy access for getting currently active master or slave DB pool.
func New ¶
New creates a new instance of database pools checker.
It will block until initial databases state is detected, therefore it is safe to immediately query for master and slave pools after this function returns.
If dbs is empty slice it will return ErrNoDatabases error.
func NewWithConfig ¶
NewWithConfig is same as New but allows passing a configuration struct.
func (*DBs) Master ¶
Master returns a database pool attached to the currently active master database instance.
This function will never return nil. If there are no master servers available it will return last seen master. It allows this function result to be used without additional checks, example: `dbs.Master().Query(...)`.
func (*DBs) Slave ¶
Slave returns database pool attached to a server suitable to be used for read-only non time sensitive queries. It tries to return slave instance with the lowest delay. If no slaves are detected it returns a master DB instance.
This function will never return nil. If there are no servers available it will return last seen master. It allows this function result to be used without additional checks, example: `dbs.Slave().Query(...)`.