schema

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DDLStrategyNormal means not an online-ddl migration. Just a normal MySQL ALTER TABLE
	DDLStrategyNormal sqlparser.DDLStrategy = ""
	// DDLStrategyGhost requests gh-ost to run the migration
	DDLStrategyGhost sqlparser.DDLStrategy = "gh-ost"
	// DDLStrategyPTOSC requests pt-online-schema-change to run the migration
	DDLStrategyPTOSC sqlparser.DDLStrategy = "pt-osc"
)

Variables

This section is empty.

Functions

func CreateUUID

func CreateUUID() (string, error)

CreateUUID creates a globally unique ID, returned as string example result: 55d00cdc_e6ab_11ea_bfe6_0242ac1c000d

func GenerateRenameStatement

func GenerateRenameStatement(fromTableName string, state TableGCState, t time.Time) (statement string, toTableName string, err error)

GenerateRenameStatement generates a "RENAME TABLE" statement, where a table is renamed to a GC table.

func IsGCTableName

func IsGCTableName(tableName string) bool

IsGCTableName answers 'true' when the given table name stands for a GC table

func IsOnlineDDLUUID

func IsOnlineDDLUUID(uuid string) bool

IsOnlineDDLUUID answers 'true' when the given string is an online-ddl UUID, e.g.: a0638f6b_ec7b_11ea_9bf8_000d3a9b8a9a

func MigrationBasePath

func MigrationBasePath() string

MigrationBasePath is the root for all schema migration entries

func MigrationJobsKeyspacePath

func MigrationJobsKeyspacePath(keyspace string) string

MigrationJobsKeyspacePath is the base path for a tablet job, by keyspace

func MigrationJobsKeyspaceShardPath

func MigrationJobsKeyspaceShardPath(keyspace, shard string) string

MigrationJobsKeyspaceShardPath is the base path for a tablet job, by keyspace and shard

func MigrationQueuedPath

func MigrationQueuedPath() string

MigrationQueuedPath is the base path for schema migrations that have been reviewed and queued for execution. Kept for historical reference

func MigrationRequestsPath

func MigrationRequestsPath() string

MigrationRequestsPath is the base path for all newly received schema migration requests. such requests need to be investigates/reviewed, and to be assigned to all shards

func ParseAlterTableOptions

func ParseAlterTableOptions(alterStatement string) (explicitSchema, explicitTable, alterOptions string)

ParseAlterTableOptions parses a ALTER ... TABLE... statement into: - explicit schema and table, if available - alter options (anything that follows ALTER ... TABLE)

func ParseGCLifecycle

func ParseGCLifecycle(gcLifecycle string) (states map[TableGCState]bool, err error)

ParseGCLifecycle parses a comma separated list of gc states and returns a map of indicated states

func RemoveOnlineDDLHints

func RemoveOnlineDDLHints(alterStatement string) (normalizedAlterStatement string)

RemoveOnlineDDLHints removes a WITH_GHOST or WITH_PT hint, which is vitess-specific, from an ALTER TABLE statement e.g "ALTER WITH 'gh-ost' TABLE my_table DROP COLUMN i" -> "ALTER TABLE `my_table` DROP COLUMN i"

func ToReadableTimestamp

func ToReadableTimestamp(t time.Time) string

ToReadableTimestamp returns a timestamp, in seconds resolution, that is human readable (as opposed to unix timestamp which is just a number) Example: for Aug 25 2020, 16:04:25 we return "20200825160425"

Types

type OnlineDDL

type OnlineDDL struct {
	Keyspace    string                `json:"keyspace,omitempty"`
	Table       string                `json:"table,omitempty"`
	Schema      string                `json:"schema,omitempty"`
	SQL         string                `json:"sql,omitempty"`
	UUID        string                `json:"uuid,omitempty"`
	Strategy    sqlparser.DDLStrategy `json:"strategy,omitempty"`
	Options     string                `json:"options,omitempty"`
	RequestTime int64                 `json:"time_created,omitempty"`
	Status      OnlineDDLStatus       `json:"status,omitempty"`
}

OnlineDDL encapsulates the relevant information in an online schema change request

func FromJSON

func FromJSON(bytes []byte) (*OnlineDDL, error)

FromJSON creates an OnlineDDL from json

func NewOnlineDDL

func NewOnlineDDL(keyspace string, table string, sql string, strategy sqlparser.DDLStrategy, options string) (*OnlineDDL, error)

NewOnlineDDL creates a schema change request with self generated UUID and RequestTime

func ReadTopo

func ReadTopo(ctx context.Context, conn topo.Conn, entryPath string) (*OnlineDDL, error)

ReadTopo reads a OnlineDDL object from given topo connection

func (*OnlineDDL) JobsKeyspaceShardPath

func (onlineDDL *OnlineDDL) JobsKeyspaceShardPath(shard string) string

JobsKeyspaceShardPath returns job/<keyspace>/<shard>/<uuid>

func (*OnlineDDL) RequestTimeSeconds

func (onlineDDL *OnlineDDL) RequestTimeSeconds() int64

RequestTimeSeconds converts request time to seconds (losing nano precision)

func (*OnlineDDL) ToJSON

func (onlineDDL *OnlineDDL) ToJSON() ([]byte, error)

ToJSON exports this onlineDDL to JSON

func (*OnlineDDL) ToString

func (onlineDDL *OnlineDDL) ToString() string

ToString returns a simple string representation of this instance

func (*OnlineDDL) WriteTopo

func (onlineDDL *OnlineDDL) WriteTopo(ctx context.Context, conn topo.Conn, basePath string) error

WriteTopo writes this online DDL to given topo connection, based on basePath and and this DDL's UUID

type OnlineDDLStatus

type OnlineDDLStatus string

OnlineDDLStatus is an indicator to a online DDL status

const (
	OnlineDDLStatusRequested OnlineDDLStatus = "requested"
	OnlineDDLStatusCancelled OnlineDDLStatus = "cancelled"
	OnlineDDLStatusQueued    OnlineDDLStatus = "queued"
	OnlineDDLStatusReady     OnlineDDLStatus = "ready"
	OnlineDDLStatusRunning   OnlineDDLStatus = "running"
	OnlineDDLStatusComplete  OnlineDDLStatus = "complete"
	OnlineDDLStatusFailed    OnlineDDLStatus = "failed"
)

type TableGCState

type TableGCState string

TableGCState provides a state for the type of GC table: HOLD? PURGE? EVAC? DROP? See details below

const (
	// HoldTableGCState is the state where table was just renamed away. Data is still in tact,
	// and the user has the option to rename it back. A "safety" period.
	HoldTableGCState TableGCState = "HOLD"
	// PurgeTableGCState is the state where we purge table data. Table in this state is "lost" to the user.
	// if in this state, the table will be fully purged.
	PurgeTableGCState TableGCState = "PURGE"
	// EvacTableGCState is a waiting state, where we merely wait out the table's pages to be
	// gone from InnoDB's buffer pool, adaptive hash index cache, and whatnot.
	EvacTableGCState TableGCState = "EVAC"
	// DropTableGCState is the state where the table is to be dropped. Probably ASAP
	DropTableGCState TableGCState = "DROP"
)

func AnalyzeGCTableName

func AnalyzeGCTableName(tableName string) (isGCTable bool, state TableGCState, t time.Time, err error)

AnalyzeGCTableName analyzes a given table name to see if it's a GC table, and if so, parse out its state and timestamp

Jump to

Keyboard shortcuts

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