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.
Index ¶
- Constants
- type Handler
- type MysqlGTIDHandler
- func (h *MysqlGTIDHandler) ChangeMasterTo(s *Server, m *Server) error
- func (h *MysqlGTIDHandler) CheckGTIDMode(slaves []*Server) error
- func (h *MysqlGTIDHandler) FindBestSlaves(slaves []*Server) ([]*Server, error)
- func (h *MysqlGTIDHandler) Promote(s *Server) error
- func (h *MysqlGTIDHandler) WaitCatchMaster(s *Server, m *Server) error
- func (h *MysqlGTIDHandler) WaitRelayLogDone(s *Server) error
- type Server
- func (s *Server) Close()
- func (s *Server) Execute(cmd string, args ...interface{}) (r *Result, err error)
- func (s *Server) FetchSlaveExecutePos() (Position, error)
- func (s *Server) FetchSlaveReadPos() (Position, error)
- func (s *Server) LockTables() error
- func (s *Server) MasterStatus() (*Resultset, error)
- func (s *Server) MysqlGTIDMode() (string, error)
- func (s *Server) ResetMaster() error
- func (s *Server) ResetSlave() error
- func (s *Server) SetReadonly(b bool) error
- func (s *Server) SlaveStatus() (*Resultset, error)
- func (s *Server) StartSlave() error
- func (s *Server) StopSlave() error
- func (s *Server) StopSlaveIOThread() error
- func (s *Server) UnlockTables() error
- type User
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 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 ¶
Failover will do below things after the master down
- Elect a slave which has the most up-to-date data with old master
- Promote the slave to new master
- 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 (*Server) FetchSlaveExecutePos ¶
Get current executed binlog filename and position from master
func (*Server) FetchSlaveReadPos ¶
Get current binlog filename and position read from master
func (*Server) LockTables ¶
func (*Server) MasterStatus ¶
func (*Server) MysqlGTIDMode ¶
func (*Server) ResetMaster ¶
func (*Server) ResetSlave ¶
func (*Server) SetReadonly ¶
func (*Server) SlaveStatus ¶
func (*Server) StartSlave ¶
func (*Server) StopSlaveIOThread ¶
func (*Server) UnlockTables ¶
Click to show internal directories.
Click to hide internal directories.