Documentation
¶
Index ¶
- Constants
- Variables
- func BuildElements(changingCol *model.ColumnInfo, changingIdxs []*model.IndexInfo) []*meta.Element
- func BuildSessionTemporaryTableInfo(ctx sessionctx.Context, is infoschema.InfoSchema, s *ast.CreateTableStmt, ...) (*model.TableInfo, error)
- func BuildTableInfoFromAST(s *ast.CreateTableStmt) (*model.TableInfo, error)
- func CheckModifyTypeCompatible(origin *types.FieldType, to *types.FieldType) (canReorg bool, err error)
- func EmulatorGCDisable()
- func EmulatorGCEnable()
- func GetCustomizedHook(s string) (func(do DomainReloader) Callback, error)
- func GetWaitTimeWhenErrorOccurred() time.Duration
- func IsAutoRandomColumnID(tblInfo *model.TableInfo, colID int64) bool
- func IsEmulatorGCEnable() bool
- func IsTooBigFieldLength(colDefTpFlen int, colDefName, setCharset string) error
- func MockTableInfo(ctx sessionctx.Context, stmt *ast.CreateTableStmt, tableID int64) (*model.TableInfo, error)
- func NewMockSchemaSyncer() util.SchemaSyncer
- func OverwriteCollationWithBinaryFlag(colDef *ast.ColumnDef, chs, coll string) (newChs string, newColl string)
- func ResolveAlterAlgorithm(alterSpec *ast.AlterTableSpec, specify ast.AlgorithmType) (ast.AlgorithmType, error)
- func ResolveCharsetCollation(charsetOpts ...ast.CharsetOpt) (string, string, error)
- func SetDirectPlacementOpt(placementSettings *model.PlacementSettings, ...) error
- func SetWaitTimeWhenErrorOccurred(dur time.Duration)
- func ShouldBuildClusteredIndex(ctx sessionctx.Context, opt *ast.IndexOption, isSingleIntPK bool) bool
- type AlterAlgorithm
- type BaseCallback
- type BaseInterceptor
- type Callback
- type DDL
- type DefaultCallback
- type DomainReloader
- type Interceptor
- type MockSchemaSyncer
- func (s *MockSchemaSyncer) Close()
- func (s *MockSchemaSyncer) CloseSession()
- func (s *MockSchemaSyncer) Done() <-chan struct{}
- func (s *MockSchemaSyncer) GlobalVersionCh() clientv3.WatchChan
- func (s *MockSchemaSyncer) Init(ctx context.Context) error
- func (s *MockSchemaSyncer) MustGetGlobalVersion(ctx context.Context) (int64, error)
- func (s *MockSchemaSyncer) NotifyCleanExpiredPaths() bool
- func (s *MockSchemaSyncer) OwnerCheckAllVersions(ctx context.Context, latestVer int64) error
- func (s *MockSchemaSyncer) OwnerUpdateGlobalVersion(ctx context.Context, version int64) error
- func (s *MockSchemaSyncer) Restart(_ context.Context) error
- func (s *MockSchemaSyncer) StartCleanWork()
- func (s *MockSchemaSyncer) UpdateSelfVersion(ctx context.Context, version int64) error
- func (s *MockSchemaSyncer) WatchGlobalSchemaVer(context.Context)
- type OnExist
- type Option
- type Options
- type RecoverInfo
Constants ¶
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
)
Variables ¶
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 ( // 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) // ErrFkDupName returns for duplicated FK name. ErrFkDupName = dbterror.ClassDDL.NewStd(mysql.ErrFkDupName) // ErrInvalidDDLState returns for invalid ddl model object state. ErrInvalidDDLState = dbterror.ClassDDL.NewStdErr(mysql.ErrInvalidDDLState, parser_mysql.Message(fmt.Sprintf("%s", 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) // ErrPartitionConstDomain returns partition constant is out of partition function domain. ErrPartitionConstDomain = dbterror.ClassDDL.NewStd(mysql.ErrPartitionConstDomain) // 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 containing unsafe functions 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) // ErrPlacementPolicyWithDirectOption is returned when create/alter table with both placement policy and placement options existed. ErrPlacementPolicyWithDirectOption = dbterror.ClassDDL.NewStd(mysql.ErrPlacementPolicyWithDirectOption) // ErrPlacementPolicyInUse is returned when placement policy is in use in drop/alter. ErrPlacementPolicyInUse = dbterror.ClassDDL.NewStd(mysql.ErrPlacementPolicyInUse) // ErrPlacementDisabled is returned when tidb_enable_alter_placement = 0 ErrPlacementDisabled = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message("Alter Placement Rule is disabled, please set 'tidb_enable_alter_placement' if you need to enable it", nil)) // 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) // ErrPartitionNoTemporary returns when partition at temporary mode ErrPartitionNoTemporary = dbterror.ClassDDL.NewStd(mysql.ErrPartitionNoTemporary) // ErrOptOnTemporaryTable returns when exec unsupported opt at temporary mode ErrOptOnTemporaryTable = dbterror.ClassDDL.NewStd(mysql.ErrOptOnTemporaryTable) // ErrOptOnCacheTable returns when exec unsupported opt at cache mode ErrOptOnCacheTable = dbterror.ClassDDL.NewStd(mysql.ErrOptOnCacheTable) // ErrUnsupportedLocalTempTableDDL returns when ddl operation unsupported for local temporary table ErrUnsupportedLocalTempTableDDL = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message("TiDB doesn't support %s for local temporary table", nil)) // ErrInvalidAttributesSpec is returned when meeting invalid attributes. ErrInvalidAttributesSpec = dbterror.ClassDDL.NewStd(mysql.ErrInvalidAttributesSpec) )
var ( // 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 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 )
var TestReorgGoroutineRunning = make(chan interface{})
TestReorgGoroutineRunning is only used in test to indicate the reorg goroutine has been started.
Functions ¶
func BuildElements ¶
BuildElements is exported for testing.
func BuildSessionTemporaryTableInfo ¶
func BuildSessionTemporaryTableInfo(ctx sessionctx.Context, is infoschema.InfoSchema, s *ast.CreateTableStmt, dbCharset, dbCollate string, placementPolicyRef *model.PolicyRefInfo, directPlacementOpts *model.PlacementSettings) (*model.TableInfo, error)
BuildSessionTemporaryTableInfo builds model.TableInfo from a SQL statement.
func BuildTableInfoFromAST ¶
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 ¶
func CheckModifyTypeCompatible(origin *types.FieldType, to *types.FieldType) (canReorg bool, 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 ¶
func EmulatorGCDisable()
EmulatorGCDisable disables emulator gc. It exports for testing.
func EmulatorGCEnable ¶
func EmulatorGCEnable()
EmulatorGCEnable enables emulator gc. It exports for testing.
func GetCustomizedHook ¶
func GetCustomizedHook(s string) (func(do DomainReloader) Callback, error)
GetCustomizedHook get the hook registered in the hookMap.
func GetWaitTimeWhenErrorOccurred ¶
GetWaitTimeWhenErrorOccurred return waiting interval when processing DDL jobs encounter errors.
func IsAutoRandomColumnID ¶
IsAutoRandomColumnID returns true if the given column ID belongs to an auto_random column.
func IsEmulatorGCEnable ¶
func IsEmulatorGCEnable() bool
IsEmulatorGCEnable indicates whether emulator GC enabled. It exports for testing.
func IsTooBigFieldLength ¶
IsTooBigFieldLength check if the varchar type column exceeds the maximum length limit.
func MockTableInfo ¶
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 ¶
func NewMockSchemaSyncer() util.SchemaSyncer
NewMockSchemaSyncer creates a new mock SchemaSyncer.
func OverwriteCollationWithBinaryFlag ¶
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 ¶
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 ¶
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 SetDirectPlacementOpt ¶
func SetDirectPlacementOpt(placementSettings *model.PlacementSettings, placementOptionType ast.PlacementOptionType, stringVal string, uintVal uint64) error
SetDirectPlacementOpt tries to make the PlacementSettings assignments generic for Schema/Table/Partition
func SetWaitTimeWhenErrorOccurred ¶
SetWaitTimeWhenErrorOccurred update waiting interval when processing DDL jobs encounter errors.
func ShouldBuildClusteredIndex ¶
func ShouldBuildClusteredIndex(ctx sessionctx.Context, opt *ast.IndexOption, isSingleIntPK bool) bool
ShouldBuildClusteredIndex is used to determine whether the CREATE TABLE statement should build a clustered index table.
Types ¶
type AlterAlgorithm ¶
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 ¶
type BaseCallback struct {
}
BaseCallback implements Callback.OnChanged interface.
func (*BaseCallback) OnChanged ¶
func (c *BaseCallback) OnChanged(err error) error
OnChanged implements Callback interface.
func (*BaseCallback) OnJobRunBefore ¶
func (c *BaseCallback) OnJobRunBefore(job *model.Job)
OnJobRunBefore implements Callback.OnJobRunBefore interface.
func (*BaseCallback) OnJobUpdated ¶
func (c *BaseCallback) OnJobUpdated(job *model.Job)
OnJobUpdated implements Callback.OnJobUpdated interface.
func (*BaseCallback) OnSchemaStateChanged ¶
func (c *BaseCallback) OnSchemaStateChanged()
OnSchemaStateChanged implements Callback interface.
func (*BaseCallback) OnWatched ¶
func (c *BaseCallback) OnWatched(ctx context.Context)
OnWatched implements Callback.OnWatched interface.
type BaseInterceptor ¶
type BaseInterceptor struct{}
BaseInterceptor implements Interceptor.
func (*BaseInterceptor) OnGetInfoSchema ¶
func (bi *BaseInterceptor) OnGetInfoSchema(ctx sessionctx.Context, is infoschema.InfoSchema) infoschema.InfoSchema
OnGetInfoSchema implements Interceptor.OnGetInfoSchema interface.
type Callback ¶
type Callback interface {
// OnChanged is called after a ddl statement is finished.
OnChanged(err error) error
// OnSchemaStateChanged is called after a schema state is changed.
OnSchemaStateChanged()
// 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 ¶
type DDL interface {
CreateSchema(ctx sessionctx.Context, schema model.CIStr, charsetInfo *ast.CharsetOpt, directPlacementOpts *model.PlacementSettings, placementPolicyRef *model.PolicyRefInfo) 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 context.Context, sctx 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
CreatePlacementPolicy(ctx sessionctx.Context, stmt *ast.CreatePlacementPolicyStmt) error
DropPlacementPolicy(ctx sessionctx.Context, stmt *ast.DropPlacementPolicyStmt) error
AlterPlacementPolicy(ctx sessionctx.Context, stmt *ast.AlterPlacementPolicyStmt) 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.
CreateSchemaWithInfo(
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.
CreateTableWithInfo(
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.
RegisterStatsHandle(*handle.Handle)
// SchemaSyncer gets the schema syncer.
SchemaSyncer() util.SchemaSyncer
// OwnerManager gets the owner manager.
OwnerManager() owner.Manager
// GetID gets the ddl ID.
GetID() string
// GetTableMaxHandle 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.
SetBinlogClient(*pumpcli.PumpsClient)
// GetHook gets the hook. It's exported for testing.
GetHook() Callback
// SetHook sets the hook.
SetHook(h Callback)
}
DDL is responsible for updating schema in data store and maintaining in-memory InfoSchema cache.
type DefaultCallback ¶
type DefaultCallback struct {
*BaseCallback
// contains filtered or unexported fields
}
DefaultCallback is the default callback that TiDB will use.
func (*DefaultCallback) OnChanged ¶
func (c *DefaultCallback) OnChanged(err error) error
OnChanged overrides ddl Callback interface.
func (*DefaultCallback) OnSchemaStateChanged ¶
func (c *DefaultCallback) OnSchemaStateChanged()
OnSchemaStateChanged overrides the ddl Callback interface.
type DomainReloader ¶
type DomainReloader interface {
Reload() error
}
DomainReloader is used to avoid import loop.
type Interceptor ¶
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 ¶
type MockSchemaSyncer struct {
// contains filtered or unexported fields
}
MockSchemaSyncer is a mock schema syncer, it is exported for tesing.
func (*MockSchemaSyncer) Close ¶
func (s *MockSchemaSyncer) Close()
Close implements SchemaSyncer.Close interface.
func (*MockSchemaSyncer) CloseSession ¶
func (s *MockSchemaSyncer) CloseSession()
CloseSession mockSession, it is exported for testing.
func (*MockSchemaSyncer) Done ¶
func (s *MockSchemaSyncer) Done() <-chan struct{}
Done implements SchemaSyncer.Done interface.
func (*MockSchemaSyncer) GlobalVersionCh ¶
func (s *MockSchemaSyncer) GlobalVersionCh() clientv3.WatchChan
GlobalVersionCh implements SchemaSyncer.GlobalVersionCh interface.
func (*MockSchemaSyncer) Init ¶
func (s *MockSchemaSyncer) Init(ctx context.Context) error
Init implements SchemaSyncer.Init interface.
func (*MockSchemaSyncer) MustGetGlobalVersion ¶
func (s *MockSchemaSyncer) MustGetGlobalVersion(ctx context.Context) (int64, error)
MustGetGlobalVersion implements SchemaSyncer.MustGetGlobalVersion interface.
func (*MockSchemaSyncer) NotifyCleanExpiredPaths ¶
func (s *MockSchemaSyncer) NotifyCleanExpiredPaths() bool
NotifyCleanExpiredPaths implements SchemaSyncer.NotifyCleanExpiredPaths interface.
func (*MockSchemaSyncer) OwnerCheckAllVersions ¶
func (s *MockSchemaSyncer) OwnerCheckAllVersions(ctx context.Context, latestVer int64) error
OwnerCheckAllVersions implements SchemaSyncer.OwnerCheckAllVersions interface.
func (*MockSchemaSyncer) OwnerUpdateGlobalVersion ¶
func (s *MockSchemaSyncer) OwnerUpdateGlobalVersion(ctx context.Context, version int64) error
OwnerUpdateGlobalVersion implements SchemaSyncer.OwnerUpdateGlobalVersion interface.
func (*MockSchemaSyncer) Restart ¶
func (s *MockSchemaSyncer) Restart(_ context.Context) error
Restart implements SchemaSyncer.Restart interface.
func (*MockSchemaSyncer) StartCleanWork ¶
func (s *MockSchemaSyncer) StartCleanWork()
StartCleanWork implements SchemaSyncer.StartCleanWork interface.
func (*MockSchemaSyncer) UpdateSelfVersion ¶
func (s *MockSchemaSyncer) UpdateSelfVersion(ctx context.Context, version int64) error
UpdateSelfVersion implements SchemaSyncer.UpdateSelfVersion interface.
func (*MockSchemaSyncer) WatchGlobalSchemaVer ¶
func (s *MockSchemaSyncer) WatchGlobalSchemaVer(context.Context)
WatchGlobalSchemaVer implements SchemaSyncer.WatchGlobalSchemaVer interface.
type OnExist ¶
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. OnExistIgnore // 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. OnExistReplace )
type Option ¶
type Option func(*Options)
Option represents an option to initialize the DDL module
func WithEtcdClient ¶
WithEtcdClient specifies the `clientv3.Client` of DDL used to request the etcd service
func WithHook ¶
WithHook specifies the `Callback` of DDL used to notify the outer module when events are triggered
func WithInfoCache ¶
func WithInfoCache(ic *infoschema.InfoCache) Option
WithInfoCache specifies the `infoschema.InfoCache`