Documentation
¶
Index ¶
- Constants
- Variables
- func GetDB(migrationUuid string, mysql_uri string) (db *gosql.DB, exists bool, err error)
- func GetDBTLSConfigKey(tlsServerName string) string
- func GetReplicationLagFromSlaveStatus(dbVersion string, informationSchemaDb *gosql.DB) (replicationLag time.Duration, err error)
- func GetTableColumns(db *gosql.DB, databaseName, tableName string) (*sql.ColumnList, *sql.ColumnList, error)
- func Kill(db *gosql.DB, connectionID string) error
- func ReplicaTermFor(mysqlVersion string, term string) string
- type BinlogCoordinates
- type ConnectionConfig
- func (this *ConnectionConfig) Duplicate() *ConnectionConfig
- func (this *ConnectionConfig) DuplicateCredentials(key InstanceKey) *ConnectionConfig
- func (this *ConnectionConfig) Equals(other *ConnectionConfig) bool
- func (this *ConnectionConfig) GetDBUri(databaseName string) string
- func (this *ConnectionConfig) RegisterTLSConfig() error
- func (this *ConnectionConfig) String() string
- func (this *ConnectionConfig) TLSConfig() *tls.Config
- func (this *ConnectionConfig) UseTLS(caCertificatePath, clientCertificate, clientKey string, allowInsecure bool) error
- type FileBinlogCoordinates
- func (this *FileBinlogCoordinates) Clone() BinlogCoordinates
- func (this *FileBinlogCoordinates) DetachedCoordinates() (isDetached bool, detachedLogFile string, detachedLogPos string)
- func (this *FileBinlogCoordinates) DisplayString() string
- func (this *FileBinlogCoordinates) Equals(other BinlogCoordinates) bool
- func (this *FileBinlogCoordinates) FileNumber() (int, int)
- func (this *FileBinlogCoordinates) FileNumberDistance(other *FileBinlogCoordinates) int
- func (this *FileBinlogCoordinates) IsEmpty() bool
- func (this *FileBinlogCoordinates) IsLogPosOverflowBeyond4Bytes(preCoordinate *FileBinlogCoordinates) bool
- func (this *FileBinlogCoordinates) NextFileCoordinates() (BinlogCoordinates, error)
- func (this *FileBinlogCoordinates) PreviousFileCoordinates() (BinlogCoordinates, error)
- func (this *FileBinlogCoordinates) PreviousFileCoordinatesBy(offset int) (BinlogCoordinates, error)
- func (this *FileBinlogCoordinates) SmallerThan(other BinlogCoordinates) bool
- func (this *FileBinlogCoordinates) SmallerThanOrEquals(other BinlogCoordinates) bool
- func (this FileBinlogCoordinates) String() string
- type GTIDBinlogCoordinates
- func (this *GTIDBinlogCoordinates) Clone() BinlogCoordinates
- func (this *GTIDBinlogCoordinates) DisplayString() string
- func (this *GTIDBinlogCoordinates) Equals(other BinlogCoordinates) bool
- func (this *GTIDBinlogCoordinates) IsEmpty() bool
- func (this *GTIDBinlogCoordinates) SmallerThan(other BinlogCoordinates) bool
- func (this *GTIDBinlogCoordinates) SmallerThanOrEquals(other BinlogCoordinates) bool
- func (this GTIDBinlogCoordinates) String() string
- type InstanceKey
- func GetInstanceKey(db *gosql.DB) (instanceKey *InstanceKey, err error)
- func GetMasterKeyFromSlaveStatus(dbVersion string, connectionConfig *ConnectionConfig) (masterKey *InstanceKey, err error)
- func NewRawInstanceKey(hostPort string) (*InstanceKey, error)
- func ParseInstanceKey(hostPort string) (*InstanceKey, error)
- func (this *InstanceKey) DetachedKey() *InstanceKey
- func (this *InstanceKey) DisplayString() string
- func (this *InstanceKey) Equals(other *InstanceKey) bool
- func (this *InstanceKey) IsDetached() bool
- func (this *InstanceKey) IsValid() bool
- func (this *InstanceKey) ReattachedKey() *InstanceKey
- func (this *InstanceKey) SmallerThan(other *InstanceKey) bool
- func (this InstanceKey) String() string
- func (this *InstanceKey) StringCode() string
- type InstanceKeyMap
- func (this *InstanceKeyMap) AddKey(key InstanceKey)
- func (this *InstanceKeyMap) AddKeys(keys []InstanceKey)
- func (this *InstanceKeyMap) GetInstanceKeys() []InstanceKey
- func (this *InstanceKeyMap) HasKey(key InstanceKey) bool
- func (this *InstanceKeyMap) Len() int
- func (this *InstanceKeyMap) MarshalJSON() ([]byte, error)
- func (this *InstanceKeyMap) ReadCommaDelimitedList(list string) error
- func (this *InstanceKeyMap) ReadJson(jsonString string) error
- func (this *InstanceKeyMap) ToCommaDelimitedList() string
- func (this *InstanceKeyMap) ToJSON() (string, error)
- func (this *InstanceKeyMap) ToJSONString() string
- type ReplicationLagResult
- type Trigger
Constants ¶
const ( MaxTableNameLength = 64 MaxDBPoolConnections = 3 )
const DefaultInstancePort = 3306
const (
MysqlVersionCutoff = "8.4"
)
const (
TLS_CONFIG_KEY = "ghost"
)
Variables ¶
var MysqlReplicaTermMap = map[string]string{
"Seconds_Behind_Master": "Seconds_Behind_Source",
"Master_Log_File": "Source_Log_File",
"Master_Host": "Source_Host",
"Master_Port": "Source_Port",
"Exec_Master_Log_Pos": "Exec_Source_Log_Pos",
"Read_Master_Log_Pos": "Read_Source_Log_Pos",
"Relay_Master_Log_File": "Relay_Source_Log_File",
"Slave_IO_Running": "Replica_IO_Running",
"Slave_SQL_Running": "Replica_SQL_Running",
"master status": "binary log status",
"slave hosts": "replicas",
"slave status": "replica status",
"slave": "replica",
}
Functions ¶
func GetDBTLSConfigKey ¶ added in v1.1.8
func GetReplicationLagFromSlaveStatus ¶ added in v1.0.48
func GetReplicationLagFromSlaveStatus(dbVersion string, informationSchemaDb *gosql.DB) (replicationLag time.Duration, err error)
GetReplicationLagFromSlaveStatus returns replication lag for a given db; via SHOW SLAVE STATUS
func GetTableColumns ¶ added in v1.0.28
func GetTableColumns(db *gosql.DB, databaseName, tableName string) (*sql.ColumnList, *sql.ColumnList, error)
GetTableColumns reads column list from given table
func ReplicaTermFor ¶ added in v1.1.8
Types ¶
type BinlogCoordinates ¶
type BinlogCoordinates interface {
String() string
DisplayString() string
IsEmpty() bool
Equals(other BinlogCoordinates) bool
SmallerThan(other BinlogCoordinates) bool
SmallerThanOrEquals(other BinlogCoordinates) bool
Clone() BinlogCoordinates
}
func GetReplicationBinlogCoordinates ¶ added in v0.7.16
type ConnectionConfig ¶
type ConnectionConfig struct {
Key InstanceKey
User string
Password string
ImpliedKey *InstanceKey
Timeout float64
TransactionIsolation string
Charset string
// contains filtered or unexported fields
}
ConnectionConfig is the minimal configuration required to connect to a MySQL server
func GetMasterConnectionConfigSafe ¶
func GetMasterConnectionConfigSafe(dbVersion string, connectionConfig *ConnectionConfig, visitedKeys *InstanceKeyMap, allowMasterMaster bool) (masterConfig *ConnectionConfig, err error)
func NewConnectionConfig ¶
func NewConnectionConfig() *ConnectionConfig
func (*ConnectionConfig) Duplicate ¶
func (this *ConnectionConfig) Duplicate() *ConnectionConfig
func (*ConnectionConfig) DuplicateCredentials ¶ added in v1.0.21
func (this *ConnectionConfig) DuplicateCredentials(key InstanceKey) *ConnectionConfig
DuplicateCredentials creates a new connection config with given key and with same credentials as this config
func (*ConnectionConfig) Equals ¶
func (this *ConnectionConfig) Equals(other *ConnectionConfig) bool
func (*ConnectionConfig) GetDBUri ¶
func (this *ConnectionConfig) GetDBUri(databaseName string) string
func (*ConnectionConfig) RegisterTLSConfig ¶ added in v1.1.8
func (this *ConnectionConfig) RegisterTLSConfig() error
func (*ConnectionConfig) String ¶
func (this *ConnectionConfig) String() string
func (*ConnectionConfig) TLSConfig ¶ added in v1.0.48
func (this *ConnectionConfig) TLSConfig() *tls.Config
type FileBinlogCoordinates ¶ added in v1.1.8
FileBinlogCoordinates described binary log coordinates in the form of a binlog file & log position.
func NewFileBinlogCoordinates ¶ added in v1.1.8
func NewFileBinlogCoordinates(logFile string, logPos int64) *FileBinlogCoordinates
func ParseFileBinlogCoordinates ¶ added in v1.1.8
func ParseFileBinlogCoordinates(logFileLogPos string) (*FileBinlogCoordinates, error)
ParseFileBinlogCoordinates parses a log file/position string into a *BinlogCoordinates struct.
func (*FileBinlogCoordinates) Clone ¶ added in v1.1.8
func (this *FileBinlogCoordinates) Clone() BinlogCoordinates
func (*FileBinlogCoordinates) DetachedCoordinates ¶ added in v1.1.8
func (this *FileBinlogCoordinates) DetachedCoordinates() (isDetached bool, detachedLogFile string, detachedLogPos string)
FileSmallerThan returns true if this coordinate's file is strictly smaller than the other's.
func (*FileBinlogCoordinates) DisplayString ¶ added in v1.1.8
func (this *FileBinlogCoordinates) DisplayString() string
DisplayString returns a user-friendly string representation of these coordinates
func (*FileBinlogCoordinates) Equals ¶ added in v1.1.8
func (this *FileBinlogCoordinates) Equals(other BinlogCoordinates) bool
Equals tests equality of this coordinate and another one.
func (*FileBinlogCoordinates) FileNumber ¶ added in v1.1.8
func (this *FileBinlogCoordinates) FileNumber() (int, int)
FileNumber returns the numeric value of the file, and the length in characters representing the number in the filename. Example: FileNumber() of mysqld.log.000789 is (789, 6)
func (*FileBinlogCoordinates) FileNumberDistance ¶ added in v1.1.8
func (this *FileBinlogCoordinates) FileNumberDistance(other *FileBinlogCoordinates) int
FileNumberDistance returns the numeric distance between this coordinate's file number and the other's. Effectively it means "how many rotates/FLUSHes would make these coordinates's file reach the other's"
func (*FileBinlogCoordinates) IsEmpty ¶ added in v1.1.8
func (this *FileBinlogCoordinates) IsEmpty() bool
IsEmpty returns true if the log file is empty, unnamed
func (*FileBinlogCoordinates) IsLogPosOverflowBeyond4Bytes ¶ added in v1.1.8
func (this *FileBinlogCoordinates) IsLogPosOverflowBeyond4Bytes(preCoordinate *FileBinlogCoordinates) bool
IsLogPosOverflowBeyond4Bytes returns true if the coordinate endpos is overflow beyond 4 bytes. The binlog event end_log_pos field type is defined as uint32, 4 bytes. https://github.com/go-mysql-org/go-mysql/blob/master/replication/event.go https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_replication_binlog_event.html#sect_protocol_replication_binlog_event_header Issue: https://github.com/github/gh-ost/issues/1366
func (*FileBinlogCoordinates) NextFileCoordinates ¶ added in v1.1.8
func (this *FileBinlogCoordinates) NextFileCoordinates() (BinlogCoordinates, error)
PreviousFileCoordinates guesses the filename of the previous binlog/relaylog
func (*FileBinlogCoordinates) PreviousFileCoordinates ¶ added in v1.1.8
func (this *FileBinlogCoordinates) PreviousFileCoordinates() (BinlogCoordinates, error)
PreviousFileCoordinates guesses the filename of the previous binlog/relaylog
func (*FileBinlogCoordinates) PreviousFileCoordinatesBy ¶ added in v1.1.8
func (this *FileBinlogCoordinates) PreviousFileCoordinatesBy(offset int) (BinlogCoordinates, error)
PreviousFileCoordinatesBy guesses the filename of the previous binlog/relaylog, by given offset (number of files back)
func (*FileBinlogCoordinates) SmallerThan ¶ added in v1.1.8
func (this *FileBinlogCoordinates) SmallerThan(other BinlogCoordinates) bool
SmallerThan returns true if this coordinate is strictly smaller than the other.
func (*FileBinlogCoordinates) SmallerThanOrEquals ¶ added in v1.1.8
func (this *FileBinlogCoordinates) SmallerThanOrEquals(other BinlogCoordinates) bool
SmallerThanOrEquals returns true if this coordinate is the same or equal to the other one. We do NOT compare the type so we can not use this.Equals()
func (FileBinlogCoordinates) String ¶ added in v1.1.8
func (this FileBinlogCoordinates) String() string
String returns a user-friendly string representation of these coordinates
type GTIDBinlogCoordinates ¶ added in v1.1.8
type GTIDBinlogCoordinates struct {
GTIDSet *gomysql.MysqlGTIDSet
UUIDSet *gomysql.UUIDSet
}
GTIDBinlogCoordinates describe binary log coordinates in MySQL GTID format.
func NewGTIDBinlogCoordinates ¶ added in v1.1.8
func NewGTIDBinlogCoordinates(gtidSet string) (*GTIDBinlogCoordinates, error)
NewGTIDBinlogCoordinates parses a MySQL GTID set into a *GTIDBinlogCoordinates struct.
func (*GTIDBinlogCoordinates) Clone ¶ added in v1.1.8
func (this *GTIDBinlogCoordinates) Clone() BinlogCoordinates
func (*GTIDBinlogCoordinates) DisplayString ¶ added in v1.1.8
func (this *GTIDBinlogCoordinates) DisplayString() string
DisplayString returns a user-friendly string representation of these current UUID set or the full GTID set.
func (*GTIDBinlogCoordinates) Equals ¶ added in v1.1.8
func (this *GTIDBinlogCoordinates) Equals(other BinlogCoordinates) bool
Equals tests equality of this coordinate and another one.
func (*GTIDBinlogCoordinates) IsEmpty ¶ added in v1.1.8
func (this *GTIDBinlogCoordinates) IsEmpty() bool
IsEmpty returns true if the GTID set is empty.
func (*GTIDBinlogCoordinates) SmallerThan ¶ added in v1.1.8
func (this *GTIDBinlogCoordinates) SmallerThan(other BinlogCoordinates) bool
SmallerThan returns true if this coordinate is strictly smaller than the other.
func (*GTIDBinlogCoordinates) SmallerThanOrEquals ¶ added in v1.1.8
func (this *GTIDBinlogCoordinates) SmallerThanOrEquals(other BinlogCoordinates) bool
SmallerThanOrEquals returns true if this coordinate is the same or equal to the other one.
func (GTIDBinlogCoordinates) String ¶ added in v1.1.8
func (this GTIDBinlogCoordinates) String() string
String returns a user-friendly string representation of these full GTID set.
type InstanceKey ¶
InstanceKey is an instance indicator, identified by hostname and port
func GetInstanceKey ¶ added in v0.9.6
func GetInstanceKey(db *gosql.DB) (instanceKey *InstanceKey, err error)
GetInstanceKey reads hostname and port on given DB
func GetMasterKeyFromSlaveStatus ¶
func GetMasterKeyFromSlaveStatus(dbVersion string, connectionConfig *ConnectionConfig) (masterKey *InstanceKey, err error)
func NewRawInstanceKey ¶
func NewRawInstanceKey(hostPort string) (*InstanceKey, error)
ParseInstanceKey will parse an InstanceKey from a string representation such as 127.0.0.1:3306
func ParseInstanceKey ¶ added in v1.1.1
func ParseInstanceKey(hostPort string) (*InstanceKey, error)
ParseInstanceKey will parse an InstanceKey from a string representation such as 127.0.0.1:3306. The port part is optional; there will be no name resolve
func (*InstanceKey) DetachedKey ¶
func (this *InstanceKey) DetachedKey() *InstanceKey
DetachedKey returns an instance key whose hostname is detached: invalid, but recoverable
func (*InstanceKey) DisplayString ¶
func (this *InstanceKey) DisplayString() string
DisplayString returns a user-friendly string representation of this key
func (*InstanceKey) Equals ¶
func (this *InstanceKey) Equals(other *InstanceKey) bool
Equals tests equality between this key and another key
func (*InstanceKey) IsDetached ¶
func (this *InstanceKey) IsDetached() bool
IsDetached returns 'true' when this hostname is logically "detached"
func (*InstanceKey) IsValid ¶
func (this *InstanceKey) IsValid() bool
IsValid uses simple heuristics to see whether this key represents an actual instance
func (*InstanceKey) ReattachedKey ¶
func (this *InstanceKey) ReattachedKey() *InstanceKey
ReattachedKey returns an instance key whose hostname is detached: invalid, but recoverable
func (*InstanceKey) SmallerThan ¶
func (this *InstanceKey) SmallerThan(other *InstanceKey) bool
SmallerThan returns true if this key is dictionary-smaller than another. This is used for consistent sorting/ordering; there's nothing magical about it.
func (InstanceKey) String ¶
func (this InstanceKey) String() string
String returns a user-friendly string representation of this key
func (*InstanceKey) StringCode ¶
func (this *InstanceKey) StringCode() string
StringCode returns an official string representation of this key
type InstanceKeyMap ¶
type InstanceKeyMap map[InstanceKey]bool
InstanceKeyMap is a convenience struct for listing InstanceKey-s
func NewInstanceKeyMap ¶
func NewInstanceKeyMap() *InstanceKeyMap
func (*InstanceKeyMap) AddKey ¶
func (this *InstanceKeyMap) AddKey(key InstanceKey)
AddKey adds a single key to this map
func (*InstanceKeyMap) AddKeys ¶
func (this *InstanceKeyMap) AddKeys(keys []InstanceKey)
AddKeys adds all given keys to this map
func (*InstanceKeyMap) GetInstanceKeys ¶
func (this *InstanceKeyMap) GetInstanceKeys() []InstanceKey
GetInstanceKeys returns keys in this map in the form of an array
func (*InstanceKeyMap) HasKey ¶
func (this *InstanceKeyMap) HasKey(key InstanceKey) bool
HasKey checks if given key is within the map
func (*InstanceKeyMap) Len ¶
func (this *InstanceKeyMap) Len() int
func (*InstanceKeyMap) MarshalJSON ¶
func (this *InstanceKeyMap) MarshalJSON() ([]byte, error)
MarshalJSON will marshal this map as JSON
func (*InstanceKeyMap) ReadCommaDelimitedList ¶
func (this *InstanceKeyMap) ReadCommaDelimitedList(list string) error
ReadJson unmarshalls a json into this map
func (*InstanceKeyMap) ReadJson ¶
func (this *InstanceKeyMap) ReadJson(jsonString string) error
ReadJson unmarshalls a json into this map
func (*InstanceKeyMap) ToCommaDelimitedList ¶
func (this *InstanceKeyMap) ToCommaDelimitedList() string
ToCommaDelimitedList will export this map in comma delimited format
func (*InstanceKeyMap) ToJSON ¶
func (this *InstanceKeyMap) ToJSON() (string, error)
ToJSON will marshal this map as JSON
func (*InstanceKeyMap) ToJSONString ¶
func (this *InstanceKeyMap) ToJSONString() string
ToJSONString will marshal this map as JSON
type ReplicationLagResult ¶ added in v1.0.6
type ReplicationLagResult struct {
Key InstanceKey
Lag time.Duration
Err error
}
func NewNoReplicationLagResult ¶ added in v1.0.35
func NewNoReplicationLagResult() *ReplicationLagResult
func (*ReplicationLagResult) HasLag ¶ added in v1.0.35
func (this *ReplicationLagResult) HasLag() bool