tidb: github.com/pingcap/tidb/ddl Index | Files | Directories

package ddl

import "github.com/pingcap/tidb/ddl"


Package Files

backfilling.go callback.go column.go ddl.go ddl_algorithm.go ddl_api.go ddl_worker.go delete_range.go error.go foreign_key.go generated_column.go index.go mock.go options.go partition.go reorg.go rollingback.go schema.go sequence.go session_pool.go split_region.go stat.go table.go table_lock.go


const (

    // DDLOwnerKey is the ddl owner path that is saved to etcd, and it's exported for testing.
    DDLOwnerKey = "/tidb/ddl/fg/owner"

    // PartitionCountLimit is limit of the number of partitions in a table.
    // Reference linking https://dev.mysql.com/doc/refman/5.7/en/partitioning-limitations.html.
    PartitionCountLimit = 8192
const (
    // MaxCommentLength is exported for testing.
    MaxCommentLength = 1024


var (
    // TestCheckWorkerNumCh use for test adjust backfill worker.
    TestCheckWorkerNumCh = make(chan struct{})
    // TestCheckWorkerNumber use for test adjust backfill worker.
    TestCheckWorkerNumber = int32(16)
    // TestCheckReorgTimeout is used to mock timeout when reorg data.
    TestCheckReorgTimeout = int32(0)
var (
    // TableIndexCountLimit is limit of the number of indexes in a table.
    TableIndexCountLimit = uint32(64)
    // EnableSplitTableRegion is a flag to decide whether to split a new region for
    // a newly created table. It takes effect only if the Storage supports split
    // region.
    EnableSplitTableRegion = uint32(0)
var (
    // RunWorker indicates if this TiDB server starts DDL worker and can run DDL job.
    RunWorker = true

    // WaitTimeWhenErrorOccurred is waiting interval when processing DDL jobs encounter errors.
    WaitTimeWhenErrorOccurred = int64(1 * time.Second)
var (

    // ErrRepairTableFail is used to repair tableInfo in repair mode.
    ErrRepairTableFail = dbterror.ClassDDL.NewStd(mysql.ErrRepairTable)

    // ErrUnsupportedOnGeneratedColumn is for unsupported actions on generated columns.
    ErrUnsupportedOnGeneratedColumn = dbterror.ClassDDL.NewStd(mysql.ErrUnsupportedOnGeneratedColumn)

    // ErrInvalidDefaultValue returns for invalid default value for columns.
    ErrInvalidDefaultValue = dbterror.ClassDDL.NewStd(mysql.ErrInvalidDefault)
    // ErrGeneratedColumnRefAutoInc forbids to refer generated columns to auto-increment columns .
    ErrGeneratedColumnRefAutoInc = dbterror.ClassDDL.NewStd(mysql.ErrGeneratedColumnRefAutoInc)
    // ErrExpressionIndexCanNotRefer forbids to refer expression index to auto-increment column.
    ErrExpressionIndexCanNotRefer = dbterror.ClassDDL.NewStd(mysql.ErrFunctionalIndexRefAutoIncrement)
    // ErrUnsupportedAddPartition returns for does not support add partitions.
    ErrUnsupportedAddPartition = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message(fmt.Sprintf(mysql.MySQLErrName[mysql.ErrUnsupportedDDLOperation].Raw, "add partitions"), nil))
    // ErrUnsupportedCoalescePartition returns for does not support coalesce partitions.
    ErrUnsupportedCoalescePartition = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message(fmt.Sprintf(mysql.MySQLErrName[mysql.ErrUnsupportedDDLOperation].Raw, "coalesce partitions"), nil))

    // ErrGeneratedColumnFunctionIsNotAllowed returns for unsupported functions for generated columns.
    ErrGeneratedColumnFunctionIsNotAllowed = dbterror.ClassDDL.NewStd(mysql.ErrGeneratedColumnFunctionIsNotAllowed)
    // ErrGeneratedColumnRowValueIsNotAllowed returns for generated columns referring to row values.
    ErrGeneratedColumnRowValueIsNotAllowed = dbterror.ClassDDL.NewStd(mysql.ErrGeneratedColumnRowValueIsNotAllowed)
    // ErrUnsupportedPartitionByRangeColumns returns for does unsupported partition by range columns.
    ErrUnsupportedPartitionByRangeColumns = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message(fmt.Sprintf(mysql.MySQLErrName[mysql.ErrUnsupportedDDLOperation].Raw, "partition by range columns"), nil))
    // ErrFunctionalIndexFunctionIsNotAllowed returns for unsupported functions for functional index.
    ErrFunctionalIndexFunctionIsNotAllowed = dbterror.ClassDDL.NewStd(mysql.ErrFunctionalIndexFunctionIsNotAllowed)
    // ErrFunctionalIndexRowValueIsNotAllowed returns for functional index referring to row values.
    ErrFunctionalIndexRowValueIsNotAllowed = dbterror.ClassDDL.NewStd(mysql.ErrFunctionalIndexRowValueIsNotAllowed)

    // ErrDupKeyName returns for duplicated key name
    ErrDupKeyName = dbterror.ClassDDL.NewStd(mysql.ErrDupKeyName)
    // ErrInvalidDDLState returns for invalid ddl model object state.
    ErrInvalidDDLState = dbterror.ClassDDL.NewStdErr(mysql.ErrInvalidDDLState, parser_mysql.Message(fmt.Sprintf(mysql.MySQLErrName[mysql.ErrInvalidDDLState].Raw), nil))
    // ErrUnsupportedModifyPrimaryKey returns an error when add or drop the primary key.
    // It's exported for testing.
    ErrUnsupportedModifyPrimaryKey = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message(fmt.Sprintf(mysql.MySQLErrName[mysql.ErrUnsupportedDDLOperation].Raw, "%s primary key"), nil))
    // ErrPKIndexCantBeInvisible return an error when primary key is invisible index
    ErrPKIndexCantBeInvisible = dbterror.ClassDDL.NewStd(mysql.ErrPKIndexCantBeInvisible)

    // ErrColumnBadNull returns for a bad null value.
    ErrColumnBadNull = dbterror.ClassDDL.NewStd(mysql.ErrBadNull)
    // ErrBadField forbids to refer to unknown column.
    ErrBadField = dbterror.ClassDDL.NewStd(mysql.ErrBadField)
    // ErrCantRemoveAllFields returns for deleting all columns.
    ErrCantRemoveAllFields = dbterror.ClassDDL.NewStd(mysql.ErrCantRemoveAllFields)
    // ErrCantDropFieldOrKey returns for dropping a non-existent field or key.
    ErrCantDropFieldOrKey = dbterror.ClassDDL.NewStd(mysql.ErrCantDropFieldOrKey)
    // ErrInvalidOnUpdate returns for invalid ON UPDATE clause.
    ErrInvalidOnUpdate = dbterror.ClassDDL.NewStd(mysql.ErrInvalidOnUpdate)
    // ErrTooLongIdent returns for too long name of database/table/column/index.
    ErrTooLongIdent = dbterror.ClassDDL.NewStd(mysql.ErrTooLongIdent)
    // ErrWrongDBName returns for wrong database name.
    ErrWrongDBName = dbterror.ClassDDL.NewStd(mysql.ErrWrongDBName)
    // ErrWrongTableName returns for wrong table name.
    ErrWrongTableName = dbterror.ClassDDL.NewStd(mysql.ErrWrongTableName)
    // ErrWrongColumnName returns for wrong column name.
    ErrWrongColumnName = dbterror.ClassDDL.NewStd(mysql.ErrWrongColumnName)
    // ErrInvalidGroupFuncUse returns for using invalid group functions.
    ErrInvalidGroupFuncUse = dbterror.ClassDDL.NewStd(mysql.ErrInvalidGroupFuncUse)
    // ErrTableMustHaveColumns returns for missing column when creating a table.
    ErrTableMustHaveColumns = dbterror.ClassDDL.NewStd(mysql.ErrTableMustHaveColumns)
    // ErrWrongNameForIndex returns for wrong index name.
    ErrWrongNameForIndex = dbterror.ClassDDL.NewStd(mysql.ErrWrongNameForIndex)
    // ErrUnknownCharacterSet returns unknown character set.
    ErrUnknownCharacterSet = dbterror.ClassDDL.NewStd(mysql.ErrUnknownCharacterSet)
    // ErrUnknownCollation returns unknown collation.
    ErrUnknownCollation = dbterror.ClassDDL.NewStd(mysql.ErrUnknownCollation)
    // ErrCollationCharsetMismatch returns when collation not match the charset.
    ErrCollationCharsetMismatch = dbterror.ClassDDL.NewStd(mysql.ErrCollationCharsetMismatch)
    // ErrConflictingDeclarations return conflict declarations.
    ErrConflictingDeclarations = dbterror.ClassDDL.NewStdErr(mysql.ErrConflictingDeclarations, parser_mysql.Message(fmt.Sprintf(mysql.MySQLErrName[mysql.ErrConflictingDeclarations].Raw, "CHARACTER SET ", "%s", "CHARACTER SET ", "%s"), nil))
    // ErrPrimaryCantHaveNull returns All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead
    ErrPrimaryCantHaveNull = dbterror.ClassDDL.NewStd(mysql.ErrPrimaryCantHaveNull)
    // ErrErrorOnRename returns error for wrong database name in alter table rename
    ErrErrorOnRename = dbterror.ClassDDL.NewStd(mysql.ErrErrorOnRename)
    // ErrViewSelectClause returns error for create view with select into clause
    ErrViewSelectClause = dbterror.ClassDDL.NewStd(mysql.ErrViewSelectClause)

    // ErrNotAllowedTypeInPartition returns not allowed type error when creating table partition with unsupported expression type.
    ErrNotAllowedTypeInPartition = dbterror.ClassDDL.NewStd(mysql.ErrFieldTypeNotAllowedAsPartitionField)
    // ErrPartitionMgmtOnNonpartitioned returns it's not a partition table.
    ErrPartitionMgmtOnNonpartitioned = dbterror.ClassDDL.NewStd(mysql.ErrPartitionMgmtOnNonpartitioned)
    // ErrDropPartitionNonExistent returns error in list of partition.
    ErrDropPartitionNonExistent = dbterror.ClassDDL.NewStd(mysql.ErrDropPartitionNonExistent)
    // ErrSameNamePartition returns duplicate partition name.
    ErrSameNamePartition = dbterror.ClassDDL.NewStd(mysql.ErrSameNamePartition)
    // ErrRangeNotIncreasing returns values less than value must be strictly increasing for each partition.
    ErrRangeNotIncreasing = dbterror.ClassDDL.NewStd(mysql.ErrRangeNotIncreasing)
    // ErrPartitionMaxvalue returns maxvalue can only be used in last partition definition.
    ErrPartitionMaxvalue = dbterror.ClassDDL.NewStd(mysql.ErrPartitionMaxvalue)
    // ErrDropLastPartition returns cannot remove all partitions, use drop table instead.
    ErrDropLastPartition = dbterror.ClassDDL.NewStd(mysql.ErrDropLastPartition)
    // ErrTooManyPartitions returns too many partitions were defined.
    ErrTooManyPartitions = dbterror.ClassDDL.NewStd(mysql.ErrTooManyPartitions)
    // ErrPartitionFunctionIsNotAllowed returns this partition function is not allowed.
    ErrPartitionFunctionIsNotAllowed = dbterror.ClassDDL.NewStd(mysql.ErrPartitionFunctionIsNotAllowed)
    // ErrPartitionFuncNotAllowed returns partition function returns the wrong type.
    ErrPartitionFuncNotAllowed = dbterror.ClassDDL.NewStd(mysql.ErrPartitionFuncNotAllowed)
    // ErrUniqueKeyNeedAllFieldsInPf returns must include all columns in the table's partitioning function.
    ErrUniqueKeyNeedAllFieldsInPf = dbterror.ClassDDL.NewStd(mysql.ErrUniqueKeyNeedAllFieldsInPf)
    // ErrWrongExprInPartitionFunc Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed.
    ErrWrongExprInPartitionFunc = dbterror.ClassDDL.NewStd(mysql.ErrWrongExprInPartitionFunc)
    // ErrWarnDataTruncated returns data truncated error.
    ErrWarnDataTruncated = dbterror.ClassDDL.NewStd(mysql.WarnDataTruncated)
    // ErrCoalesceOnlyOnHashPartition returns coalesce partition can only be used on hash/key partitions.
    ErrCoalesceOnlyOnHashPartition = dbterror.ClassDDL.NewStd(mysql.ErrCoalesceOnlyOnHashPartition)
    // ErrViewWrongList returns create view must include all columns in the select clause
    ErrViewWrongList = dbterror.ClassDDL.NewStd(mysql.ErrViewWrongList)
    // ErrAlterOperationNotSupported returns when alter operations is not supported.
    ErrAlterOperationNotSupported = dbterror.ClassDDL.NewStd(mysql.ErrAlterOperationNotSupportedReason)
    // ErrWrongObject returns for wrong object.
    ErrWrongObject = dbterror.ClassDDL.NewStd(mysql.ErrWrongObject)
    // ErrTableCantHandleFt returns FULLTEXT keys are not supported by table type
    ErrTableCantHandleFt = dbterror.ClassDDL.NewStd(mysql.ErrTableCantHandleFt)
    // ErrFieldNotFoundPart returns an error when 'partition by columns' are not found in table columns.
    ErrFieldNotFoundPart = dbterror.ClassDDL.NewStd(mysql.ErrFieldNotFoundPart)
    // ErrWrongTypeColumnValue returns 'Partition column values of incorrect type'
    ErrWrongTypeColumnValue = dbterror.ClassDDL.NewStd(mysql.ErrWrongTypeColumnValue)
    // ErrValuesIsNotIntType returns 'VALUES value for partition '%-.64s' must have type INT'
    ErrValuesIsNotIntType = dbterror.ClassDDL.NewStd(mysql.ErrValuesIsNotIntType)
    // ErrFunctionalIndexPrimaryKey returns 'The primary key cannot be a functional index'
    ErrFunctionalIndexPrimaryKey = dbterror.ClassDDL.NewStd(mysql.ErrFunctionalIndexPrimaryKey)
    // ErrFunctionalIndexOnField returns 'Functional index on a column is not supported. Consider using a regular index instead'
    ErrFunctionalIndexOnField = dbterror.ClassDDL.NewStd(mysql.ErrFunctionalIndexOnField)
    // ErrInvalidAutoRandom returns when auto_random is used incorrectly.
    ErrInvalidAutoRandom = dbterror.ClassDDL.NewStd(mysql.ErrInvalidAutoRandom)
    // ErrUnsupportedConstraintCheck returns when use ADD CONSTRAINT CHECK
    ErrUnsupportedConstraintCheck = dbterror.ClassDDL.NewStd(mysql.ErrUnsupportedConstraintCheck)
    // ErrDerivedMustHaveAlias returns when a sub select statement does not have a table alias.
    ErrDerivedMustHaveAlias = dbterror.ClassDDL.NewStd(mysql.ErrDerivedMustHaveAlias)

    // ErrSequenceRunOut returns when the sequence has been run out.
    ErrSequenceRunOut = dbterror.ClassDDL.NewStd(mysql.ErrSequenceRunOut)
    // ErrSequenceInvalidData returns when sequence values are conflicting.
    ErrSequenceInvalidData = dbterror.ClassDDL.NewStd(mysql.ErrSequenceInvalidData)
    // ErrSequenceAccessFail returns when sequences are not able to access.
    ErrSequenceAccessFail = dbterror.ClassDDL.NewStd(mysql.ErrSequenceAccessFail)
    // ErrNotSequence returns when object is not a sequence.
    ErrNotSequence = dbterror.ClassDDL.NewStd(mysql.ErrNotSequence)
    // ErrUnknownSequence returns when drop / alter unknown sequence.
    ErrUnknownSequence = dbterror.ClassDDL.NewStd(mysql.ErrUnknownSequence)
    // ErrSequenceUnsupportedTableOption returns when unsupported table option exists in sequence.
    ErrSequenceUnsupportedTableOption = dbterror.ClassDDL.NewStd(mysql.ErrSequenceUnsupportedTableOption)
    // ErrColumnTypeUnsupportedNextValue is returned when sequence next value is assigned to unsupported column type.
    ErrColumnTypeUnsupportedNextValue = dbterror.ClassDDL.NewStd(mysql.ErrColumnTypeUnsupportedNextValue)
    // ErrAddColumnWithSequenceAsDefault is returned when the new added column with sequence's nextval as it's default value.
    ErrAddColumnWithSequenceAsDefault = dbterror.ClassDDL.NewStd(mysql.ErrAddColumnWithSequenceAsDefault)
    // ErrUnsupportedExpressionIndex is returned when create an expression index without allow-expression-index.
    ErrUnsupportedExpressionIndex = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message(fmt.Sprintf(mysql.MySQLErrName[mysql.ErrUnsupportedDDLOperation].Raw, "creating expression index without allow-expression-index in config"), nil))
    // ErrPartitionExchangePartTable is returned when exchange table partition with another table is partitioned.
    ErrPartitionExchangePartTable = dbterror.ClassDDL.NewStd(mysql.ErrPartitionExchangePartTable)
    // ErrTablesDifferentMetadata is returned when exchanges tables is not compatible.
    ErrTablesDifferentMetadata = dbterror.ClassDDL.NewStd(mysql.ErrTablesDifferentMetadata)
    // ErrRowDoesNotMatchPartition is returned when the row record of exchange table does not match the partition rule.
    ErrRowDoesNotMatchPartition = dbterror.ClassDDL.NewStd(mysql.ErrRowDoesNotMatchPartition)
    // ErrPartitionExchangeForeignKey is returned when exchanged normal table has foreign keys.
    ErrPartitionExchangeForeignKey = dbterror.ClassDDL.NewStd(mysql.ErrPartitionExchangeForeignKey)
    // ErrCheckNoSuchTable is returned when exchanged normal table is view or sequence.
    ErrCheckNoSuchTable = dbterror.ClassDDL.NewStd(mysql.ErrCheckNoSuchTable)

    // ErrPartitionExchangeDifferentOption is returned when attribute does not match between partition table and normal table.
    ErrPartitionExchangeDifferentOption = dbterror.ClassDDL.NewStd(mysql.ErrPartitionExchangeDifferentOption)
    // ErrTableOptionUnionUnsupported is returned when create/alter table with union option.
    ErrTableOptionUnionUnsupported = dbterror.ClassDDL.NewStd(mysql.ErrTableOptionUnionUnsupported)
    // ErrTableOptionInsertMethodUnsupported is returned when create/alter table with insert method option.
    ErrTableOptionInsertMethodUnsupported = dbterror.ClassDDL.NewStd(mysql.ErrTableOptionInsertMethodUnsupported)

    // ErrInvalidPlacementSpec is returned when add/alter an invalid placement rule
    ErrInvalidPlacementSpec = dbterror.ClassDDL.NewStd(mysql.ErrInvalidPlacementSpec)

    // ErrInvalidPlacementPolicyCheck is returned when txn_scope and commit data changing do not meet the placement policy
    ErrInvalidPlacementPolicyCheck = dbterror.ClassDDL.NewStd(mysql.ErrPlacementPolicyCheck)

    // ErrMultipleDefConstInListPart returns multiple definition of same constant in list partitioning.
    ErrMultipleDefConstInListPart = dbterror.ClassDDL.NewStd(mysql.ErrMultipleDefConstInListPart)

    // ErrTruncatedWrongValue is returned when data has been truncated during conversion.
    ErrTruncatedWrongValue = dbterror.ClassDDL.NewStd(mysql.ErrTruncatedWrongValue)

    // ErrWarnDataOutOfRange is returned when the value in a numeric column that is outside the permissible range of the column data type.
    // See https://dev.mysql.com/doc/refman/5.5/en/out-of-range-and-overflow.html for details
    ErrWarnDataOutOfRange = dbterror.ClassDDL.NewStd(mysql.ErrWarnDataOutOfRange)

    // ErrTooLongValueForType is returned when the individual enum element length is too long.
    ErrTooLongValueForType = dbterror.ClassDDL.NewStd(mysql.ErrTooLongValueForType)

    // ErrUnknownEngine is returned when the table engine is unknown.
    ErrUnknownEngine = dbterror.ClassDDL.NewStd(mysql.ErrUnknownStorageEngine)
var ReorgWaitTimeout = 5 * time.Second

ReorgWaitTimeout is the timeout that wait ddl in write reorganization stage.

var (
    // RunInGoTest is used to identify whether ddl in running in the test.
    RunInGoTest bool

func BuildElements Uses

func BuildElements(changingCol *model.ColumnInfo, changingIdxs []*model.IndexInfo) []*meta.Element

BuildElements is exported for testing.

func BuildTableInfoFromAST Uses

func BuildTableInfoFromAST(s *ast.CreateTableStmt) (*model.TableInfo, error)

BuildTableInfoFromAST builds model.TableInfo from a SQL statement. Note: TableID and PartitionID are left as uninitialized value.

func CheckModifyTypeCompatible Uses

func CheckModifyTypeCompatible(origin *types.FieldType, to *types.FieldType) (canReorg bool, errMsg string, err error)

CheckModifyTypeCompatible checks whether changes column type to another is compatible and can be changed. If types are compatible and can be directly changed, nil err will be returned; otherwise the types are incompatible. There are two cases when types incompatible: 1. returned canReorg == true: types can be changed by reorg 2. returned canReorg == false: type change not supported yet

func EmulatorGCDisable Uses

func EmulatorGCDisable()

EmulatorGCDisable disables emulator gc. It exports for testing.

func EmulatorGCEnable Uses

func EmulatorGCEnable()

EmulatorGCEnable enables emulator gc. It exports for testing.

func GetWaitTimeWhenErrorOccurred Uses

func GetWaitTimeWhenErrorOccurred() time.Duration

GetWaitTimeWhenErrorOccurred return waiting interval when processing DDL jobs encounter errors.

func IsAutoRandomColumnID Uses

func IsAutoRandomColumnID(tblInfo *model.TableInfo, colID int64) bool

IsAutoRandomColumnID returns true if the given column ID belongs to an auto_random column.

func IsEmulatorGCEnable Uses

func IsEmulatorGCEnable() bool

IsEmulatorGCEnable indicates whether emulator GC enabled. It exports for testing.

func IsTooBigFieldLength Uses

func IsTooBigFieldLength(colDefTpFlen int, colDefName, setCharset string) error

IsTooBigFieldLength check if the varchar type column exceeds the maximum length limit.

func MockTableInfo Uses

func MockTableInfo(ctx sessionctx.Context, stmt *ast.CreateTableStmt, tableID int64) (*model.TableInfo, error)

MockTableInfo mocks a table info by create table stmt ast and a specified table id.

func NewMockSchemaSyncer Uses

func NewMockSchemaSyncer() util.SchemaSyncer

NewMockSchemaSyncer creates a new mock SchemaSyncer.

func OverwriteCollationWithBinaryFlag Uses

func OverwriteCollationWithBinaryFlag(colDef *ast.ColumnDef, chs, coll string) (newChs string, newColl string)

OverwriteCollationWithBinaryFlag is used to handle the case like

CREATE TABLE t (a VARCHAR(255) BINARY) CHARSET utf8 COLLATE utf8_general_ci;

The 'BINARY' sets the column collation to *_bin according to the table charset.

func ResolveAlterAlgorithm Uses

func ResolveAlterAlgorithm(alterSpec *ast.AlterTableSpec, specify ast.AlgorithmType) (ast.AlgorithmType, error)

ResolveAlterAlgorithm resolves the algorithm of the alterSpec. If specify is the ast.AlterAlgorithmDefault, then the default algorithm of the alter action will be returned. If specify algorithm is not supported by the alter action, it will try to find a better algorithm in the order `INSTANT > INPLACE > COPY`, errAlterOperationNotSupported will be returned. E.g. INSTANT may be returned if specify=INPLACE If failed to choose any valid algorithm, AlgorithmTypeDefault and errAlterOperationNotSupported will be returned

func ResolveCharsetCollation Uses

func ResolveCharsetCollation(charsetOpts ...ast.CharsetOpt) (string, string, error)

ResolveCharsetCollation will resolve the charset and collate by the order of parameters: * If any given ast.CharsetOpt is not empty, the resolved charset and collate will be returned. * If all ast.CharsetOpts are empty, the default charset and collate will be returned.

func SetWaitTimeWhenErrorOccurred Uses

func SetWaitTimeWhenErrorOccurred(dur time.Duration)

SetWaitTimeWhenErrorOccurred update waiting interval when processing DDL jobs encounter errors.

type AlterAlgorithm Uses

type AlterAlgorithm struct {
    // contains filtered or unexported fields

AlterAlgorithm is used to store supported alter algorithm. For now, TiDB only support AlterAlgorithmInplace and AlterAlgorithmInstant. The most alter operations are using instant algorithm, and only the add index is using inplace(not really inplace, because we never block the DML but costs some time to backfill the index data) See https://dev.mysql.com/doc/refman/8.0/en/alter-table.html#alter-table-performance.

type BaseCallback Uses

type BaseCallback struct {

BaseCallback implements Callback.OnChanged interface.

func (*BaseCallback) OnChanged Uses

func (c *BaseCallback) OnChanged(err error) error

OnChanged implements Callback interface.

func (*BaseCallback) OnJobRunBefore Uses

func (c *BaseCallback) OnJobRunBefore(job *model.Job)

OnJobRunBefore implements Callback.OnJobRunBefore interface.

func (*BaseCallback) OnJobUpdated Uses

func (c *BaseCallback) OnJobUpdated(job *model.Job)

OnJobUpdated implements Callback.OnJobUpdated interface.

func (*BaseCallback) OnSchemaStateChanged Uses

func (c *BaseCallback) OnSchemaStateChanged()

OnSchemaStateChanged implements Callback interface.

func (*BaseCallback) OnWatched Uses

func (c *BaseCallback) OnWatched(ctx context.Context)

OnWatched implements Callback.OnWatched interface.

type BaseInterceptor Uses

type BaseInterceptor struct{}

BaseInterceptor implements Interceptor.

func (*BaseInterceptor) OnGetInfoSchema Uses

func (bi *BaseInterceptor) OnGetInfoSchema(ctx sessionctx.Context, is infoschema.InfoSchema) infoschema.InfoSchema

OnGetInfoSchema implements Interceptor.OnGetInfoSchema interface.

type Callback Uses

type Callback interface {
    // OnChanged is called after a ddl statement is finished.
    OnChanged(err error) error
    // OnSchemaStateChange is called after a schema state is changed.
    // OnJobRunBefore is called before running job.
    OnJobRunBefore(job *model.Job)
    // OnJobUpdated is called after the running job is updated.
    OnJobUpdated(job *model.Job)
    // OnWatched is called after watching owner is completed.
    OnWatched(ctx context.Context)

Callback is used for DDL.

type DDL Uses

type DDL interface {
    CreateSchema(ctx sessionctx.Context, name model.CIStr, charsetInfo *ast.CharsetOpt) error
    AlterSchema(ctx sessionctx.Context, stmt *ast.AlterDatabaseStmt) error
    DropSchema(ctx sessionctx.Context, schema model.CIStr) error
    CreateTable(ctx sessionctx.Context, stmt *ast.CreateTableStmt) error
    CreateView(ctx sessionctx.Context, stmt *ast.CreateViewStmt) error
    DropTable(ctx sessionctx.Context, tableIdent ast.Ident) (err error)
    RecoverTable(ctx sessionctx.Context, recoverInfo *RecoverInfo) (err error)
    DropView(ctx sessionctx.Context, tableIdent ast.Ident) (err error)
    CreateIndex(ctx sessionctx.Context, tableIdent ast.Ident, keyType ast.IndexKeyType, indexName model.CIStr,
        columnNames []*ast.IndexPartSpecification, indexOption *ast.IndexOption, ifNotExists bool) error
    DropIndex(ctx sessionctx.Context, tableIdent ast.Ident, indexName model.CIStr, ifExists bool) error
    AlterTable(ctx sessionctx.Context, tableIdent ast.Ident, spec []*ast.AlterTableSpec) error
    TruncateTable(ctx sessionctx.Context, tableIdent ast.Ident) error
    RenameTable(ctx sessionctx.Context, oldTableIdent, newTableIdent ast.Ident, isAlterTable bool) error
    RenameTables(ctx sessionctx.Context, oldTableIdent, newTableIdent []ast.Ident, isAlterTable bool) error
    LockTables(ctx sessionctx.Context, stmt *ast.LockTablesStmt) error
    UnlockTables(ctx sessionctx.Context, lockedTables []model.TableLockTpInfo) error
    CleanupTableLock(ctx sessionctx.Context, tables []*ast.TableName) error
    UpdateTableReplicaInfo(ctx sessionctx.Context, physicalID int64, available bool) error
    RepairTable(ctx sessionctx.Context, table *ast.TableName, createStmt *ast.CreateTableStmt) error
    CreateSequence(ctx sessionctx.Context, stmt *ast.CreateSequenceStmt) error
    DropSequence(ctx sessionctx.Context, tableIdent ast.Ident, ifExists bool) (err error)
    AlterSequence(ctx sessionctx.Context, stmt *ast.AlterSequenceStmt) error

    // CreateSchemaWithInfo creates a database (schema) given its database info.
    // If `tryRetainID` is true, this method will try to keep the database ID specified in
    // the `info` rather than generating new ones. This is just a hint though, if the ID collides
    // with an existing database a new ID will always be used.
    // WARNING: the DDL owns the `info` after calling this function, and will modify its fields
    // in-place. If you want to keep using `info`, please call Clone() first.
        ctx sessionctx.Context,
        info *model.DBInfo,
        onExist OnExist,
        tryRetainID bool) error

    // CreateTableWithInfo creates a table, view or sequence given its table info.
    // If `tryRetainID` is true, this method will try to keep the table ID specified in the `info`
    // rather than generating new ones. This is just a hint though, if the ID collides with an
    // existing table a new ID will always be used.
    // WARNING: the DDL owns the `info` after calling this function, and will modify its fields
    // in-place. If you want to keep using `info`, please call Clone() first.
        ctx sessionctx.Context,
        schema model.CIStr,
        info *model.TableInfo,
        onExist OnExist,
        tryRetainID bool) error

    // Start campaigns the owner and starts workers.
    // ctxPool is used for the worker's delRangeManager and creates sessions.
    Start(ctxPool *pools.ResourcePool) error
    // GetLease returns current schema lease time.
    GetLease() time.Duration
    // Stats returns the DDL statistics.
    Stats(vars *variable.SessionVars) (map[string]interface{}, error)
    // GetScope gets the status variables scope.
    GetScope(status string) variable.ScopeFlag
    // Stop stops DDL worker.
    Stop() error
    // RegisterStatsHandle registers statistics handle and its corresponding event channel for ddl.
    // SchemaSyncer gets the schema syncer.
    SchemaSyncer() util.SchemaSyncer
    // OwnerManager gets the owner manager.
    OwnerManager() owner.Manager
    // GetID gets the ddl ID.
    GetID() string
    // GetTableMaxRowID gets the max row ID of a normal table or a partition.
    GetTableMaxHandle(startTS uint64, tbl table.PhysicalTable) (kv.Handle, bool, error)
    // SetBinlogClient sets the binlog client for DDL worker. It's exported for testing.
    // GetHook gets the hook. It's exported for testing.
    GetHook() Callback

DDL is responsible for updating schema in data store and maintaining in-memory InfoSchema cache.

func NewDDL Uses

func NewDDL(ctx context.Context, options ...Option) DDL

NewDDL creates a new DDL.

type Interceptor Uses

type Interceptor interface {
    // OnGetInfoSchema is an intercept which is called in the function ddl.GetInfoSchema(). It is used in the tests.
    OnGetInfoSchema(ctx sessionctx.Context, is infoschema.InfoSchema) infoschema.InfoSchema

Interceptor is used for DDL.

type MockSchemaSyncer Uses

type MockSchemaSyncer struct {
    // contains filtered or unexported fields

MockSchemaSyncer is a mock schema syncer, it is exported for tesing.

func (*MockSchemaSyncer) Close Uses

func (s *MockSchemaSyncer) Close()

Close implements SchemaSyncer.Close interface.

func (*MockSchemaSyncer) CloseSession Uses

func (s *MockSchemaSyncer) CloseSession()

CloseSession mockSession, it is exported for testing.

func (*MockSchemaSyncer) Done Uses

func (s *MockSchemaSyncer) Done() <-chan struct{}

Done implements SchemaSyncer.Done interface.

func (*MockSchemaSyncer) GlobalVersionCh Uses

func (s *MockSchemaSyncer) GlobalVersionCh() clientv3.WatchChan

GlobalVersionCh implements SchemaSyncer.GlobalVersionCh interface.

func (*MockSchemaSyncer) Init Uses

func (s *MockSchemaSyncer) Init(ctx context.Context) error

Init implements SchemaSyncer.Init interface.

func (*MockSchemaSyncer) MustGetGlobalVersion Uses

func (s *MockSchemaSyncer) MustGetGlobalVersion(ctx context.Context) (int64, error)

MustGetGlobalVersion implements SchemaSyncer.MustGetGlobalVersion interface.

func (*MockSchemaSyncer) NotifyCleanExpiredPaths Uses

func (s *MockSchemaSyncer) NotifyCleanExpiredPaths() bool

NotifyCleanExpiredPaths implements SchemaSyncer.NotifyCleanExpiredPaths interface.

func (*MockSchemaSyncer) OwnerCheckAllVersions Uses

func (s *MockSchemaSyncer) OwnerCheckAllVersions(ctx context.Context, latestVer int64) error

OwnerCheckAllVersions implements SchemaSyncer.OwnerCheckAllVersions interface.

func (*MockSchemaSyncer) OwnerUpdateGlobalVersion Uses

func (s *MockSchemaSyncer) OwnerUpdateGlobalVersion(ctx context.Context, version int64) error

OwnerUpdateGlobalVersion implements SchemaSyncer.OwnerUpdateGlobalVersion interface.

func (*MockSchemaSyncer) Restart Uses

func (s *MockSchemaSyncer) Restart(_ context.Context) error

Restart implements SchemaSyncer.Restart interface.

func (*MockSchemaSyncer) StartCleanWork Uses

func (s *MockSchemaSyncer) StartCleanWork()

StartCleanWork implements SchemaSyncer.StartCleanWork interface.

func (*MockSchemaSyncer) UpdateSelfVersion Uses

func (s *MockSchemaSyncer) UpdateSelfVersion(ctx context.Context, version int64) error

UpdateSelfVersion implements SchemaSyncer.UpdateSelfVersion interface.

func (*MockSchemaSyncer) WatchGlobalSchemaVer Uses

func (s *MockSchemaSyncer) WatchGlobalSchemaVer(context.Context)

WatchGlobalSchemaVer implements SchemaSyncer.WatchGlobalSchemaVer interface.

type OnExist Uses

type OnExist uint8

OnExist specifies what to do when a new object has a name collision.

const (
    // OnExistError throws an error on name collision.
    OnExistError OnExist = iota
    // OnExistIgnore skips creating the new object.
    // OnExistReplace replaces the old object by the new object. This is only
    // supported by VIEWs at the moment. For other object types, this is
    // equivalent to OnExistError.

type Option Uses

type Option func(*Options)

Option represents an option to initialize the DDL module

func WithEtcdClient Uses

func WithEtcdClient(client *clientv3.Client) Option

WithEtcdClient specifies the `clientv3.Client` of DDL used to request the etcd service

func WithHook Uses

func WithHook(callback Callback) Option

WithHook specifies the `Callback` of DDL used to notify the outer module when events are triggered

func WithInfoHandle Uses

func WithInfoHandle(ih *infoschema.Handle) Option

WithInfoHandle specifies the `infoschema.Handle`

func WithLease Uses

func WithLease(lease time.Duration) Option

WithLease specifies the schema lease duration

func WithStore Uses

func WithStore(store kv.Storage) Option

WithStore specifies the `kv.Storage` of DDL used to request the KV service

type Options Uses

type Options struct {
    EtcdCli    *clientv3.Client
    Store      kv.Storage
    InfoHandle *infoschema.Handle
    Hook       Callback
    Lease      time.Duration

Options represents all the options of the DDL module needs

type RecoverInfo Uses

type RecoverInfo struct {
    SchemaID      int64
    TableInfo     *model.TableInfo
    DropJobID     int64
    SnapshotTS    uint64
    CurAutoIncID  int64
    CurAutoRandID int64

RecoverInfo contains information needed by DDL.RecoverTable.



Package ddl imports 79 packages (graph) and is imported by 216 packages. Updated 2021-01-25. Refresh now. Tools for package owners.