Documentation ¶
Index ¶
- Constants
- Variables
- func CreateOnlineDDLUUID() (string, error)
- func CreateUUID() (string, error)
- func GenerateGCTableName(state TableGCState, t time.Time) (tableName string, err error)
- func GenerateRenameStatement(fromTableName string, state TableGCState, t time.Time) (statement string, toTableName string, err error)
- func GenerateRenameStatementWithUUID(fromTableName string, state TableGCState, uuid string, t time.Time) (statement string, toTableName string, err error)
- func IsGCTableName(tableName string) bool
- func IsGCUUID(uuid string) bool
- func IsInternalOperationTableName(tableName string) bool
- func IsOnlineDDLTableName(tableName string) bool
- func IsOnlineDDLUUID(uuid string) bool
- func MigrationBasePath() string
- func MigrationJobsKeyspacePath(keyspace string) string
- func MigrationJobsKeyspaceShardPath(keyspace, shard string) string
- func MigrationQueuedPath() string
- func MigrationRequestsPath() string
- func OnlineDDLToGCUUID(uuid string) string
- func ParseAlterTableOptions(alterStatement string) (explicitSchema, explicitTable, alterOptions string)
- func ParseEnumOrSetTokensMap(enumOrSetValues string) map[string]string
- func ParseEnumValues(enumColumnType string) string
- func ParseGCLifecycle(gcLifecycle string) (states map[TableGCState]bool, err error)
- func ParseOnlineDDLStatement(sql string) (ddlStmt sqlparser.DDLStatement, action sqlparser.DDLAction, err error)
- func ParseSetValues(setColumnType string) string
- func ReplaceTableNameInCreateTableStatement(createStatement string, replacementName string) (modifiedStatement string, err error)
- func ToReadableTimestamp(t time.Time) string
- type DDLStrategy
- type DDLStrategySetting
- func (cached *DDLStrategySetting) CachedSize(alloc bool) int64
- func (setting *DDLStrategySetting) IsAllowConcurrent() bool
- func (setting *DDLStrategySetting) IsAllowZeroInDateFlag() bool
- func (setting *DDLStrategySetting) IsDeclarative() bool
- func (setting *DDLStrategySetting) IsPostponeCompletion() bool
- func (setting *DDLStrategySetting) IsSingleton() bool
- func (setting *DDLStrategySetting) IsSingletonContext() bool
- func (setting *DDLStrategySetting) IsSkipTopo() bool
- func (setting *DDLStrategySetting) IsVreplicationTestSuite() bool
- func (setting *DDLStrategySetting) RuntimeOptions() []string
- func (setting *DDLStrategySetting) ToString() string
- type NormalizedDDLQuery
- type OnlineDDL
- func FromJSON(bytes []byte) (*OnlineDDL, error)
- func NewOnlineDDL(keyspace string, table string, sql string, ...) (onlineDDL *OnlineDDL, err error)
- func NewOnlineDDLs(keyspace string, sql string, ddlStmt sqlparser.DDLStatement, ...) (onlineDDLs [](*OnlineDDL), err error)
- func OnlineDDLFromCommentedStatement(stmt sqlparser.Statement) (onlineDDL *OnlineDDL, err error)
- func ReadTopo(ctx context.Context, conn topo.Conn, entryPath string) (*OnlineDDL, error)
- func (onlineDDL *OnlineDDL) GetAction() (action sqlparser.DDLAction, err error)
- func (onlineDDL *OnlineDDL) GetActionStr() (action sqlparser.DDLAction, actionStr string, err error)
- func (onlineDDL *OnlineDDL) GetGCUUID() string
- func (onlineDDL *OnlineDDL) GetRevertUUID() (uuid string, err error)
- func (onlineDDL *OnlineDDL) JobsKeyspaceShardPath(shard string) string
- func (onlineDDL *OnlineDDL) RequestTimeSeconds() int64
- func (onlineDDL *OnlineDDL) StrategySetting() *DDLStrategySetting
- func (onlineDDL *OnlineDDL) ToJSON() ([]byte, error)
- func (onlineDDL *OnlineDDL) ToString() string
- func (onlineDDL *OnlineDDL) WriteTopo(ctx context.Context, conn topo.Conn, basePath string) error
- type OnlineDDLStatus
- type TableGCState
Constants ¶
const ( SchemaMigrationsTableName = "schema_migrations" RevertActionStr = "revert" )
Variables ¶
var ( // ErrDirectDDLDisabled is returned when direct DDL is disabled, and a user attempts to run a DDL statement ErrDirectDDLDisabled = errors.New("direct DDL is disabled") // ErrOnlineDDLDisabled is returned when online DDL is disabled, and a user attempts to run an online DDL operation (submit, review, control) ErrOnlineDDLDisabled = errors.New("online DDL is disabled") // ErrForeignKeyFound indicates any finding of FOREIGN KEY clause in a DDL statement ErrForeignKeyFound = errors.New("Foreign key found") // ErrRenameTableFound indicates finding of ALTER TABLE...RENAME in ddl statement ErrRenameTableFound = errors.New("RENAME clause found") )
Functions ¶
func CreateOnlineDDLUUID ¶ added in v0.11.0
CreateOnlineDDLUUID creates a UUID in OnlineDDL format, e.g.: a0638f6b_ec7b_11ea_9bf8_000d3a9b8a9a
func CreateUUID ¶
CreateUUID creates a globally unique ID example result "1876a01a-354d-11eb-9a79-f8e4e33000bb"
func GenerateGCTableName ¶ added in v0.10.0
func GenerateGCTableName(state TableGCState, t time.Time) (tableName string, err error)
GenerateGCTableName creates a GC table name, based on desired state and time, and with random UUID
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 GenerateRenameStatementWithUUID ¶ added in v0.9.0
func GenerateRenameStatementWithUUID(fromTableName string, state TableGCState, uuid string, t time.Time) (statement string, toTableName string, err error)
GenerateRenameStatementWithUUID generates a "RENAME TABLE" statement, where a table is renamed to a GC table, with preset UUID
func IsGCTableName ¶
IsGCTableName answers 'true' when the given table name stands for a GC table
func IsGCUUID ¶ added in v0.9.0
IsGCUUID answers 'true' when the given string is an GC UUID, e.g.: a0638f6bec7b11ea9bf8000d3a9b8a9a
func IsInternalOperationTableName ¶ added in v0.9.0
IsInternalOperationTableName answers 'true' when the given table name stands for an internal Vitess table used for operations such as: - Online DDL (gh-ost, pt-online-schema-change) - Table GC (renamed before drop) Apps such as VStreamer may choose to ignore such tables.
func IsOnlineDDLTableName ¶ added in v0.9.0
IsOnlineDDLTableName answers 'true' when the given table name _appears to be_ a name generated by an online DDL operation; either the name determined by the online DDL Executor, or by pt-online-schema-change. There is no guarantee that the tables _was indeed_ generated by an online DDL flow.
func IsOnlineDDLUUID ¶
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 ¶
MigrationJobsKeyspacePath is the base path for a tablet job, by keyspace
func MigrationJobsKeyspaceShardPath ¶
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 OnlineDDLToGCUUID ¶ added in v0.9.0
OnlineDDLToGCUUID converts a UUID in online-ddl format to GC-table format
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 ParseEnumOrSetTokensMap ¶ added in v0.13.0
ParseEnumOrSetTokensMap parses the comma delimited part of an enum column definition and returns a map where ["1"] is the first token, and ["<n>"] is th elast token
func ParseEnumValues ¶ added in v0.11.0
ParseEnumValues parses the comma delimited part of an enum column definition
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 ParseOnlineDDLStatement ¶ added in v0.9.0
func ParseOnlineDDLStatement(sql string) (ddlStmt sqlparser.DDLStatement, action sqlparser.DDLAction, err error)
ParseOnlineDDLStatement parses the given SQL into a statement and returns the action type of the DDL statement, or error if the statement is not a DDL
func ParseSetValues ¶ added in v0.13.0
ParseSetValues parses the comma delimited part of a set column definition
func ReplaceTableNameInCreateTableStatement ¶ added in v0.10.0
func ReplaceTableNameInCreateTableStatement(createStatement string, replacementName string) (modifiedStatement string, err error)
ReplaceTableNameInCreateTableStatement returns a modified CREATE TABLE statement, such that the table name is replaced with given name. This intentionally string-replacement based, and not sqlparser.String() based, because the return statement has to be formatted _precisely_, up to MySQL version nuances, like the original statement. That's in favor of tengo table comparison. We expect a well formatted, no-qualifier statement in the form: CREATE TABLE `some_table` ...
func ToReadableTimestamp ¶
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 DDLStrategy ¶ added in v0.9.0
type DDLStrategy string
DDLStrategy suggests how an ALTER TABLE should run (e.g. "direct", "online", "gh-ost" or "pt-osc")
const ( // DDLStrategyDirect means not an online-ddl migration. Just a normal MySQL ALTER TABLE DDLStrategyDirect DDLStrategy = "direct" // DDLStrategyVitess requests vreplication to run the migration; new name for DDLStrategyOnline DDLStrategyVitess DDLStrategy = "vitess" // DDLStrategyOnline requests vreplication to run the migration DDLStrategyOnline DDLStrategy = "online" // DDLStrategyGhost requests gh-ost to run the migration DDLStrategyGhost DDLStrategy = "gh-ost" // DDLStrategyPTOSC requests pt-online-schema-change to run the migration DDLStrategyPTOSC DDLStrategy = "pt-osc" )
func (DDLStrategy) IsDirect ¶ added in v0.9.0
func (s DDLStrategy) IsDirect() bool
IsDirect returns true if this strategy is a direct strategy A strategy is direct if it's not explciitly one of the online DDL strategies
type DDLStrategySetting ¶ added in v0.11.0
type DDLStrategySetting struct { Strategy DDLStrategy `json:"strategy,omitempty"` Options string `json:"options,omitempty"` }
DDLStrategySetting is a formal breakdown of the @@ddl_strategy variable, into strategy and options
func NewDDLStrategySetting ¶ added in v0.11.0
func NewDDLStrategySetting(strategy DDLStrategy, options string) *DDLStrategySetting
NewDDLStrategySetting instantiates a new setting
func ParseDDLStrategy ¶ added in v0.9.0
func ParseDDLStrategy(strategyVariable string) (*DDLStrategySetting, error)
ParseDDLStrategy parses and validates the value of @@ddl_strategy or -ddl_strategy variables
func (*DDLStrategySetting) CachedSize ¶ added in v0.11.0
func (cached *DDLStrategySetting) CachedSize(alloc bool) int64
func (*DDLStrategySetting) IsAllowConcurrent ¶ added in v0.13.0
func (setting *DDLStrategySetting) IsAllowConcurrent() bool
IsAllowConcurrent checks if strategy options include -allow-concurrent
func (*DDLStrategySetting) IsAllowZeroInDateFlag ¶ added in v0.13.0
func (setting *DDLStrategySetting) IsAllowZeroInDateFlag() bool
IsAllowZeroInDateFlag checks if strategy options include -allow-zero-in-date
func (*DDLStrategySetting) IsDeclarative ¶ added in v0.11.0
func (setting *DDLStrategySetting) IsDeclarative() bool
IsDeclarative checks if strategy options include -declarative
func (*DDLStrategySetting) IsPostponeCompletion ¶ added in v0.13.0
func (setting *DDLStrategySetting) IsPostponeCompletion() bool
IsPostponeCompletion checks if strategy options include -postpone-completion
func (*DDLStrategySetting) IsSingleton ¶ added in v0.11.0
func (setting *DDLStrategySetting) IsSingleton() bool
IsSingleton checks if strategy options include -singleton
func (*DDLStrategySetting) IsSingletonContext ¶ added in v0.11.0
func (setting *DDLStrategySetting) IsSingletonContext() bool
IsSingletonContext checks if strategy options include -singleton-context
func (*DDLStrategySetting) IsSkipTopo ¶ added in v0.11.0
func (setting *DDLStrategySetting) IsSkipTopo() bool
IsSkipTopo suggests that DDL should apply to tables bypassing global topo request
func (*DDLStrategySetting) IsVreplicationTestSuite ¶ added in v0.11.0
func (setting *DDLStrategySetting) IsVreplicationTestSuite() bool
IsVreplicationTestSuite checks if strategy options include -vreplicatoin-test-suite
func (*DDLStrategySetting) RuntimeOptions ¶ added in v0.11.0
func (setting *DDLStrategySetting) RuntimeOptions() []string
RuntimeOptions returns the options used as runtime flags for given strategy, removing any internal hint options
func (*DDLStrategySetting) ToString ¶ added in v0.11.0
func (setting *DDLStrategySetting) ToString() string
ToString returns a simple string representation of this instance
type NormalizedDDLQuery ¶ added in v0.9.0
NormalizedDDLQuery contains a query which is online-ddl -normalized
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 DDLStrategy `json:"strategy,omitempty"` Options string `json:"options,omitempty"` RequestTime int64 `json:"time_created,omitempty"` MigrationContext string `json:"context,omitempty"` Status OnlineDDLStatus `json:"status,omitempty"` TabletAlias string `json:"tablet,omitempty"` Retries int64 `json:"retries,omitempty"` }
OnlineDDL encapsulates the relevant information in an online schema change request
func NewOnlineDDL ¶
func NewOnlineDDL(keyspace string, table string, sql string, ddlStrategySetting *DDLStrategySetting, migrationContext string, providedUUID string) (onlineDDL *OnlineDDL, err error)
NewOnlineDDL creates a schema change request with self generated UUID and RequestTime
func NewOnlineDDLs ¶ added in v0.11.0
func NewOnlineDDLs(keyspace string, sql string, ddlStmt sqlparser.DDLStatement, ddlStrategySetting *DDLStrategySetting, migrationContext string, providedUUID string) (onlineDDLs [](*OnlineDDL), err error)
NewOnlineDDLs takes a single DDL statement, normalizes it (potentially break down into multiple statements), and generates one or more OnlineDDL instances, one for each normalized statement
func OnlineDDLFromCommentedStatement ¶ added in v0.11.0
OnlineDDLFromCommentedStatement creates a schema instance based on a commented query. The query is expected to be commented as e.g. `CREATE /*vt+ uuid=... context=... table=... strategy=... options=... */ TABLE ...`
func (*OnlineDDL) GetAction ¶ added in v0.9.0
GetAction extracts the DDL action type from the online DDL statement
func (*OnlineDDL) GetActionStr ¶ added in v0.9.0
func (onlineDDL *OnlineDDL) GetActionStr() (action sqlparser.DDLAction, actionStr string, err error)
GetActionStr returns a string representation of the DDL action
func (*OnlineDDL) GetRevertUUID ¶ added in v0.10.0
GetRevertUUID works when this migration is a revert for another migration. It returns the UUID fo the reverted migration. The function returns error when this is not a revert migration.
func (*OnlineDDL) JobsKeyspaceShardPath ¶
JobsKeyspaceShardPath returns job/<keyspace>/<shard>/<uuid>
func (*OnlineDDL) RequestTimeSeconds ¶
RequestTimeSeconds converts request time to seconds (losing nano precision)
func (*OnlineDDL) StrategySetting ¶ added in v0.11.0
func (onlineDDL *OnlineDDL) StrategySetting() *DDLStrategySetting
StrategySetting returns the ddl strategy setting associated with this online DDL
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, uuid string, 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, uuid, and timestamp