Documentation
¶
Index ¶
- Constants
- Variables
- func Backup(ctx context.Context, mysqld MysqlDaemon, logger logutil.Logger, ...) error
- func ConcurrentMap(concurrency, n int, fun MapFunc) error
- func CreateReparentJournal() []string
- func FindSlaves(mysqld MysqlDaemon) ([]string, error)
- func GetPermissions(mysqld MysqlDaemon) (*tabletmanagerdatapb.Permissions, error)
- func NewMariadbBinlogEvent(buf []byte) replication.BinlogEvent
- func NewMysql56BinlogEvent(buf []byte) replication.BinlogEvent
- func PopulateReparentJournal(timeCreatedNS int64, actionName, masterAlias string, pos replication.Position) string
- func RegisterFlags()
- func ResolveTables(mysqld MysqlDaemon, dbName string, tables []string) ([]string, error)
- func Restore(ctx context.Context, mysqld MysqlDaemon, dir string, restoreConcurrency int, ...) (replication.Position, error)
- func SnapshotDir(uid uint32) string
- func StartSlave(md MysqlDaemon, hookExtraEnv map[string]string) error
- func StopSlave(md MysqlDaemon, hookExtraEnv map[string]string) error
- func TabletDir(uid uint32) string
- func TopLevelDirs() []string
- func WaitBlpPosition(mysqld MysqlDaemon, sql string, replicationPosition string, ...) error
- func WaitForSlaveStart(mysqld MysqlDaemon, slaveStartDeadline int) error
- type BackupManifest
- type FakeMysqlDaemon
- func (fmd *FakeMysqlDaemon) ApplySchemaChange(dbName string, change *tmutils.SchemaChange) (*tabletmanagerdatapb.SchemaChangeResult, error)
- func (fmd *FakeMysqlDaemon) CheckSuperQueryList() error
- func (fmd *FakeMysqlDaemon) Close()
- func (fmd *FakeMysqlDaemon) Cnf() *Mycnf
- func (fmd *FakeMysqlDaemon) DemoteMaster() (replication.Position, error)
- func (fmd *FakeMysqlDaemon) DisableBinlogPlayback() error
- func (fmd *FakeMysqlDaemon) EnableBinlogPlayback() error
- func (fmd *FakeMysqlDaemon) ExecuteSuperQueryList(queryList []string) error
- func (fmd *FakeMysqlDaemon) FetchSuperQuery(query string) (*sqltypes.Result, error)
- func (fmd *FakeMysqlDaemon) GetAppConnection() (dbconnpool.PoolConnection, error)
- func (fmd *FakeMysqlDaemon) GetDbaConnection() (*dbconnpool.DBConnection, error)
- func (fmd *FakeMysqlDaemon) GetMysqlPort() (int32, error)
- func (fmd *FakeMysqlDaemon) GetSchema(dbName string, tables, excludeTables []string, includeViews bool) (*tabletmanagerdatapb.SchemaDefinition, error)
- func (fmd *FakeMysqlDaemon) IsReadOnly() (bool, error)
- func (fmd *FakeMysqlDaemon) MasterPosition() (replication.Position, error)
- func (fmd *FakeMysqlDaemon) NewSlaveConnection() (*SlaveConnection, error)
- func (fmd *FakeMysqlDaemon) PreflightSchemaChange(dbName string, changes []string) ([]*tabletmanagerdatapb.SchemaChangeResult, error)
- func (fmd *FakeMysqlDaemon) PromoteSlave(hookExtraEnv map[string]string) (replication.Position, error)
- func (fmd *FakeMysqlDaemon) ResetReplicationCommands() ([]string, error)
- func (fmd *FakeMysqlDaemon) RunMysqlUpgrade() error
- func (fmd *FakeMysqlDaemon) SemiSyncEnabled() (master, slave bool)
- func (fmd *FakeMysqlDaemon) SetMasterCommands(masterHost string, masterPort int) ([]string, error)
- func (fmd *FakeMysqlDaemon) SetReadOnly(on bool) error
- func (fmd *FakeMysqlDaemon) SetSemiSyncEnabled(master, slave bool) error
- func (fmd *FakeMysqlDaemon) SetSlavePositionCommands(pos replication.Position) ([]string, error)
- func (fmd *FakeMysqlDaemon) Shutdown(ctx context.Context, waitForMysqld bool) error
- func (fmd *FakeMysqlDaemon) SlaveStatus() (replication.Status, error)
- func (fmd *FakeMysqlDaemon) Start(ctx context.Context) error
- func (fmd *FakeMysqlDaemon) TabletDir() string
- func (fmd *FakeMysqlDaemon) Wait(ctx context.Context) error
- func (fmd *FakeMysqlDaemon) WaitForReparentJournal(ctx context.Context, timeCreatedNS int64) error
- func (fmd *FakeMysqlDaemon) WaitMasterPos(pos replication.Position, waitTimeout time.Duration) error
- type FileEntry
- type MapFunc
- type Mycnf
- type MysqlDaemon
- type MysqlFlavor
- type Mysqld
- func (mysqld *Mysqld) ApplySchemaChange(dbName string, change *tmutils.SchemaChange) (*tabletmanagerdatapb.SchemaChangeResult, error)
- func (mysqld *Mysqld) Close()
- func (mysqld *Mysqld) Cnf() *Mycnf
- func (mysqld *Mysqld) DemoteMaster() (rp replication.Position, err error)
- func (mysqld *Mysqld) DisableBinlogPlayback() error
- func (mysqld *Mysqld) EnableBinlogPlayback() error
- func (mysqld *Mysqld) ExecuteSuperQuery(query string) error
- func (mysqld *Mysqld) ExecuteSuperQueryList(queryList []string) error
- func (mysqld *Mysqld) FetchSuperQuery(query string) (*sqltypes.Result, error)
- func (mysqld *Mysqld) GetAppConnection() (dbconnpool.PoolConnection, error)
- func (mysqld *Mysqld) GetColumns(dbName, table string) ([]string, error)
- func (mysqld *Mysqld) GetDbaConnection() (*dbconnpool.DBConnection, error)
- func (mysqld *Mysqld) GetMysqlPort() (int32, error)
- func (mysqld *Mysqld) GetPrimaryKeyColumns(dbName, table string) ([]string, error)
- func (mysqld *Mysqld) GetSchema(dbName string, tables, excludeTables []string, includeViews bool) (*tabletmanagerdatapb.SchemaDefinition, error)
- func (mysqld *Mysqld) Init(ctx context.Context, initDBSQLFile string) error
- func (mysqld *Mysqld) IsReadOnly() (bool, error)
- func (mysqld *Mysqld) MasterPosition() (rp replication.Position, err error)
- func (mysqld *Mysqld) NewSlaveConnection() (*SlaveConnection, error)
- func (mysqld *Mysqld) OnTerm(f func())
- func (mysqld *Mysqld) PreflightSchemaChange(dbName string, changes []string) ([]*tabletmanagerdatapb.SchemaChangeResult, error)
- func (mysqld *Mysqld) PromoteSlave(hookExtraEnv map[string]string) (replication.Position, error)
- func (mysqld *Mysqld) ResetReplicationCommands() ([]string, error)
- func (mysqld *Mysqld) RunMysqlUpgrade() error
- func (mysqld *Mysqld) SemiSyncEnabled() (master, slave bool)
- func (mysqld *Mysqld) SetMasterCommands(masterHost string, masterPort int) ([]string, error)
- func (mysqld *Mysqld) SetReadOnly(on bool) error
- func (mysqld *Mysqld) SetSemiSyncEnabled(master, slave bool) error
- func (mysqld *Mysqld) SetSlavePositionCommands(pos replication.Position) ([]string, error)
- func (mysqld *Mysqld) Shutdown(ctx context.Context, waitForMysqld bool) error
- func (mysqld *Mysqld) SlaveStatus() (replication.Status, error)
- func (mysqld *Mysqld) Start(ctx context.Context) error
- func (mysqld *Mysqld) TabletDir() string
- func (mysqld *Mysqld) Teardown(ctx context.Context, force bool) error
- func (mysqld *Mysqld) Wait(ctx context.Context) error
- func (mysqld *Mysqld) WaitForReparentJournal(ctx context.Context, timeCreatedNS int64) error
- func (mysqld *Mysqld) WaitMasterPos(targetPos replication.Position, waitTimeout time.Duration) error
- type SlaveConnection
Constants ¶
const ( // BinlogChecksumAlgOff indicates that checksums are supported but off. BinlogChecksumAlgOff = 0 // BinlogChecksumAlgCRC32 indicates that CRC32 checksums are used. BinlogChecksumAlgCRC32 = 1 // BinlogChecksumAlgUndef indicates that checksums are not supported. BinlogChecksumAlgUndef = 255 )
These constants are common between MariaDB 10.0 and MySQL 5.6.
const ( // SQLStartSlave is the SQl command issued to start MySQL replication SQLStartSlave = "START SLAVE" // SQLStopSlave is the SQl command issued to stop MySQL replication SQLStopSlave = "STOP SLAVE" )
Variables ¶
var ( // ErrNoBackup is returned when there is no backup. ErrNoBackup = errors.New("no available backup") // ErrExistingDB is returned when there's already an active DB. ErrExistingDB = errors.New("skipping restore due to existing database") )
var ( // ErrNotSlave means there is no slave status ErrNotSlave = errors.New("no slave status") // ErrNotMaster means there is no master status ErrNotMaster = errors.New("no master status") )
Functions ¶
func Backup ¶
func Backup(ctx context.Context, mysqld MysqlDaemon, logger logutil.Logger, dir, name string, backupConcurrency int, hookExtraEnv map[string]string) error
Backup is the main entry point for a backup: - uses the BackupStorage service to store a new backup - shuts down Mysqld during the backup - remember if we were replicating, restore the exact same state
func ConcurrentMap ¶
ConcurrentMap applies fun in a concurrent manner on integers from 0 to n-1 (they are assumed to be indexes of some slice containing items to be processed). The first error returned by a fun application will returned (subsequent errors will only be logged). It will use concurrency goroutines.
func CreateReparentJournal ¶
func CreateReparentJournal() []string
CreateReparentJournal returns the commands to execute to create the _vt.reparent_journal table. It is safe to run these commands even if the table already exists.
func FindSlaves ¶
func FindSlaves(mysqld MysqlDaemon) ([]string, error)
FindSlaves gets IP addresses for all currently connected slaves.
func GetPermissions ¶
func GetPermissions(mysqld MysqlDaemon) (*tabletmanagerdatapb.Permissions, error)
GetPermissions lists the permissions on the mysqld
func NewMariadbBinlogEvent ¶
func NewMariadbBinlogEvent(buf []byte) replication.BinlogEvent
NewMariadbBinlogEvent creates a BinlogEvent instance from given byte array
func NewMysql56BinlogEvent ¶
func NewMysql56BinlogEvent(buf []byte) replication.BinlogEvent
NewMysql56BinlogEvent creates a BinlogEvent from given byte array
func PopulateReparentJournal ¶
func PopulateReparentJournal(timeCreatedNS int64, actionName, masterAlias string, pos replication.Position) string
PopulateReparentJournal returns the SQL command to use to populate the _vt.reparent_journal table, as well as the time_created_ns value used.
func RegisterFlags ¶
func RegisterFlags()
RegisterFlags registers the command line flags for specifying the values of a mycnf config file. See NewMycnfFromFlags to get the supported modes.
func ResolveTables ¶
func ResolveTables(mysqld MysqlDaemon, dbName string, tables []string) ([]string, error)
ResolveTables returns a list of actual tables+views matching a list of regexps
func Restore ¶
func Restore(ctx context.Context, mysqld MysqlDaemon, dir string, restoreConcurrency int, hookExtraEnv map[string]string) (replication.Position, error)
Restore is the main entry point for backup restore. If there is no appropriate backup on the BackupStorage, Restore logs an error and returns ErrNoBackup. Any other error is returned.
func SnapshotDir ¶
SnapshotDir returns the default directory for a tablet's snapshots
func StartSlave ¶
func StartSlave(md MysqlDaemon, hookExtraEnv map[string]string) error
StartSlave starts a slave on the provided MysqldDaemon
func StopSlave ¶
func StopSlave(md MysqlDaemon, hookExtraEnv map[string]string) error
StopSlave stops a slave on the provided MysqldDaemon
func TopLevelDirs ¶
func TopLevelDirs() []string
TopLevelDirs returns the list of directories in the toplevel tablet directory that might be located in a different place.
func WaitBlpPosition ¶
func WaitBlpPosition(mysqld MysqlDaemon, sql string, replicationPosition string, waitTimeout time.Duration) error
WaitBlpPosition will wait for the filtered replication to reach at least the provided position.
func WaitForSlaveStart ¶
func WaitForSlaveStart(mysqld MysqlDaemon, slaveStartDeadline int) error
WaitForSlaveStart waits until the deadline for replication to start. This validates the current master is correct and can be connected to.
Types ¶
type BackupManifest ¶
type BackupManifest struct { // FileEntries contains all the files in the backup FileEntries []FileEntry // Position is the position at which the backup was taken Position replication.Position }
BackupManifest represents the backup. It lists all the files, and the Position that the backup was taken at.
type FakeMysqlDaemon ¶ added in v0.17.0
type FakeMysqlDaemon struct { // Mycnf will be returned by Cnf() Mycnf *Mycnf // Running is used by Start / Shutdown Running bool // MysqlPort will be returned by GetMysqlPort(). Set to -1 to // return an error. MysqlPort int32 // Replicating is updated when calling StartSlave / StopSlave // (it is not used at all when calling SlaveStatus, it is the // test owner responsability to have these two match) Replicating bool // ResetReplicationResult is returned by ResetReplication ResetReplicationResult []string // ResetReplicationError is returned by ResetReplication ResetReplicationError error // CurrentMasterPosition is returned by MasterPosition // and SlaveStatus CurrentMasterPosition replication.Position // SlaveStatusError is used by SlaveStatus SlaveStatusError error // CurrentMasterHost is returned by SlaveStatus CurrentMasterHost string // CurrentMasterport is returned by SlaveStatus CurrentMasterPort int // SecondsBehindMaster is returned by SlaveStatus SecondsBehindMaster uint // ReadOnly is the current value of the flag ReadOnly bool // SetSlavePositionCommandsPos is matched against the input // of SetSlavePositionCommands. If it doesn't match, // SetSlavePositionCommands will return an error. SetSlavePositionCommandsPos replication.Position // SetSlavePositionCommandsResult is what // SetSlavePositionCommands will return SetSlavePositionCommandsResult []string // SetMasterCommandsInput is matched against the input // of SetMasterCommands (as "%v:%v"). If it doesn't match, // SetMasterCommands will return an error. SetMasterCommandsInput string // SetMasterCommandsResult is what // SetMasterCommands will return SetMasterCommandsResult []string // DemoteMasterPosition is returned by DemoteMaster DemoteMasterPosition replication.Position // WaitMasterPosition is checked by WaitMasterPos, if the // same it returns nil, if different it returns an error WaitMasterPosition replication.Position // PromoteSlaveResult is returned by PromoteSlave PromoteSlaveResult replication.Position // SchemaFunc provides the return value for GetSchema. // If not defined, the "Schema" field will be used instead, see below. SchemaFunc func() (*tabletmanagerdatapb.SchemaDefinition, error) // Schema will be returned by GetSchema. If nil we'll // return an error. Schema *tabletmanagerdatapb.SchemaDefinition // PreflightSchemaChangeResult will be returned by PreflightSchemaChange. // If nil we'll return an error. PreflightSchemaChangeResult []*tabletmanagerdatapb.SchemaChangeResult // ApplySchemaChangeResult will be returned by ApplySchemaChange. // If nil we'll return an error. ApplySchemaChangeResult *tabletmanagerdatapb.SchemaChangeResult // DbAppConnectionFactory is the factory for making fake db app connections DbAppConnectionFactory func() (dbconnpool.PoolConnection, error) // ExpectedExecuteSuperQueryList is what we expect // ExecuteSuperQueryList to be called with. If it doesn't // match, ExecuteSuperQueryList will return an error. // Note each string is just a substring if it begins with SUB, // so we support partial queries (usefull when queries contain // data fields like timestamps) ExpectedExecuteSuperQueryList []string // ExpectedExecuteSuperQueryCurrent is the current index of the queries // we expect ExpectedExecuteSuperQueryCurrent int // FetchSuperQueryResults is used by FetchSuperQuery FetchSuperQueryMap map[string]*sqltypes.Result // BinlogPlayerEnabled is used by {Enable,Disable}BinlogPlayer BinlogPlayerEnabled bool // SemiSyncMasterEnabled represents the state of rpl_semi_sync_master_enabled. SemiSyncMasterEnabled bool // SemiSyncSlaveEnabled represents the state of rpl_semi_sync_slave_enabled. SemiSyncSlaveEnabled bool // contains filtered or unexported fields }
FakeMysqlDaemon implements MysqlDaemon and allows the user to fake everything.
func NewFakeMysqlDaemon ¶ added in v0.17.0
func NewFakeMysqlDaemon(db *fakesqldb.DB) *FakeMysqlDaemon
NewFakeMysqlDaemon returns a FakeMysqlDaemon where mysqld appears to be running
func (*FakeMysqlDaemon) ApplySchemaChange ¶ added in v0.17.0
func (fmd *FakeMysqlDaemon) ApplySchemaChange(dbName string, change *tmutils.SchemaChange) (*tabletmanagerdatapb.SchemaChangeResult, error)
ApplySchemaChange is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) CheckSuperQueryList ¶ added in v0.17.0
func (fmd *FakeMysqlDaemon) CheckSuperQueryList() error
CheckSuperQueryList returns an error if all the queries we expected haven't been seen.
func (*FakeMysqlDaemon) Close ¶ added in v0.17.0
func (fmd *FakeMysqlDaemon) Close()
Close is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) Cnf ¶
func (fmd *FakeMysqlDaemon) Cnf() *Mycnf
Cnf is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) DemoteMaster ¶
func (fmd *FakeMysqlDaemon) DemoteMaster() (replication.Position, error)
DemoteMaster is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) DisableBinlogPlayback ¶
func (fmd *FakeMysqlDaemon) DisableBinlogPlayback() error
DisableBinlogPlayback disable playback of binlog events
func (*FakeMysqlDaemon) EnableBinlogPlayback ¶
func (fmd *FakeMysqlDaemon) EnableBinlogPlayback() error
EnableBinlogPlayback is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) ExecuteSuperQueryList ¶ added in v0.17.0
func (fmd *FakeMysqlDaemon) ExecuteSuperQueryList(queryList []string) error
ExecuteSuperQueryList is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) FetchSuperQuery ¶ added in v0.17.0
func (fmd *FakeMysqlDaemon) FetchSuperQuery(query string) (*sqltypes.Result, error)
FetchSuperQuery returns the results from the map, if any
func (*FakeMysqlDaemon) GetAppConnection ¶ added in v0.17.0
func (fmd *FakeMysqlDaemon) GetAppConnection() (dbconnpool.PoolConnection, error)
GetAppConnection is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) GetDbaConnection ¶ added in v0.17.0
func (fmd *FakeMysqlDaemon) GetDbaConnection() (*dbconnpool.DBConnection, error)
GetDbaConnection is part of the MysqlDaemon interface.
func (*FakeMysqlDaemon) GetMysqlPort ¶ added in v0.17.0
func (fmd *FakeMysqlDaemon) GetMysqlPort() (int32, error)
GetMysqlPort is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) GetSchema ¶ added in v0.17.0
func (fmd *FakeMysqlDaemon) GetSchema(dbName string, tables, excludeTables []string, includeViews bool) (*tabletmanagerdatapb.SchemaDefinition, error)
GetSchema is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) IsReadOnly ¶ added in v0.17.0
func (fmd *FakeMysqlDaemon) IsReadOnly() (bool, error)
IsReadOnly is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) MasterPosition ¶
func (fmd *FakeMysqlDaemon) MasterPosition() (replication.Position, error)
MasterPosition is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) NewSlaveConnection ¶
func (fmd *FakeMysqlDaemon) NewSlaveConnection() (*SlaveConnection, error)
NewSlaveConnection is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) PreflightSchemaChange ¶ added in v0.17.0
func (fmd *FakeMysqlDaemon) PreflightSchemaChange(dbName string, changes []string) ([]*tabletmanagerdatapb.SchemaChangeResult, error)
PreflightSchemaChange is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) PromoteSlave ¶
func (fmd *FakeMysqlDaemon) PromoteSlave(hookExtraEnv map[string]string) (replication.Position, error)
PromoteSlave is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) ResetReplicationCommands ¶
func (fmd *FakeMysqlDaemon) ResetReplicationCommands() ([]string, error)
ResetReplicationCommands is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) RunMysqlUpgrade ¶ added in v0.17.0
func (fmd *FakeMysqlDaemon) RunMysqlUpgrade() error
RunMysqlUpgrade is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) SemiSyncEnabled ¶ added in v0.17.0
func (fmd *FakeMysqlDaemon) SemiSyncEnabled() (master, slave bool)
SemiSyncEnabled is part of the MysqlDaemon interface.
func (*FakeMysqlDaemon) SetMasterCommands ¶
func (fmd *FakeMysqlDaemon) SetMasterCommands(masterHost string, masterPort int) ([]string, error)
SetMasterCommands is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) SetReadOnly ¶ added in v0.17.0
func (fmd *FakeMysqlDaemon) SetReadOnly(on bool) error
SetReadOnly is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) SetSemiSyncEnabled ¶ added in v0.17.0
func (fmd *FakeMysqlDaemon) SetSemiSyncEnabled(master, slave bool) error
SetSemiSyncEnabled is part of the MysqlDaemon interface.
func (*FakeMysqlDaemon) SetSlavePositionCommands ¶
func (fmd *FakeMysqlDaemon) SetSlavePositionCommands(pos replication.Position) ([]string, error)
SetSlavePositionCommands is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) Shutdown ¶ added in v0.17.0
func (fmd *FakeMysqlDaemon) Shutdown(ctx context.Context, waitForMysqld bool) error
Shutdown is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) SlaveStatus ¶
func (fmd *FakeMysqlDaemon) SlaveStatus() (replication.Status, error)
SlaveStatus is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) Start ¶ added in v0.17.0
func (fmd *FakeMysqlDaemon) Start(ctx context.Context) error
Start is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) TabletDir ¶
func (fmd *FakeMysqlDaemon) TabletDir() string
TabletDir is part of the MysqlDaemon interface.
func (*FakeMysqlDaemon) Wait ¶ added in v0.17.0
func (fmd *FakeMysqlDaemon) Wait(ctx context.Context) error
Wait is part of the MysqlDaemon interface.
func (*FakeMysqlDaemon) WaitForReparentJournal ¶ added in v0.17.0
func (fmd *FakeMysqlDaemon) WaitForReparentJournal(ctx context.Context, timeCreatedNS int64) error
WaitForReparentJournal is part of the MysqlDaemon interface
func (*FakeMysqlDaemon) WaitMasterPos ¶
func (fmd *FakeMysqlDaemon) WaitMasterPos(pos replication.Position, waitTimeout time.Duration) error
WaitMasterPos is part of the MysqlDaemon interface
type FileEntry ¶
type FileEntry struct { // Base is one of: // - backupInnodbDataHomeDir for files that go into Mycnf.InnodbDataHomeDir // - backupInnodbLogGroupHomeDir for files that go into Mycnf.InnodbLogGroupHomeDir // - backupData for files that go into Mycnf.DataDir Base string // Name is the file name, relative to Base Name string // Hash is the hash of the gzip compressed data stored in the // BackupStorage. Hash string }
FileEntry is one file to backup
type Mycnf ¶
type Mycnf struct { // ServerID is the unique id for this server. // Used to create a bunch of named directories. ServerID uint32 // MysqlPort is the port for the MySQL server running on this machine. // It is mainly used to communicate with topology server. MysqlPort int32 // DataDir is where the table files are // (used by vt software for Clone) DataDir string // InnodbDataHomeDir is the data directory for innodb. // (used by vt software for Clone) InnodbDataHomeDir string // InnodbLogGroupHomeDir is the logs directory for innodb. // (used by vt software for Clone) InnodbLogGroupHomeDir string // SocketFile is the path to the local mysql.sock file. // (used by vt software to check server is running) SocketFile string // ErrorLogPath is the path to store error logs at. // (unused by vt software for now) ErrorLogPath string // SlowLogPath is the slow query log path // (unused by vt software for now) SlowLogPath string // RelayLogPath is the path of the relay logs // (unused by vt software for now) RelayLogPath string // RelayLogIndexPath is the file name for the relay log index // (unused by vt software for now) RelayLogIndexPath string // RelayLogInfoPath is the file name for the relay log info file // (unused by vt software for now) RelayLogInfoPath string // BinLogPath is the base path for binlogs // (used by vt software for binlog streaming) BinLogPath string // MasterInfoFile is the master.info file location. // (unused by vt software for now) MasterInfoFile string // PidFile is the mysql.pid file location // (used by vt software to check server is running) PidFile string // TmpDir is where to create temporary tables // (unused by vt software for now) TmpDir string // SlaveLoadTmpDir is where to create tmp files for replication // (unused by vt software for now) SlaveLoadTmpDir string // contains filtered or unexported fields }
Mycnf is a memory structure that contains a bunch of interesting parameters to start mysqld. It can be used to generate standard my.cnf files from a server id and mysql port. It can also be populated from an existing my.cnf, or by command line parameters.
func NewMycnf ¶
NewMycnf fills the Mycnf structure with vt root paths and derived values. This is used to fill out the cnfTemplate values and generate my.cnf. uid is a unique id for a particular tablet - it must be unique within the tabletservers deployed within a keyspace, lest there be collisions on disk. mysqldPort needs to be unique per instance per machine.
func NewMycnfFromFlags ¶
NewMycnfFromFlags creates a Mycnf object from the command line flags.
Multiple modes are supported:
- at least mycnf_server_id is set on the command line --> then we read all parameters from the command line, and not from any my.cnf file.
- mycnf_server_id is not passed in, but mycnf-file is passed in --> then we read that mycnf file
- mycnf_server_id and mycnf-file are not passed in: --> then we use the default location of the my.cnf file for the provided uid and read that my.cnf file.
RegisterCommandLineFlags should have been called before calling this, otherwise we'll panic.
type MysqlDaemon ¶
type MysqlDaemon interface { // Cnf returns the underlying mycnf Cnf() *Mycnf // TabletDir returns the tablet directory. TabletDir() string // methods related to mysql running or not Start(ctx context.Context) error Shutdown(ctx context.Context, waitForMysqld bool) error RunMysqlUpgrade() error Wait(ctx context.Context) error // GetMysqlPort returns the current port mysql is listening on. GetMysqlPort() (int32, error) // replication related methods SlaveStatus() (replication.Status, error) SetSemiSyncEnabled(master, slave bool) error SemiSyncEnabled() (master, slave bool) // reparenting related methods ResetReplicationCommands() ([]string, error) MasterPosition() (replication.Position, error) IsReadOnly() (bool, error) SetReadOnly(on bool) error SetSlavePositionCommands(pos replication.Position) ([]string, error) SetMasterCommands(masterHost string, masterPort int) ([]string, error) WaitForReparentJournal(ctx context.Context, timeCreatedNS int64) error // DemoteMaster waits for all current transactions to finish, // and returns the current replication position. It will not // change the read_only state of the server. DemoteMaster() (replication.Position, error) WaitMasterPos(replication.Position, time.Duration) error // PromoteSlave makes the slave the new master. It will not change // the read_only state of the server. PromoteSlave(map[string]string) (replication.Position, error) // Schema related methods GetSchema(dbName string, tables, excludeTables []string, includeViews bool) (*tabletmanagerdatapb.SchemaDefinition, error) PreflightSchemaChange(dbName string, changes []string) ([]*tabletmanagerdatapb.SchemaChangeResult, error) ApplySchemaChange(dbName string, change *tmutils.SchemaChange) (*tabletmanagerdatapb.SchemaChangeResult, error) // GetAppConnection returns a app connection to be able to talk to the database. GetAppConnection() (dbconnpool.PoolConnection, error) // GetDbaConnection returns a dba connection. GetDbaConnection() (*dbconnpool.DBConnection, error) // ExecuteSuperQueryList executes a list of queries, no result ExecuteSuperQueryList(queryList []string) error // FetchSuperQuery executes one query, returns the result FetchSuperQuery(query string) (*sqltypes.Result, error) // NewSlaveConnection returns a SlaveConnection to the database. NewSlaveConnection() (*SlaveConnection, error) // EnableBinlogPlayback enables playback of binlog events EnableBinlogPlayback() error // DisableBinlogPlayback disable playback of binlog events DisableBinlogPlayback() error // Close will close this instance of Mysqld. It will wait for all dba // queries to be finished. Close() }
MysqlDaemon is the interface we use for abstracting Mysqld.
type MysqlFlavor ¶
type MysqlFlavor interface { // VersionMatch returns true if the version string (from // SELECT VERSION()) represents a server that this flavor // knows how to talk to. VersionMatch(version string) bool // MasterPosition returns the ReplicationPosition of a master. MasterPosition(mysqld *Mysqld) (replication.Position, error) // SlaveStatus returns the ReplicationStatus of a slave. SlaveStatus(mysqld *Mysqld) (replication.Status, error) // ResetReplicationCommands returns the commands to completely reset // replication on the host. ResetReplicationCommands() []string // PromoteSlaveCommands returns the commands to run to change // a slave into a master. PromoteSlaveCommands() []string // SetSlavePositionCommands returns the commands to set the // replication position at which the slave will resume // when it is later reparented with SetMasterCommands. SetSlavePositionCommands(pos replication.Position) ([]string, error) // SetMasterCommands returns the commands to use the provided master // as the new master (without changing any GTID position). // It is guaranteed to be called with replication stopped. // It should not start or stop replication. SetMasterCommands(params *sqldb.ConnParams, masterHost string, masterPort int, masterConnectRetry int) ([]string, error) // ParseGTID parses a GTID in the canonical format of this // MySQL flavor into a replication.GTID interface value. ParseGTID(string) (replication.GTID, error) // ParseReplicationPosition parses a replication position in // the canonical format of this MySQL flavor into a // replication.Position struct. ParseReplicationPosition(string) (replication.Position, error) // SendBinlogDumpCommand sends the flavor-specific version of // the COM_BINLOG_DUMP command to start dumping raw binlog // events over a slave connection, starting at a given GTID. SendBinlogDumpCommand(conn *SlaveConnection, startPos replication.Position) error // MakeBinlogEvent takes a raw packet from the MySQL binlog // stream connection and returns a BinlogEvent through which // the packet can be examined. MakeBinlogEvent(buf []byte) replication.BinlogEvent // WaitMasterPos waits until slave replication reaches at // least targetPos. WaitMasterPos(mysqld *Mysqld, targetPos replication.Position, waitTimeout time.Duration) error // EnableBinlogPlayback prepares the server to play back // events from a binlog stream. Whatever it does for a given // flavor, it must be idempotent. EnableBinlogPlayback(mysqld *Mysqld) error // DisableBinlogPlayback returns the server to the normal // state after playback is done. Whatever it does for a given // flavor, it must be idempotent. DisableBinlogPlayback(mysqld *Mysqld) error }
MysqlFlavor is the abstract interface for a flavor.
type Mysqld ¶
type Mysqld struct { SnapshotDir string // contains filtered or unexported fields }
Mysqld is the object that represents a mysqld daemon running on this server.
func NewMysqld ¶
func NewMysqld(dbaName, appName string, config *Mycnf, dba, app, repl *sqldb.ConnParams) *Mysqld
NewMysqld creates a Mysqld object based on the provided configuration and connection parameters. dbaName and appName are the base for stats exports, use 'Dba' and 'App', except in tests
func (*Mysqld) ApplySchemaChange ¶
func (mysqld *Mysqld) ApplySchemaChange(dbName string, change *tmutils.SchemaChange) (*tabletmanagerdatapb.SchemaChangeResult, error)
ApplySchemaChange will apply the schema change to the given database.
func (*Mysqld) Close ¶
func (mysqld *Mysqld) Close()
Close will close this instance of Mysqld. It will wait for all dba queries to be finished.
func (*Mysqld) DemoteMaster ¶
func (mysqld *Mysqld) DemoteMaster() (rp replication.Position, err error)
DemoteMaster will gracefully demote a master mysql instance to read only. If the master is still alive, then we need to demote it gracefully make it read-only, flush the writes and get the position
func (*Mysqld) DisableBinlogPlayback ¶
DisableBinlogPlayback returns the server to the normal state after streaming. Whatever it does for a given flavor, it must be idempotent.
func (*Mysqld) EnableBinlogPlayback ¶
EnableBinlogPlayback prepares the server to play back events from a binlog stream. Whatever it does for a given flavor, it must be idempotent.
func (*Mysqld) ExecuteSuperQuery ¶
ExecuteSuperQuery allows the user to execute a query as a super user.
func (*Mysqld) ExecuteSuperQueryList ¶
ExecuteSuperQueryList alows the user to execute queries as a super user.
func (*Mysqld) FetchSuperQuery ¶
FetchSuperQuery returns the results of executing a query as a super user.
func (*Mysqld) GetAppConnection ¶
func (mysqld *Mysqld) GetAppConnection() (dbconnpool.PoolConnection, error)
GetAppConnection returns a connection from the app pool. Recycle needs to be called on the result.
func (*Mysqld) GetColumns ¶
GetColumns returns the columns of table.
func (*Mysqld) GetDbaConnection ¶
func (mysqld *Mysqld) GetDbaConnection() (*dbconnpool.DBConnection, error)
GetDbaConnection creates a new DBConnection.
func (*Mysqld) GetMysqlPort ¶
GetMysqlPort returns mysql port
func (*Mysqld) GetPrimaryKeyColumns ¶
GetPrimaryKeyColumns returns the primary key columns of table.
func (*Mysqld) GetSchema ¶
func (mysqld *Mysqld) GetSchema(dbName string, tables, excludeTables []string, includeViews bool) (*tabletmanagerdatapb.SchemaDefinition, error)
GetSchema returns the schema for database for tables listed in tables. If tables is empty, return the schema for all tables.
func (*Mysqld) Init ¶
Init will create the default directory structure for the mysqld process, generate / configure a my.cnf file, install a skeleton database, and apply the provided initial SQL file.
func (*Mysqld) IsReadOnly ¶
IsReadOnly return true if the instance is read only
func (*Mysqld) MasterPosition ¶
func (mysqld *Mysqld) MasterPosition() (rp replication.Position, err error)
MasterPosition returns master replication position
func (*Mysqld) NewSlaveConnection ¶
func (mysqld *Mysqld) NewSlaveConnection() (*SlaveConnection, error)
NewSlaveConnection creates a new slave connection to the mysqld instance. It uses a pools.IDPool to ensure that the server IDs used to connect are unique within this process. This is done with the assumptions that:
- No other processes are making fake slave connections to our mysqld.
- No real slave servers will have IDs in the range 1-N where N is the peak number of concurrent fake slave connections we will ever make.
func (*Mysqld) OnTerm ¶
func (mysqld *Mysqld) OnTerm(f func())
OnTerm registers a function to be called if mysqld terminates for any reason other than a call to Mysqld.Shutdown(). This only works if mysqld was actually started by calling Start() on this Mysqld instance.
func (*Mysqld) PreflightSchemaChange ¶
func (mysqld *Mysqld) PreflightSchemaChange(dbName string, changes []string) ([]*tabletmanagerdatapb.SchemaChangeResult, error)
PreflightSchemaChange checks the schema changes in "changes" by applying them to an intermediate database that has the same schema as the target database.
func (*Mysqld) PromoteSlave ¶
PromoteSlave will promote a slave to be the new master.
func (*Mysqld) ResetReplicationCommands ¶
ResetReplicationCommands returns the commands to run to reset all replication for this host.
func (*Mysqld) RunMysqlUpgrade ¶
RunMysqlUpgrade will run the mysql_upgrade program on the current install. Will not be called when mysqld is running.
func (*Mysqld) SemiSyncEnabled ¶
SemiSyncEnabled returns whether semi-sync is enabled for master or slave. If the semi-sync plugin is not loaded, we assume semi-sync is disabled.
func (*Mysqld) SetMasterCommands ¶
SetMasterCommands returns the commands to run to make the provided host / port the master.
func (*Mysqld) SetReadOnly ¶
SetReadOnly set/unset the read_only flag
func (*Mysqld) SetSemiSyncEnabled ¶
SetSemiSyncEnabled enables or disables semi-sync replication for master and/or slave mode.
func (*Mysqld) SetSlavePositionCommands ¶
func (mysqld *Mysqld) SetSlavePositionCommands(pos replication.Position) ([]string, error)
SetSlavePositionCommands returns the commands to set the replication position at which the slave will resume when it is later reparented with SetMasterCommands.
func (*Mysqld) Shutdown ¶
Shutdown will stop the mysqld daemon that is running in the background.
waitForMysqld: should the function block until mysqld has stopped? This can actually take a *long* time if the buffer cache needs to be fully flushed - on the order of 20-30 minutes.
If a mysqlctld address is provided in a flag, Shutdown will run remotely.
func (*Mysqld) SlaveStatus ¶
func (mysqld *Mysqld) SlaveStatus() (replication.Status, error)
SlaveStatus returns the slave replication statuses
func (*Mysqld) Start ¶
Start will start the mysql daemon, either by running the 'mysqld_start' hook, or by running mysqld_safe in the background. If a mysqlctld address is provided in a flag, Start will run remotely.
func (*Mysqld) TabletDir ¶
TabletDir returns the main tablet directory. It's a method so it can be accessed through the MysqlDaemon interface.
func (*Mysqld) WaitForReparentJournal ¶
WaitForReparentJournal will wait until the context is done for the row in the reparent_journal table.
func (*Mysqld) WaitMasterPos ¶
func (mysqld *Mysqld) WaitMasterPos(targetPos replication.Position, waitTimeout time.Duration) error
WaitMasterPos lets slaves wait to given replication position
type SlaveConnection ¶
SlaveConnection represents a connection to mysqld that pretends to be a slave connecting for replication. Each such connection must identify itself to mysqld with a server ID that is unique both among other SlaveConnections and among actual slaves in the topology.
func (*SlaveConnection) Close ¶
func (sc *SlaveConnection) Close()
Close closes the slave connection, which also signals an ongoing dump started with StartBinlogDump() to stop and close its BinlogEvent channel. The ID for the slave connection is recycled back into the pool.
func (*SlaveConnection) StartBinlogDump ¶
func (sc *SlaveConnection) StartBinlogDump(startPos replication.Position) (<-chan replication.BinlogEvent, error)
StartBinlogDump requests a replication binlog dump from the master mysqld and then immediately returns a channel on which received binlog events will be sent. The stream will continue, waiting for new events if necessary, until the connection is closed, either by the master or by calling SlaveConnection.Close(). At that point, the channel will also be closed.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package backupstorage contains the interface and file system implementation of the backup system.
|
Package backupstorage contains the interface and file system implementation of the backup system. |
Package cephbackupstorage implements the BackupStorage interface for Ceph Cloud Storage.
|
Package cephbackupstorage implements the BackupStorage interface for Ceph Cloud Storage. |
Package filebackupstorage implements the BackupStorage interface for a local filesystem (which can be an NFS mount).
|
Package filebackupstorage implements the BackupStorage interface for a local filesystem (which can be an NFS mount). |
Package gcsbackupstorage implements the BackupStorage interface for Google Cloud Storage.
|
Package gcsbackupstorage implements the BackupStorage interface for Google Cloud Storage. |
Package grpcmysqlctlclient contains the gRPC1 version of the mysqlctl client protocol.
|
Package grpcmysqlctlclient contains the gRPC1 version of the mysqlctl client protocol. |
Package grpcmysqlctlserver contains the gRPC implementation of the server side of the remote execution of mysqlctl commands.
|
Package grpcmysqlctlserver contains the gRPC implementation of the server side of the remote execution of mysqlctl commands. |
Package mysqlctlclient contains the generic client side of the remote mysqlctl protocol.
|
Package mysqlctlclient contains the generic client side of the remote mysqlctl protocol. |
Package replication contains data structures to deal with MySQL replication.
|
Package replication contains data structures to deal with MySQL replication. |
Package tmutils contains helper methods to deal with the tabletmanagerdata proto3 structures.
|
Package tmutils contains helper methods to deal with the tabletmanagerdata proto3 structures. |