Documentation ¶
Index ¶
- Constants
- func CreateUUID() (string, error)
- func GenerateRenameStatement(fromTableName string, state TableGCState, t time.Time) (statement string, toTableName string, err error)
- func IsGCTableName(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 ParseAlterTableOptions(alterStatement string) (explicitSchema, explicitTable, alterOptions string)
- func ParseGCLifecycle(gcLifecycle string) (states map[TableGCState]bool, err error)
- func RemoveOnlineDDLHints(alterStatement string) (normalizedAlterStatement string)
- func ToReadableTimestamp(t time.Time) string
- type OnlineDDL
- func (onlineDDL *OnlineDDL) JobsKeyspaceShardPath(shard string) string
- func (onlineDDL *OnlineDDL) RequestTimeSeconds() int64
- 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 ( // 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 ¶
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 ¶
IsGCTableName answers 'true' when the given table name stands for a GC table
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 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 ¶
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 ¶
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 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 (*OnlineDDL) JobsKeyspaceShardPath ¶
JobsKeyspaceShardPath returns job/<keyspace>/<shard>/<uuid>
func (*OnlineDDL) RequestTimeSeconds ¶
RequestTimeSeconds converts request time to seconds (losing nano precision)
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