onlineddl

package
v0.0.0-...-cc2de37 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GhostDDLInfo

type GhostDDLInfo struct {
	Schema string `json:"schema"`
	Table  string `json:"table"`

	DDLs []string `json:"ddls"`
}

GhostDDLInfo stores ghost information and ddls.

type OnlinePlugin

type OnlinePlugin interface {
	// Apply does:
	// * detect online ddl
	// * record changes
	// * apply online ddl on real table
	// returns sqls, error
	Apply(tctx *tcontext.Context, tables []*filter.Table, statement string, stmt ast.StmtNode, p *parser.Parser) ([]string, error)
	// Finish would delete online ddl from memory and storage
	Finish(tctx *tcontext.Context, table *filter.Table) error
	// TableType returns ghost/real table
	TableType(table string) TableType
	// RealName returns real table name that removed ghost suffix and handled by table router
	RealName(table string) string
	// ResetConn reset db connection
	ResetConn(tctx *tcontext.Context) error
	// Clear clears all online information
	// TODO: not used now, check if we could remove it later
	Clear(tctx *tcontext.Context) error
	// Close closes online ddl plugin
	Close()
	// CheckAndUpdate try to check and fix the schema/table case-sensitive issue
	CheckAndUpdate(tctx *tcontext.Context, schemas map[string]string, tables map[string]map[string]string) error
	// CheckRegex checks the regex of shadow/trash table rules and reports an error if a ddl event matches only either of the rules
	CheckRegex(stmt ast.StmtNode, schema string, flavor conn.LowerCaseTableNamesFlavor) error
}

OnlinePlugin handles online ddl solutions like pt, gh-ost.

func NewRealOnlinePlugin

func NewRealOnlinePlugin(
	tctx *tcontext.Context,
	cfg *config.SubTaskConfig,
	metricProxies *metrics.Proxies,
) (OnlinePlugin, error)

NewRealOnlinePlugin returns real online plugin.

type RealOnlinePlugin

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

RealOnlinePlugin support ghost and pt Ghost's table format: _*_gho ghost table _*_ghc ghost changelog table _*_del ghost transh table. PT's table format: (_*).*_new ghost table (_*).*_old ghost trash table we don't support `--new-table-name` flag.

func (*RealOnlinePlugin) Apply

func (r *RealOnlinePlugin) Apply(tctx *tcontext.Context, tables []*filter.Table, statement string, stmt ast.StmtNode, p *parser.Parser) ([]string, error)

Apply implements interface. returns ddls, error.

func (*RealOnlinePlugin) CheckAndUpdate

func (r *RealOnlinePlugin) CheckAndUpdate(tctx *tcontext.Context, schemas map[string]string, tables map[string]map[string]string) error

CheckAndUpdate try to check and fix the schema/table case-sensitive issue.

func (*RealOnlinePlugin) CheckRegex

func (r *RealOnlinePlugin) CheckRegex(stmt ast.StmtNode, schema string, flavor conn.LowerCaseTableNamesFlavor) error

CheckRegex checks the regex of shadow/trash table rules and reports an error if a ddl event matches only either of the rules.

func (*RealOnlinePlugin) Clear

func (r *RealOnlinePlugin) Clear(tctx *tcontext.Context) error

Clear clears online ddl information.

func (*RealOnlinePlugin) Close

func (r *RealOnlinePlugin) Close()

Close implements interface.

func (*RealOnlinePlugin) Finish

func (r *RealOnlinePlugin) Finish(tctx *tcontext.Context, table *filter.Table) error

Finish implements interface.

func (*RealOnlinePlugin) RealName

func (r *RealOnlinePlugin) RealName(table string) string

RealName implements interface.

func (*RealOnlinePlugin) ResetConn

func (r *RealOnlinePlugin) ResetConn(tctx *tcontext.Context) error

ResetConn implements interface.

func (*RealOnlinePlugin) TableType

func (r *RealOnlinePlugin) TableType(table string) TableType

TableType implements interface.

type Storage

type Storage struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Storage stores sharding group online ddls information.

func NewOnlineDDLStorage

func NewOnlineDDLStorage(
	logCtx *tcontext.Context,
	cfg *config.SubTaskConfig,
	metricProxies *metrics.Proxies,
) *Storage

NewOnlineDDLStorage creates a new online ddl storager.

func (*Storage) CheckAndUpdate

func (s *Storage) CheckAndUpdate(
	tctx *tcontext.Context,
	schemaMap map[string]string,
	tablesMap map[string]map[string]string,
	realNameFn func(table string) string,
) error

CheckAndUpdate try to check and fix the schema/table case-sensitive issue.

func (*Storage) Clear

func (s *Storage) Clear(tctx *tcontext.Context) error

Clear clears online ddl information from storage.

func (*Storage) Close

func (s *Storage) Close()

Close closes database connection.

func (*Storage) Delete

func (s *Storage) Delete(tctx *tcontext.Context, ghostSchema, ghostTable string) error

Delete deletes online ddl informations.

func (*Storage) Get

func (s *Storage) Get(ghostSchema, ghostTable string) *GhostDDLInfo

Get returns ddls by given schema/table.

func (*Storage) Init

func (s *Storage) Init(tctx *tcontext.Context) error

Init initials online handler.

func (*Storage) Load

func (s *Storage) Load(tctx *tcontext.Context) error

Load loads information from storage.

func (*Storage) ResetConn

func (s *Storage) ResetConn(tctx *tcontext.Context) error

ResetConn implements OnlinePlugin.ResetConn.

func (*Storage) Save

func (s *Storage) Save(tctx *tcontext.Context, ghostSchema, ghostTable, realSchema, realTable, ddl string) error

Save saves online ddl information.

type TableType

type TableType string

TableType is type of table.

const (
	RealTable  TableType = "real table"
	GhostTable TableType = "ghost table"
	TrashTable TableType = "trash table" // means we should ignore these tables
)

below variables will be explained later.

Jump to

Keyboard shortcuts

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