Documentation ¶
Overview ¶
Package msops implements series of mysql ops methods.
Index ¶
- func ChangeMasterTo(slaveEndpoint, masterEndpoint string, useGTID bool) error
- func GetGlobalStatus(endpoint, pattern string) (map[string]string, error)
- func GetGlobalVariables(endpoint, pattern string) (map[string]string, error)
- func KillProcesses(endpoint string, whiteUsers ...string) error
- func Register(endpoint, dbaUser, dbaPassword, replUser, replPassword string, ...) error
- func ResetSlave(endpoint string, resetAll bool) error
- func SetGlobalVariable(endpoint, key string, value interface{}) error
- func StartSlave(endpoint string) error
- func StopSlave(endpoint string) error
- func Unregister(endpoint string)
- type InnoDBStatus
- type Instance
- type InstanceStatus
- type MasterStatus
- type Process
- type ReplicationStatus
- type SlaveStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChangeMasterTo ¶
ChangeMasterTo makes slaveEndpoint as a slave of masterEndpoint from now on. Use MASTER_AUTO_POSITION=1 instead of specifying the binlog file and position if useGTID is true.
func GetGlobalStatus ¶
GetGlobalStatus executes "SHOW GLOBAL STATUS LIKE pattern" and returns the resultset.
func GetGlobalVariables ¶
GetGlobalVariables executes "SHOW GLOBAL VARIABLES LIKE pattern" and returns the resultset.
func KillProcesses ¶
KillProcesses kills all the connection threads except the ones of whiteUsers.
func Register ¶
func Register(endpoint, dbaUser, dbaPassword, replUser, replPassword string, params map[string]string) error
Register registers the instance of endpoint with opening the connection with user 'dbaUser', password 'dbaPassword'.
'replUser' and 'replPassword' are used to establish replication by other endpoints.
'params' are the k-v params appending to go-mysql-driver connection string.
'dbaUser' should have the following privileges at least: RELOAD, PROCESS, SUPER, REPLICATION CLIENT, REPLICATION SLAVE.
'replUser' should have the following privileges at least: PROCESS, REPLICATION SLAVE.
'endpoint' show have the form "host:port".
If the final connection string generated is invalid, an error will be returned.
func ResetSlave ¶
ResetSlave executes "RESET SLAVE ALL" if resetAll is true. Otherwise executes "RESET SLAVE".
func SetGlobalVariable ¶
SetGlobalVariable executes the statement 'SET GLOBAL key=value'.
func StartSlave ¶
StartSlave executes "START SLAVE" at the endpoint.
func Unregister ¶
func Unregister(endpoint string)
Unregister deletes the information from msops's connection pool and closes the connections to endpoint.
Types ¶
type InnoDBStatus ¶
type InnoDBStatus struct { InnodbMutexSpinWaits int InnodbMutexSpinRounds int InnodbMutexOSWaits int }
InnoDBStatus represents the innodb engine status of one endpoint. Based on 5.6.30-log MySQL Community Server.
Field specification can be found at https://dev.mysql.com/doc/refman/5.6/en/innodb-standard-monitor.html
func GetInnoDBStatus ¶
func GetInnoDBStatus(endpoint string) (InnoDBStatus, error)
GetInnoDBStatus executes "SHOW engine InnoDB STATUS" and returns the 'Status' field.
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance records the connect information.
type InstanceStatus ¶
type InstanceStatus int
InstanceStatus represents the running status of one instance.
The judgement is according to the result of db.Conn.Ping().
const ( // InstanceOK implies that we can connect to the instance. InstanceOK InstanceStatus = iota // InstanceERROR implies that we can't connect to the instance. InstanceERROR // InstanceUnregistered implies that we haven't registered the instance. InstanceUnregistered )
func CheckInstance ¶
func CheckInstance(endpoint string) InstanceStatus
CheckInstance checks the status of a instance with the endpoint.
type MasterStatus ¶
type MasterStatus struct { File string Position int BinlogDoDB string BinlogIgnoreDB string ExecutedGtidSet string }
MasterStatus represents the master status of one endpoint. Based on 5.6.30-log MySQL Community Server.
Field specification can be found at https://dev.mysql.com/doc/refman/5.6/en/show-master-status.html
func GetMasterStatus ¶
func GetMasterStatus(endpoint string) (MasterStatus, error)
GetMasterStatus executes "SHOW MASTER STATUS" and returns the resultset.
type Process ¶
type Process struct { ID int User string Host string DB string Command string Time int State string Info string }
Process represents one row data of processlist. Based on 5.6.30-log MySQL Community Server.
Field specification can be found at https://dev.mysql.com/doc/refman/5.6/en/show-processlist.html
func GetProcessList ¶
GetProcessList executes "SHOW PROCESSLIST" and returns the resultset.
type ReplicationStatus ¶
type ReplicationStatus int
ReplicationStatus represents the replication status between to instance.
The judgement is according to the result of `SHOW SLAVE STATUS` and `SHOW MASTER STATUS`.
Comparing the binlog file and binlog positions between master and slave.
const ( // ReplicationOK implies that in the slave status of the slave instance, // 'Master_Host' and 'Master_Port' are the same as the master's, // 'Slave_SQL_Running' and 'Slave_IO_Running' are both 'Yes', // 'Master_Log_File' and 'Master_Log_Position'equals to '0'. ReplicationOK ReplicationStatus = iota // ReplicationError implies that in the slave status of the slave instance, // 'Master_Host' and 'Master_Port' are the same as the master's, // 'Slave_SQL_Running' and 'Slave_IO_Running' are not both 'Yes', // and 'Last_Error' is not empty. ReplicationError // ReplicationSyning implies that in the slave status of the slave instance, // 'Master_Host' and 'Master_Port' are the same as the master's, // 'Slave_SQL_Running' and 'Slave_IO_Running' are both 'Yes', // 'Second_Behind_Master' is larger than '0'. ReplicationSyning // ReplicationPausing implies that in the slave status of the slave instance, // 'Master_Host' and 'Master_Port' are the same as the master's, // and 'Slave_SQL_Running' and 'Slave_IO_Running' are both 'no'. ReplicationPausing // ReplicationWrongMaster implies that in the slave status of the slave instance, // 'Master_Host' and 'Master_Port' are not the same as the master's. ReplicationWrongMaster // ReplicationNone implies that the slave status of the endpoint is empty. ReplicationNone // ReplicationUnknown implies that we can't connect to the slave instance. ReplicationUnknown )
func CheckReplication ¶
func CheckReplication(slaveEndpoint, masterEndpoint string) ReplicationStatus
CheckReplication checks the replicaton status between slaveEndpoint and masterEndpoint. Note that if one of slave or master is not registered, or getting MasterStatus and SlaveStatus failed, ReplicationUnknown is returned.
type SlaveStatus ¶
type SlaveStatus struct { SlaveIOState string MasterHost string MasterUser string MasterPort int ConnectRetry string MasterLogFile string ReadMasterLogPos int RelayLogFile string RelayLogPos int RelayMasterLogFile string SlaveIORunning string SlaveSQLRunning string ReplicateDoDB string ReplicateIgnoreDB string ReplicateDoTable string ReplicateIgnoreTable string ReplicateWildDoTable string ReplicateWildIgnoreTable string LastErrno int LastError string SkipCounter int ExecMasterLogPos int RelayLogSpace int UntilCondition string UntilLogFile string UntilLogPos int MasterSSLAllowed string MasterSSLCAFile string MasterSSLCAPath string MasterSSLCert string MasterSSLCipher string MasterSSLKey string SecondsBehindMaster int MasterSSLVerifyServerCert string LastIOErrno int LastIOError string LastSQLErrno int LastSQLError string ReplicateIgnoreServerIds string MasterServerID int MasterUUID string MasterInfoFile string SQLDelay int SQLRemainingDelay string SlaveSQLRunningState string MasterRetryCount int MasterBind string LastIOErrorTimestamp string LastSQLErrorTimestamp string MasterSSLCrl string MasterSSLCrlpath string RetrievedGtidSet string ExecutedGtidSet string AutoPosition bool }
SlaveStatus represents the slave status of one endpoint. Based on 5.6.30-log MySQL Community Server.
Field specification can be found at https://dev.mysql.com/doc/refman/5.6/en/show-slave-status.html
func GetSlaveStatus ¶
func GetSlaveStatus(endpoint string) (SlaveStatus, error)
GetSlaveStatus executes "SHOW SLAVE STATUS" and returns the resultset.