failover

package
v0.0.0-...-dbb064b Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2016 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Failover supports to promote a new master and let other slaves replicate from it automatically.

Failover does not support monitoring whether a master is alive or not, and will think the master is down.

This package is still in development and could not be used in production environment.

Index

Constants

View Source
const (
	IOThreadType  = "IO_THREAD"
	SQLThreadType = "SQL_THREAD"
)
View Source
const (
	GTIDModeOn  = "ON"
	GTIDModeOff = "OFF"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler interface {
	// Promote slave s to master
	Promote(s *Server) error

	// Change slave s to master m and replicate from it
	ChangeMasterTo(s *Server, m *Server) error

	// Ensure all relay log done, it will stop slave IO_THREAD
	// You must start slave again if you want to do replication continuatively
	WaitRelayLogDone(s *Server) error

	// Wait until slave s catch all data from master m at current time
	WaitCatchMaster(s *Server, m *Server) error

	// Find best slave which has the most up-to-date data from master
	FindBestSlaves(slaves []*Server) ([]*Server, error)

	// Check all slaves have gtid enabled
	CheckGTIDMode(slaves []*Server) error
}

type MariadbGTIDHandler

type MariadbGTIDHandler struct {
	Handler
}

Limiatation + Multi source replication is not supported + Slave can not handle write transactions, so maybe readonly or strict_mode = 1 is better

func (*MariadbGTIDHandler) ChangeMasterTo

func (h *MariadbGTIDHandler) ChangeMasterTo(s *Server, m *Server) error

func (*MariadbGTIDHandler) CheckGTIDMode

func (h *MariadbGTIDHandler) CheckGTIDMode(slaves []*Server) error

func (*MariadbGTIDHandler) FindBestSlaves

func (h *MariadbGTIDHandler) FindBestSlaves(slaves []*Server) ([]*Server, error)

func (*MariadbGTIDHandler) Promote

func (h *MariadbGTIDHandler) Promote(s *Server) error

func (*MariadbGTIDHandler) WaitCatchMaster

func (h *MariadbGTIDHandler) WaitCatchMaster(s *Server, m *Server) error

func (*MariadbGTIDHandler) WaitRelayLogDone

func (h *MariadbGTIDHandler) WaitRelayLogDone(s *Server) error

type MysqlGTIDHandler

type MysqlGTIDHandler struct {
	Handler
}

func (*MysqlGTIDHandler) ChangeMasterTo

func (h *MysqlGTIDHandler) ChangeMasterTo(s *Server, m *Server) error

func (*MysqlGTIDHandler) CheckGTIDMode

func (h *MysqlGTIDHandler) CheckGTIDMode(slaves []*Server) error

func (*MysqlGTIDHandler) FindBestSlaves

func (h *MysqlGTIDHandler) FindBestSlaves(slaves []*Server) ([]*Server, error)

func (*MysqlGTIDHandler) Promote

func (h *MysqlGTIDHandler) Promote(s *Server) error

func (*MysqlGTIDHandler) WaitCatchMaster

func (h *MysqlGTIDHandler) WaitCatchMaster(s *Server, m *Server) error

func (*MysqlGTIDHandler) WaitRelayLogDone

func (h *MysqlGTIDHandler) WaitRelayLogDone(s *Server) error

type Server

type Server struct {
	Addr string

	User     User
	ReplUser User
	// contains filtered or unexported fields
}

func Failover

func Failover(flavor string, slaves []*Server) ([]*Server, error)

Failover will do below things after the master down

  1. Elect a slave which has the most up-to-date data with old master
  2. Promote the slave to new master
  3. Change other slaves to the new master

Limitation:

1, All slaves must have the same master before, Failover will check using master server id or uuid
2, If the failover error, the whole topology may be wrong, we must handle this error manually
3, Slaves must have same replication mode, all use GTID or not

func NewServer

func NewServer(addr string, user User, replUser User) *Server

func (*Server) Close

func (s *Server) Close()

func (*Server) Execute

func (s *Server) Execute(cmd string, args ...interface{}) (r *Result, err error)

func (*Server) FetchSlaveExecutePos

func (s *Server) FetchSlaveExecutePos() (Position, error)

Get current executed binlog filename and position from master

func (*Server) FetchSlaveReadPos

func (s *Server) FetchSlaveReadPos() (Position, error)

Get current binlog filename and position read from master

func (*Server) LockTables

func (s *Server) LockTables() error

func (*Server) MasterPosWait

func (s *Server) MasterPosWait(pos Position, timeout int) error

func (*Server) MasterStatus

func (s *Server) MasterStatus() (*Resultset, error)

func (*Server) MysqlGTIDMode

func (s *Server) MysqlGTIDMode() (string, error)

func (*Server) ResetMaster

func (s *Server) ResetMaster() error

func (*Server) ResetSlave

func (s *Server) ResetSlave() error

func (*Server) ResetSlaveALL

func (s *Server) ResetSlaveALL() error

func (*Server) SetReadonly

func (s *Server) SetReadonly(b bool) error

func (*Server) SlaveStatus

func (s *Server) SlaveStatus() (*Resultset, error)

func (*Server) StartSlave

func (s *Server) StartSlave() error

func (*Server) StopSlave

func (s *Server) StopSlave() error

func (*Server) StopSlaveIOThread

func (s *Server) StopSlaveIOThread() error

func (*Server) UnlockTables

func (s *Server) UnlockTables() error

type User

type User struct {
	Name     string
	Password string
}

Jump to

Keyboard shortcuts

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