failover

package
v0.0.0-...-3d60fba Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2020 License: MIT Imports: 23 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ClusterStateNew      = "new"
	ClusterStateExisting = "existing"
)
View Source
const (
	MastersStateNew      = "new"
	MastersStateExisting = "existing"
)
View Source
const (
	MasterType = "master"
	SlaveType  = "slave"
)
View Source
const (
	ConnectState    = "connect"
	ConnectingState = "connecting"
	ConnectedState  = "connected"
	SyncState       = "sync"
)

Variables

View Source
var (
	ErrNodeDown    = errors.New("Node is down")
	ErrNodeAlive   = errors.New("Node may be still alive")
	ErrNoCandidate = errors.New("no proper candidate to be promoted to master")
	ErrNodeType    = errors.New("Node is not the expected type")
)
View Source
var (
	// If failover handler return this error, we will give up future handling.
	ErrGiveupFailover = errors.New("Give up failover handling")
)

Functions

This section is empty.

Types

type AfterFailoverHandler

type AfterFailoverHandler func(downMaster, newMaster string) error

type App

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

func NewApp

func NewApp(c *Config) (*App, error)

func (*App) AddAfterFailoverHandler

func (a *App) AddAfterFailoverHandler(f AfterFailoverHandler)

func (*App) AddBeforeFailoverHandler

func (a *App) AddBeforeFailoverHandler(f BeforeFailoverHandler)

func (*App) Close

func (a *App) Close()

func (*App) Run

func (a *App) Run()

type BeforeFailoverHandler

type BeforeFailoverHandler func(downMaster string) error

type Cluster

type Cluster interface {
	Close()
	AddMasters(addrs []string, timeout time.Duration) error
	DelMasters(addrs []string, timeout time.Duration) error
	SetMasters(addrs []string, timeout time.Duration) error
	Barrier(timeout time.Duration) error
	IsLeader() bool
	LeaderCh() <-chan bool
}

type Config

type Config struct {
	Addr          string   `toml:"addr"`
	Masters       []string `toml:"masters"`
	MastersState  string   `toml:"masters_state"`
	CheckInterval int      `toml:"check_interval"`
	MaxDownTime   int      `toml:"max_down_time"`

	Broker string     `toml:"broker"`
	Raft   RaftConfig `toml:"raft"`
	Zk     ZkConfig   `toml:"zk"`
}

func NewConfig

func NewConfig(data string) (*Config, error)

func NewConfigWithFile

func NewConfigWithFile(name string) (*Config, error)

type Group

type Group struct {
	Master *Node
	Slaves map[string]*Node

	CheckErrNum sync2.AtomicInt32
	// contains filtered or unexported fields
}

A group contains a Redis master and one or more slaves It will use role command per second to check master's alive and find slaves automatically.

func (*Group) Check

func (g *Group) Check() error

func (*Group) Close

func (g *Group) Close()

func (*Group) Elect

func (g *Group) Elect() (string, error)

Elect a best slave which has the most up-to-date data with master

func (*Group) Ping

func (g *Group) Ping() error

func (*Group) Promote

func (g *Group) Promote(addr string) error

Promote the slave to master, then let other slaves replicate from it

type Node

type Node struct {
	// Redis address, only support tcp now
	Addr string

	// Replication offset
	Offset int64
	// contains filtered or unexported fields
}

A node represents a real redis server

func (*Node) String

func (n *Node) String() string

type Raft

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

redis-failover uses raft to elect the cluster leader and do monitoring and failover.

func (*Raft) AddMasters

func (r *Raft) AddMasters(addrs []string, timeout time.Duration) error

func (*Raft) AddPeer

func (r *Raft) AddPeer(peerAddr string) error

func (*Raft) Barrier

func (r *Raft) Barrier(timeout time.Duration) error

func (*Raft) Close

func (r *Raft) Close()

func (*Raft) DelMasters

func (r *Raft) DelMasters(addrs []string, timeout time.Duration) error

func (*Raft) DelPeer

func (r *Raft) DelPeer(peerAddr string) error

func (*Raft) GetPeers

func (r *Raft) GetPeers() ([]string, error)

func (*Raft) IsLeader

func (r *Raft) IsLeader() bool

func (*Raft) Leader

func (r *Raft) Leader() string

func (*Raft) LeaderCh

func (r *Raft) LeaderCh() <-chan bool

func (*Raft) SetMasters

func (r *Raft) SetMasters(addrs []string, timeout time.Duration) error

func (*Raft) SetPeers

func (r *Raft) SetPeers(peerAddrs []string) error

type RaftConfig

type RaftConfig struct {
	Addr         string   `toml:"addr"`
	DataDir      string   `toml:"data_dir"`
	LogDir       string   `toml:"log_dir"`
	Cluster      []string `toml:"cluster"`
	ClusterState string   `toml:"cluster_state"`
}

type Zk

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

func (*Zk) AddMasters

func (z *Zk) AddMasters(addrs []string, timeout time.Duration) error

func (*Zk) Barrier

func (z *Zk) Barrier(timeout time.Duration) error

func (*Zk) Close

func (z *Zk) Close()

func (*Zk) DelMasters

func (z *Zk) DelMasters(addrs []string, timeout time.Duration) error

func (*Zk) IsLeader

func (z *Zk) IsLeader() bool

func (*Zk) LeaderCh

func (z *Zk) LeaderCh() <-chan bool

func (*Zk) SetMasters

func (z *Zk) SetMasters(addrs []string, timeout time.Duration) error

type ZkConfig

type ZkConfig struct {
	Addr    []string `toml:"addr"`
	BaseDir string   `toml:"base_dir"`
}

Jump to

Keyboard shortcuts

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