Documentation ¶
Index ¶
- Constants
- Variables
- 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 ParseGCLifecycle(gcLifecycle string) (states map[TableGCState]bool, err error)
- func ParseOnlineDDLStatement(sql string) (ddlStmt sqlparser.DDLStatement, action sqlparser.DDLAction, err error)
- func ReplaceTableNameInCreateTableStatement(createStatement string, replacementName string) (modifiedStatement string, err error)
- func ToReadableTimestamp(t time.Time) string
- type DDLStrategy
- type NormalizedDDLQuery
- type OnlineDDL
- 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) IsDeclarative() bool
- func (onlineDDL *OnlineDDL) JobsKeyspaceShardPath(shard string) string
- func (onlineDDL *OnlineDDL) RequestTimeSeconds() int64
- func (onlineDDL *OnlineDDL) RuntimeOptions() []string
- 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 ( // 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") )
Functions ¶
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 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 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. "" for normal, "gh-ost" or "pt-osc")
const ( // DDLStrategyDirect means not an online-ddl migration. Just a normal MySQL ALTER TABLE DDLStrategyDirect DDLStrategy = "direct" // 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 ParseDDLStrategy ¶ added in v0.9.0
func ParseDDLStrategy(strategyVariable string) (strategy DDLStrategy, options string, err error)
ParseDDLStrategy validates the given ddl_strategy variable value , and parses the strategy and options parts.
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 NormalizedDDLQuery ¶ added in v0.9.0
NormalizedDDLQuery contains a query which is online-ddl -normalized
func NormalizeOnlineDDL ¶ added in v0.9.0
func NormalizeOnlineDDL(sql string) (normalized []*NormalizedDDLQuery, err error)
NormalizeOnlineDDL normalizes a given query for OnlineDDL, possibly exploding it into multiple distinct queries
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"` RequestContext 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, strategy DDLStrategy, options string, requestContext string) (*OnlineDDL, error)
NewOnlineDDL creates a schema change request with self generated UUID and RequestTime
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) IsDeclarative ¶ added in v0.10.0
IsDeclarative checks if strategy options include -declarative
func (*OnlineDDL) JobsKeyspaceShardPath ¶
JobsKeyspaceShardPath returns job/<keyspace>/<shard>/<uuid>
func (*OnlineDDL) RequestTimeSeconds ¶
RequestTimeSeconds converts request time to seconds (losing nano precision)
func (*OnlineDDL) RuntimeOptions ¶ added in v0.10.0
RuntimeOptions returns the options used as runtime flags for given strategy, removing any internal hint options
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