mysqlctl

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: Apache-2.0 Imports: 56 Imported by: 13

Documentation

Index

Constants

View Source
const (

	// RestoreState is the name of the sentinel file used to detect whether a previous restore
	// terminated abnormally
	RestoreState = "restore_in_progress"
	// BackupTimestampFormat is the format in which we save BackupTime and FinishedTime
	BackupTimestampFormat = "2006-01-02.150405"
)
View Source
const (
	FlavorMySQL   mysqlFlavor = "mysql"
	FlavorPercona mysqlFlavor = "percona"
	FlavorMariaDB mysqlFlavor = "mariadb"
)

Flavor constants define the type of mysql flavor being used

Variables

View Source
var (
	// ErrNoBackup is returned when there is no backup.
	ErrNoBackup = errors.New("no available backup")

	// ErrNoCompleteBackup is returned when there is at least one backup,
	// but none of them are complete.
	ErrNoCompleteBackup = errors.New("backup(s) found but none are complete")
)
View Source
var (
	// DisableActiveReparents is a flag to disable active
	// reparents for safety reasons. It is used in three places:
	// 1. in this file to skip registering the commands.
	// 2. in vtctld so it can be exported to the UI (different
	// package, that's why it's exported). That way we can disable
	// menu items there, using features.
	// 3. prevents the vtworker from updating replication topology
	// after restarting replication after a split clone/diff.
	DisableActiveReparents = flag.Bool("disable_active_reparents", false, "if set, do not allow active reparents. Use this to protect a cluster using external reparents.")

	// DbaIdleTimeout is how often we will refresh the DBA connpool connections
	DbaIdleTimeout = flag.Duration("dba_idle_timeout", time.Minute, "Idle timeout for dba connections")

	// PoolDynamicHostnameResolution is whether we should retry DNS resolution of hostname targets
	// and reconnect if necessary
	PoolDynamicHostnameResolution = flag.Duration("pool_hostname_resolve_interval", 0, "if set force an update to all hostnames and reconnect if changed, defaults to 0 (disabled)")
)
View Source
var BackupRestoreEngineMap = make(map[string]BackupRestoreEngine)

BackupRestoreEngineMap contains the registered implementations for BackupEngine and RestoreEngine.

View Source
var (
	// BuiltinBackupMysqldTimeout is how long ExecuteBackup should wait for response from mysqld.Shutdown.
	// It can later be extended for other calls to mysqld during backup functions.
	// Exported for testing.
	BuiltinBackupMysqldTimeout = flag.Duration("builtinbackup_mysqld_timeout", 10*time.Minute, "how long to wait for mysqld to shutdown at the start of the backup")
)

Functions

func AlterReparentJournal added in v0.13.0

func AlterReparentJournal() []string

AlterReparentJournal returns the commands to execute to change column master_alias -> primary_alias or the other way In 13.0.0 we introduce renaming of primary_alias -> master_alias. This is to support in-place downgrade from a later version. In 14.0.0 we will replace this with renaming of master_alias -> primary_alias. This is to support in-place upgrades from 13.0.x to 14.0.x

func Backup

func Backup(ctx context.Context, params BackupParams) 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

func ConcurrentMap(concurrency, n int, fun MapFunc) error

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 CreateMysqldAndMycnf

func CreateMysqldAndMycnf(tabletUID uint32, mysqlSocket string, mysqlPort int32) (*Mysqld, *Mycnf, error)

CreateMysqldAndMycnf returns a Mysqld and a Mycnf object to use for working with a MySQL installation that hasn't been set up yet.

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.

If the table was created by Vitess version 2.0, the following command may need to be run: ALTER TABLE _vt.reparent_journal MODIFY COLUMN replication_position VARBINARY(64000);

func DefaultTabletDirAtRoot added in v0.10.0

func DefaultTabletDirAtRoot(dataRoot string, uid uint32) string

DefaultTabletDirAtRoot returns the default directory for a tablet given a UID and a VtDataRoot variable

func FindBackupToRestore

func FindBackupToRestore(ctx context.Context, params RestoreParams, bhs []backupstorage.BackupHandle) (backupstorage.BackupHandle, error)

FindBackupToRestore returns a selected candidate backup to be restored. It returns the most recent backup that is complete, meaning it has a valid MANIFEST file.

func FindReplicas

func FindReplicas(mysqld MysqlDaemon) ([]string, error)

FindReplicas gets IP addresses for all currently connected replicas.

func GetBackupDir

func GetBackupDir(keyspace, shard string) string

GetBackupDir returns the directory where backups for the given keyspace/shard are (or will be) stored

func GetPermissions

func GetPermissions(mysqld MysqlDaemon) (*tabletmanagerdatapb.Permissions, error)

GetPermissions lists the permissions on the mysqld. The rows are sorted in primary key order to help with comparing permissions between tablets.

func GetVersionFromEnv added in v0.8.0

func GetVersionFromEnv() (flavor mysqlFlavor, ver serverVersion, err error)

GetVersionFromEnv returns the flavor and an assumed version based on the legacy MYSQL_FLAVOR environment variable.

The assumed version may not be accurate since the legacy variable only specifies broad families of compatible versions. However, the differences between those versions should only matter if Vitess is managing the lifecycle of mysqld, in which case we should have a local copy of the mysqld binary from which we can fetch the accurate version instead of falling back to this function (see GetVersionString).

func GetVersionString added in v0.8.0

func GetVersionString() (string, error)

GetVersionString runs mysqld --version and returns its output as a string

func MycnfFile

func MycnfFile(uid uint32) string

MycnfFile returns the default location of the my.cnf file.

func OpenMysqldAndMycnf

func OpenMysqldAndMycnf(tabletUID uint32) (*Mysqld, *Mycnf, error)

OpenMysqldAndMycnf returns a Mysqld and a Mycnf object to use for working with a MySQL installation that already exists. The Mycnf will be built based on the my.cnf file of the MySQL instance.

func ParseBackupName added in v0.11.0

func ParseBackupName(dir string, name string) (backupTime *time.Time, alias *topodatapb.TabletAlias, err error)

ParseBackupName parses the backup name for a given dir/name, according to the format generated by mysqlctl.Backup. An error is returned only if the backup name does not have the expected number of parts; errors parsing the timestamp and tablet alias are logged, and a nil value is returned for those fields in case of error.

func ParseVersionString added in v0.8.0

func ParseVersionString(version string) (flavor mysqlFlavor, ver serverVersion, err error)

ParseVersionString parses the output of mysqld --version into a flavor and version

func PopulateReparentJournal

func PopulateReparentJournal(timeCreatedNS int64, actionName, primaryAlias string, pos mysql.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(ctx context.Context, mysqld MysqlDaemon, dbName string, tables []string) ([]string, error)

ResolveTables returns a list of actual tables+views matching a list of regexps

func RestoreWasInterrupted

func RestoreWasInterrupted(cnf *Mycnf) bool

RestoreWasInterrupted tells us whether a previous restore was interrupted and we are now retrying it

func ShouldRestore added in v0.8.0

func ShouldRestore(ctx context.Context, params RestoreParams) (bool, error)

ShouldRestore checks whether a database with tables already exists and returns whether a restore action should be performed

func TabletDir

func TabletDir(uid uint32) string

TabletDir returns the default directory for a tablet

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 WaitForReplicationStart

func WaitForReplicationStart(mysqld MysqlDaemon, replicaStartDeadline int) error

WaitForReplicationStart waits until the deadline for replication to start. This validates the current primary is correct and can be connected to.

Types

type BackupEngine

type BackupEngine interface {
	ExecuteBackup(ctx context.Context, params BackupParams, bh backupstorage.BackupHandle) (bool, error)
	ShouldDrainForBackup() bool
}

BackupEngine is the interface to take a backup with a given engine.

func GetBackupEngine

func GetBackupEngine() (BackupEngine, error)

GetBackupEngine returns the BackupEngine implementation that should be used to create new backups.

To restore a backup, you should instead get the appropriate RestoreEngine for a particular backup by calling GetRestoreEngine().

This must only be called after flags have been parsed.

type BackupManifest

type BackupManifest struct {
	// BackupMethod is the name of the backup engine that created this backup.
	// If this is empty, the backup engine is assumed to be "builtin" since that
	// was the only engine that ever left this field empty. All new backup
	// engines are required to set this field to the backup engine name.
	BackupMethod string

	// Position is the replication position at which the backup was taken.
	Position mysql.Position

	// BackupTime is when the backup was taken in UTC time (RFC 3339 format)
	BackupTime string

	// FinishedTime is the time (in RFC 3339 format, UTC) at which the backup finished, if known.
	// Some backups may not set this field if they were created before the field was added.
	FinishedTime string
}

BackupManifest defines the common fields in the MANIFEST file. All backup engines must include at least these fields. They are free to add their own custom fields by embedding this struct anonymously into their own custom struct, as long as their custom fields don't have conflicting names.

func GetBackupManifest

func GetBackupManifest(ctx context.Context, backup backupstorage.BackupHandle) (*BackupManifest, error)

GetBackupManifest returns the common fields of the MANIFEST file for a given backup.

func Restore

func Restore(ctx context.Context, params RestoreParams) (*BackupManifest, 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.

type BackupParams

type BackupParams struct {
	Cnf    *Mycnf
	Mysqld MysqlDaemon
	Logger logutil.Logger
	// Concurrency is the value of -concurrency flag given to Backup command
	// It determines how many files are processed in parallel
	Concurrency int
	// Extra env variables for pre-backup and post-backup transform hooks
	HookExtraEnv map[string]string
	// TopoServer, Keyspace and Shard are used to discover primary tablet
	TopoServer *topo.Server
	// Keyspace and Shard are used to infer the directory where backups should be stored
	Keyspace string
	Shard    string
	// TabletAlias is used along with backupTime to construct the backup name
	TabletAlias string
	// BackupTime is the time at which the backup is being started
	BackupTime time.Time
}

BackupParams is the struct that holds all params passed to ExecuteBackup

type BackupRestoreEngine

type BackupRestoreEngine interface {
	BackupEngine
	RestoreEngine
}

BackupRestoreEngine is a combination of BackupEngine and RestoreEngine.

type BuiltinBackupEngine

type BuiltinBackupEngine struct {
}

BuiltinBackupEngine encapsulates the logic of the builtin engine it implements the BackupEngine interface and contains all the logic required to implement a backup/restore by copying files from and to the correct location / storage bucket

func (*BuiltinBackupEngine) ExecuteBackup

func (be *BuiltinBackupEngine) ExecuteBackup(ctx context.Context, params BackupParams, bh backupstorage.BackupHandle) (bool, error)

ExecuteBackup returns a boolean that indicates if the backup is usable, and an overall error.

func (*BuiltinBackupEngine) ExecuteRestore

ExecuteRestore restores from a backup. If the restore is successful we return the position from which replication should start otherwise an error is returned

func (*BuiltinBackupEngine) ShouldDrainForBackup

func (be *BuiltinBackupEngine) ShouldDrainForBackup() bool

ShouldDrainForBackup satisfies the BackupEngine interface backup requires query service to be stopped, hence true

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 final data (transformed and
	// compressed if specified) stored in the BackupStorage.
	Hash string
}

FileEntry is one file to backup

type MapFunc

type MapFunc func(index int) error

type MetadataManager added in v0.11.0

type MetadataManager struct{}

MetadataManager manages the creation and filling of the _vt.local_metadata and _vt.shard_metadata tables.

func (*MetadataManager) PopulateMetadataTables added in v0.11.0

func (m *MetadataManager) PopulateMetadataTables(mysqld MysqlDaemon, localMetadata map[string]string, dbName string) error

PopulateMetadataTables creates and fills the _vt.local_metadata table and creates the _vt.shard_metadata table.

_vt.local_metadata table is a per-tablet table that is never replicated. This allows queries against local_metadata to return different values on different tablets, which is used for communicating between Vitess and MySQL-level tools like Orchestrator (https://github.com/openark/orchestrator).

_vt.shard_metadata is a replicated table with per-shard information, but it's created here to make it easier to create it on databases that were running old version of Vitess, or databases that are getting converted to run under Vitess.

This function is semantically equivalent to calling createMetadataTables followed immediately by upsertLocalMetadata.

func (*MetadataManager) UpsertLocalMetadata added in v0.11.0

func (m *MetadataManager) UpsertLocalMetadata(mysqld MysqlDaemon, localMetadata map[string]string, dbName string) error

UpsertLocalMetadata adds the given metadata map to the _vt.local_metadata table, updating any rows that exist for a given `_vt.local_metadata.name` with the map value. The session that performs these upserts sets sql_log_bin=0, as the _vt.local_metadata table is meant to never be replicated.

Callers are responsible for ensuring the _vt.local_metadata table exists before calling this function, usually by calling CreateMetadataTables at least once prior.

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

	// SecureFilePriv is the path for loading secure files
	// (used by vt software for bulk loading into tablet instances)
	SecureFilePriv string

	// SocketFile is the path to the local mysql.sock file.
	// (used by vt software to check server is running)
	SocketFile string

	// GeneralLogPath is the path to store general logs at,
	// if general-log is enabled.
	// (unused by vt software for now)
	GeneralLogPath 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 when vitess manages mysql config because we set
	// master_info_repository = TABLE and
	// relay_log_info_repository = TABLE
	// However it is possible to use custom cnf files with vitess
	// and to generate them using command-line flags, so we allow a way to set this property
	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
	// 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

func NewMycnf(tabletUID uint32, mysqlPort int32) *Mycnf

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

func NewMycnfFromFlags(uid uint32) (mycnf *Mycnf, err error)

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.

func ReadMycnf

func ReadMycnf(mycnf *Mycnf) (*Mycnf, error)

ReadMycnf will read an existing my.cnf from disk, and update the passed in Mycnf object with values from the my.cnf on disk.

func (*Mycnf) RandomizeMysqlServerID

func (cnf *Mycnf) RandomizeMysqlServerID() error

RandomizeMysqlServerID generates a random MySQL server_id.

The value assigned to ServerID will be in the range [100, 2^31): - It avoids 0 because that's reserved for mysqlbinlog dumps. - It also avoids 1-99 because low numbers are used for fake connections. See NewBinlogConnection() in binlog/binlog_connection.go for more on that. - It avoids the 2^31 - 2^32-1 range, as there seems to be some confusion there. The main MySQL documentation at: http://dev.mysql.com/doc/refman/5.7/en/replication-options.html implies serverID is a full 32 bits number. The semi-sync log line at startup '[Note] Start semi-sync binlog_dump to slave ...' interprets the server_id as signed 32-bit (shows negative numbers for that range). Such an ID may also be responsible for a mysqld crash in semi-sync code, although we haven't been able to verify that yet. The issue for that is: https://github.com/vitessio/vitess/issues/2280

func (*Mycnf) TabletDir

func (cnf *Mycnf) TabletDir() string

TabletDir returns the tablet directory.

type MysqlDaemon

type MysqlDaemon interface {
	// methods related to mysql running or not
	Start(ctx context.Context, cnf *Mycnf, mysqldArgs ...string) error
	Shutdown(ctx context.Context, cnf *Mycnf, waitForMysqld bool) error
	RunMysqlUpgrade() error
	ReinitConfig(ctx context.Context, cnf *Mycnf) error
	Wait(ctx context.Context, cnf *Mycnf) error

	// GetMysqlPort returns the current port mysql is listening on.
	GetMysqlPort() (int32, error)

	// replication related methods
	StartReplication(hookExtraEnv map[string]string) error
	RestartReplication(hookExtraEnv map[string]string) error
	StartReplicationUntilAfter(ctx context.Context, pos mysql.Position) error
	StopReplication(hookExtraEnv map[string]string) error
	StopIOThread(ctx context.Context) error
	ReplicationStatus() (mysql.ReplicationStatus, error)
	PrimaryStatus(ctx context.Context) (mysql.PrimaryStatus, error)
	SetSemiSyncEnabled(source, replica bool) error
	SemiSyncEnabled() (source, replica bool)
	SemiSyncReplicationStatus() (bool, error)

	// reparenting related methods
	ResetReplication(ctx context.Context) error
	PrimaryPosition() (mysql.Position, error)
	IsReadOnly() (bool, error)
	SetReadOnly(on bool) error
	SetSuperReadOnly(on bool) error
	SetReplicationPosition(ctx context.Context, pos mysql.Position) error
	SetReplicationSource(ctx context.Context, host string, port int, stopReplicationBefore bool, startReplicationAfter bool) error
	WaitForReparentJournal(ctx context.Context, timeCreatedNS int64) error

	WaitSourcePos(context.Context, mysql.Position) error

	// Promote makes the current server the primary. It will not change
	// the read_only state of the server.
	Promote(map[string]string) (mysql.Position, error)

	// Schema related methods
	GetSchema(ctx context.Context, dbName string, tables, excludeTables []string, includeViews bool) (*tabletmanagerdatapb.SchemaDefinition, error)
	GetColumns(ctx context.Context, dbName, table string) ([]*querypb.Field, []string, error)
	GetPrimaryKeyColumns(ctx context.Context, dbName, table string) ([]string, error)
	PreflightSchemaChange(ctx context.Context, dbName string, changes []string) ([]*tabletmanagerdatapb.SchemaChangeResult, error)
	ApplySchemaChange(ctx context.Context, dbName string, change *tmutils.SchemaChange) (*tabletmanagerdatapb.SchemaChangeResult, error)

	// GetAppConnection returns a app connection to be able to talk to the database.
	GetAppConnection(ctx context.Context) (*dbconnpool.PooledDBConnection, error)
	// GetDbaConnection returns a dba connection.
	GetDbaConnection(ctx context.Context) (*dbconnpool.DBConnection, error)
	// GetAllPrivsConnection returns an allprivs connection (for user with all privileges except SUPER).
	GetAllPrivsConnection(ctx context.Context) (*dbconnpool.DBConnection, error)

	// GetVersionString returns the database version as a string
	GetVersionString() string

	// ExecuteSuperQueryList executes a list of queries, no result
	ExecuteSuperQueryList(ctx context.Context, queryList []string) error

	// FetchSuperQuery executes one query, returns the result
	FetchSuperQuery(ctx context.Context, query string) (*sqltypes.Result, 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 Mysqld

type Mysqld struct {
	// contains filtered or unexported fields
}

Mysqld is the object that represents a mysqld daemon running on this server.

func NewMysqld

func NewMysqld(dbcfgs *dbconfigs.DBConfigs) *Mysqld

NewMysqld creates a Mysqld object based on the provided configuration and connection parameters.

func (*Mysqld) ApplySchemaChange

func (mysqld *Mysqld) ApplySchemaChange(ctx context.Context, 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) DisableBinlogPlayback

func (mysqld *Mysqld) DisableBinlogPlayback() error

DisableBinlogPlayback returns the server to the normal state after streaming. Whatever it does for a given flavor, it must be idempotent.

func (*Mysqld) EnableBinlogPlayback

func (mysqld *Mysqld) EnableBinlogPlayback() error

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

func (mysqld *Mysqld) ExecuteSuperQuery(ctx context.Context, query string) error

ExecuteSuperQuery allows the user to execute a query as a super user.

func (*Mysqld) ExecuteSuperQueryList

func (mysqld *Mysqld) ExecuteSuperQueryList(ctx context.Context, queryList []string) error

ExecuteSuperQueryList alows the user to execute queries as a super user.

func (*Mysqld) FetchSuperQuery

func (mysqld *Mysqld) FetchSuperQuery(ctx context.Context, query string) (*sqltypes.Result, error)

FetchSuperQuery returns the results of executing a query as a super user.

func (*Mysqld) GetAllPrivsConnection

func (mysqld *Mysqld) GetAllPrivsConnection(ctx context.Context) (*dbconnpool.DBConnection, error)

GetAllPrivsConnection creates a new DBConnection.

func (*Mysqld) GetAppConnection

func (mysqld *Mysqld) GetAppConnection(ctx context.Context) (*dbconnpool.PooledDBConnection, error)

GetAppConnection returns a connection from the app pool. Recycle needs to be called on the result.

func (*Mysqld) GetColumns

func (mysqld *Mysqld) GetColumns(ctx context.Context, dbName, table string) ([]*querypb.Field, []string, error)

GetColumns returns the columns of table.

func (*Mysqld) GetDbaConnection

func (mysqld *Mysqld) GetDbaConnection(ctx context.Context) (*dbconnpool.DBConnection, error)

GetDbaConnection creates a new DBConnection.

func (*Mysqld) GetMysqlPort

func (mysqld *Mysqld) GetMysqlPort() (int32, error)

GetMysqlPort returns mysql port

func (*Mysqld) GetPrimaryKeyColumns

func (mysqld *Mysqld) GetPrimaryKeyColumns(ctx context.Context, dbName, table string) ([]string, error)

GetPrimaryKeyColumns returns the primary key columns of table.

func (*Mysqld) GetSchema

func (mysqld *Mysqld) GetSchema(ctx context.Context, 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) GetVersionString added in v0.12.1

func (mysqld *Mysqld) GetVersionString() string

GetVersionString is part of the MysqlDeamon interface.

func (*Mysqld) Init

func (mysqld *Mysqld) Init(ctx context.Context, cnf *Mycnf, initDBSQLFile string) error

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) InitConfig

func (mysqld *Mysqld) InitConfig(cnf *Mycnf) error

InitConfig will create the default directory structure for the mysqld process, generate / configure a my.cnf file.

func (*Mysqld) IsReadOnly

func (mysqld *Mysqld) IsReadOnly() (bool, error)

IsReadOnly return true if the instance is read only

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(ctx context.Context, 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) PrimaryPosition added in v0.11.0

func (mysqld *Mysqld) PrimaryPosition() (mysql.Position, error)

PrimaryPosition returns the primary replication position.

func (*Mysqld) PrimaryStatus added in v0.11.0

func (mysqld *Mysqld) PrimaryStatus(ctx context.Context) (mysql.PrimaryStatus, error)

PrimaryStatus returns the primary replication statuses

func (*Mysqld) Promote

func (mysqld *Mysqld) Promote(hookExtraEnv map[string]string) (mysql.Position, error)

Promote will promote this server to be the new primary.

func (*Mysqld) RefreshConfig

func (mysqld *Mysqld) RefreshConfig(ctx context.Context, cnf *Mycnf) error

RefreshConfig attempts to recreate the my.cnf from templates, and log and swap in to place if it's updated. It keeps a copy of the last version in case fallback is required. Should be called from a stable replica, server_id is not regenerated.

func (*Mysqld) ReinitConfig

func (mysqld *Mysqld) ReinitConfig(ctx context.Context, cnf *Mycnf) error

ReinitConfig updates the config file as if Mysqld is initializing. At the moment it only randomizes ServerID because it's not safe to restore a replica from a backup and then give it the same ServerID as before, MySQL can then skip transactions in the replication stream with the same server_id.

func (*Mysqld) ReplicationStatus

func (mysqld *Mysqld) ReplicationStatus() (mysql.ReplicationStatus, error)

ReplicationStatus returns the server replication status

func (*Mysqld) ResetReplication

func (mysqld *Mysqld) ResetReplication(ctx context.Context) error

ResetReplication resets all replication for this host.

func (*Mysqld) RestartReplication

func (mysqld *Mysqld) RestartReplication(hookExtraEnv map[string]string) error

RestartReplication stops, resets and starts replication.

func (*Mysqld) RunMysqlUpgrade

func (mysqld *Mysqld) RunMysqlUpgrade() error

RunMysqlUpgrade will run the mysql_upgrade program on the current install. Will be called only when mysqld is running with no network and no grant tables.

func (*Mysqld) SemiSyncEnabled

func (mysqld *Mysqld) SemiSyncEnabled() (primary, replica bool)

SemiSyncEnabled returns whether semi-sync is enabled for primary or replica. If the semi-sync plugin is not loaded, we assume semi-sync is disabled.

func (*Mysqld) SemiSyncReplicationStatus

func (mysqld *Mysqld) SemiSyncReplicationStatus() (bool, error)

SemiSyncReplicationStatus returns whether semi-sync is currently used by replication.

func (*Mysqld) SetReadOnly

func (mysqld *Mysqld) SetReadOnly(on bool) error

SetReadOnly set/unset the read_only flag

func (*Mysqld) SetReplicationPosition

func (mysqld *Mysqld) SetReplicationPosition(ctx context.Context, pos mysql.Position) error

SetReplicationPosition sets the replication position at which the replica will resume when its replication is started.

func (*Mysqld) SetReplicationSource added in v0.11.0

func (mysqld *Mysqld) SetReplicationSource(ctx context.Context, host string, port int, replicationStopBefore bool, replicationStartAfter bool) error

SetReplicationSource makes the provided host / port the primary. It optionally stops replication before, and starts it after.

func (*Mysqld) SetSemiSyncEnabled

func (mysqld *Mysqld) SetSemiSyncEnabled(primary, replica bool) error

SetSemiSyncEnabled enables or disables semi-sync replication for primary and/or replica mode.

func (*Mysqld) SetSuperReadOnly

func (mysqld *Mysqld) SetSuperReadOnly(on bool) error

SetSuperReadOnly set/unset the super_read_only flag

func (*Mysqld) Shutdown

func (mysqld *Mysqld) Shutdown(ctx context.Context, cnf *Mycnf, waitForMysqld bool) error

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) Start

func (mysqld *Mysqld) Start(ctx context.Context, cnf *Mycnf, mysqldArgs ...string) error

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. When waiting for mysqld to start, we will use the dba user.

func (*Mysqld) StartReplication

func (mysqld *Mysqld) StartReplication(hookExtraEnv map[string]string) error

StartReplication starts replication.

func (*Mysqld) StartReplicationUntilAfter

func (mysqld *Mysqld) StartReplicationUntilAfter(ctx context.Context, targetPos mysql.Position) error

StartReplicationUntilAfter starts replication until replication has come to `targetPos`, then it stops replication

func (*Mysqld) StopIOThread

func (mysqld *Mysqld) StopIOThread(ctx context.Context) error

StopIOThread stops a replica's IO thread only.

func (*Mysqld) StopReplication

func (mysqld *Mysqld) StopReplication(hookExtraEnv map[string]string) error

StopReplication stops replication.

func (*Mysqld) Teardown

func (mysqld *Mysqld) Teardown(ctx context.Context, cnf *Mycnf, force bool) error

Teardown will shutdown the running daemon, and delete the root directory.

func (*Mysqld) Wait

func (mysqld *Mysqld) Wait(ctx context.Context, cnf *Mycnf) error

Wait returns nil when mysqld is up and accepting connections. It will use the dba credentials to try to connect. Use wait() with different credentials if needed.

func (*Mysqld) WaitForReparentJournal

func (mysqld *Mysqld) WaitForReparentJournal(ctx context.Context, timeCreatedNS int64) error

WaitForReparentJournal will wait until the context is done for the row in the reparent_journal table.

func (*Mysqld) WaitSourcePos added in v0.11.0

func (mysqld *Mysqld) WaitSourcePos(ctx context.Context, targetPos mysql.Position) error

WaitSourcePos lets replicas wait to given replication position

type RestoreEngine

type RestoreEngine interface {
	ExecuteRestore(ctx context.Context, params RestoreParams, bh backupstorage.BackupHandle) (*BackupManifest, error)
}

RestoreEngine is the interface to restore a backup with a given engine. Returns the manifest of a backup if successful, otherwise returns an error

func GetRestoreEngine

func GetRestoreEngine(ctx context.Context, backup backupstorage.BackupHandle) (RestoreEngine, error)

GetRestoreEngine returns the RestoreEngine implementation to restore a given backup. It reads the MANIFEST file from the backup to check which engine was used to create it.

type RestoreParams

type RestoreParams struct {
	Cnf    *Mycnf
	Mysqld MysqlDaemon
	Logger logutil.Logger
	// Concurrency is the value of -restore_concurrency flag (init restore parameter)
	// It determines how many files are processed in parallel
	Concurrency int
	// Extra env variables for pre-restore and post-restore transform hooks
	HookExtraEnv map[string]string
	// Metadata to write into database after restore. See PopulateMetadataTables
	LocalMetadata map[string]string
	// DeleteBeforeRestore tells us whether existing data should be deleted before
	// restoring. This is always set to false when starting a tablet with -restore_from_backup,
	// but is set to true when executing a RestoreFromBackup command on an already running vttablet
	DeleteBeforeRestore bool
	// DbName is the name of the managed database / schema
	DbName string
	// Keyspace and Shard are used to infer the directory where backups are stored
	Keyspace string
	Shard    string
	// StartTime: if non-zero, look for a backup that was taken at or before this time
	// Otherwise, find the most recent backup
	StartTime time.Time
}

RestoreParams is the struct that holds all params passed to ExecuteRestore

type XtrabackupEngine

type XtrabackupEngine struct {
}

XtrabackupEngine encapsulates the logic of the xtrabackup engine it implements the BackupEngine interface and contains all the logic required to implement a backup/restore by invoking xtrabackup with the appropriate parameters

func (*XtrabackupEngine) ExecuteBackup

func (be *XtrabackupEngine) ExecuteBackup(ctx context.Context, params BackupParams, bh backupstorage.BackupHandle) (complete bool, finalErr error)

ExecuteBackup returns a boolean that indicates if the backup is usable, and an overall error.

func (*XtrabackupEngine) ExecuteRestore

ExecuteRestore restores from a backup. Any error is returned.

func (*XtrabackupEngine) ShouldDrainForBackup

func (be *XtrabackupEngine) ShouldDrainForBackup() bool

ShouldDrainForBackup satisfies the BackupEngine interface xtrabackup can run while tablet is serving, hence false

Directories

Path Synopsis
Package azblobbackupstorage implements the BackupStorage interface for Azure Blob Storage
Package azblobbackupstorage implements the BackupStorage interface for Azure Blob Storage
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 mysqlctlproto provides utility functions for working with data structures in mysqlctl.proto.
Package mysqlctlproto provides utility functions for working with data structures in mysqlctl.proto.
Package s3backupstorage implements the BackupStorage interface for AWS S3.
Package s3backupstorage implements the BackupStorage interface for AWS S3.
Package tmutils contains helper methods to deal with the tabletmanagerdata proto3 structures.
Package tmutils contains helper methods to deal with the tabletmanagerdata proto3 structures.

Jump to

Keyboard shortcuts

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