Documentation ¶
Index ¶
- Constants
- Variables
- func NewMockSchemaSyncer() util.SchemaSyncer
- type AddIndexWorker
- type BaseCallback
- type BaseInterceptor
- type Callback
- type DDL
- type IndexTask
- type Interceptor
- type MockSchemaSyncer
- func (s *MockSchemaSyncer) CloseCleanWork()
- 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) RemoveSelfVersionPath() 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 Task
- type Worker
- type WorkerPool
Constants ¶
const (
// DDLOwnerKey is the ddl owner path that is saved to etcd, and it's exported for testing.
DDLOwnerKey = "/zetta-dev/ddl/fg/owner"
)
Variables ¶
var ( // RunWorker indicates if this TiDB server starts DDL worker and can run DDL job. RunWorker = true // WaitTimeWhenErrorOccured is waiting interval when processing DDL jobs encounter errors. WaitTimeWhenErrorOccured = 1 * time.Second )
var ( // ErrInvalidDefaultValue returns for invalid default value for columns. ErrInvalidDefaultValue = terror.ClassDDL.New(codeInvalidDefaultValue, mysql.MySQLErrName[mysql.ErrInvalidDefault]) // ErrGeneratedColumnRefAutoInc forbids to refer generated columns to auto-increment columns . ErrGeneratedColumnRefAutoInc = terror.ClassDDL.New(codeErrGeneratedColumnRefAutoInc, mysql.MySQLErrName[mysql.ErrGeneratedColumnRefAutoInc]) // ErrUnsupportedAddPartition returns for does not support add partitions. ErrUnsupportedAddPartition = terror.ClassDDL.New(codeUnsupportedAddPartition, "unsupported add partitions") // ErrUnsupportedCoalescePartition returns for does not support coalesce partitions. ErrUnsupportedCoalescePartition = terror.ClassDDL.New(codeUnsupportedCoalescePartition, "unsupported coalesce partitions") // ErrGeneratedColumnFunctionIsNotAllowed returns for unsupported functions for generated columns. ErrGeneratedColumnFunctionIsNotAllowed = terror.ClassDDL.New(codeErrGeneratedColumnFunctionIsNotAllowed, "Expression of generated column '%s' contains a disallowed function.") // ErrUnsupportedPartitionByRangeColumns returns for does unsupported partition by range columns. ErrUnsupportedPartitionByRangeColumns = terror.ClassDDL.New(codeUnsupportedPartitionByRangeColumns, "unsupported partition by range columns") // ErrDupKeyName returns for duplicated key name ErrDupKeyName = terror.ClassDDL.New(codeDupKeyName, "duplicate key name") // ErrInvalidDBState returns for invalid database state. ErrInvalidDBState = terror.ClassDDL.New(codeInvalidDBState, "invalid database state") // ErrInvalidTableState returns for invalid Table state. ErrInvalidTableState = terror.ClassDDL.New(codeInvalidTableState, "invalid table state") // ErrInvalidColumnState returns for invalid column state. ErrInvalidColumnState = terror.ClassDDL.New(codeInvalidColumnState, "invalid column state") // ErrInvalidIndexState returns for invalid index state. ErrInvalidIndexState = terror.ClassDDL.New(codeInvalidIndexState, "invalid index state") // ErrInvalidForeignKeyState returns for invalid foreign key state. ErrInvalidForeignKeyState = terror.ClassDDL.New(codeInvalidForeignKeyState, "invalid foreign key state") // ErrUnsupportedModifyPrimaryKey returns an error when add or drop the primary key. // It's exported for testing. ErrUnsupportedModifyPrimaryKey = terror.ClassDDL.New(codeUnsupportedModifyPrimaryKey, "unsupported %s primary key") // ErrColumnBadNull returns for a bad null value. ErrColumnBadNull = terror.ClassDDL.New(codeBadNull, "column cann't be null") // ErrBadField forbids to refer to unknown column. ErrBadField = terror.ClassDDL.New(codeBadField, "Unknown column '%s' in '%s'") // ErrCantRemoveAllFields returns for deleting all columns. ErrCantRemoveAllFields = terror.ClassDDL.New(codeCantRemoveAllFields, "can't delete all columns with ALTER TABLE") // ErrCantDropFieldOrKey returns for dropping a non-existent field or key. ErrCantDropFieldOrKey = terror.ClassDDL.New(codeCantDropFieldOrKey, "can't drop field; check that column/key exists") // ErrInvalidOnUpdate returns for invalid ON UPDATE clause. ErrInvalidOnUpdate = terror.ClassDDL.New(codeInvalidOnUpdate, mysql.MySQLErrName[mysql.ErrInvalidOnUpdate]) // ErrTooLongIdent returns for too long name of database/table/column/index. ErrTooLongIdent = terror.ClassDDL.New(codeTooLongIdent, mysql.MySQLErrName[mysql.ErrTooLongIdent]) // ErrWrongDBName returns for wrong database name. ErrWrongDBName = terror.ClassDDL.New(codeWrongDBName, mysql.MySQLErrName[mysql.ErrWrongDBName]) // ErrWrongTableName returns for wrong table name. ErrWrongTableName = terror.ClassDDL.New(codeWrongTableName, mysql.MySQLErrName[mysql.ErrWrongTableName]) // ErrWrongColumnName returns for wrong column name. ErrWrongColumnName = terror.ClassDDL.New(codeWrongColumnName, mysql.MySQLErrName[mysql.ErrWrongColumnName]) // ErrTableMustHaveColumns returns for missing column when creating a table. ErrTableMustHaveColumns = terror.ClassDDL.New(codeTableMustHaveColumns, mysql.MySQLErrName[mysql.ErrTableMustHaveColumns]) // ErrWrongNameForIndex returns for wrong index name. ErrWrongNameForIndex = terror.ClassDDL.New(codeWrongNameForIndex, mysql.MySQLErrName[mysql.ErrWrongNameForIndex]) // ErrUnknownCharacterSet returns unknown character set. ErrUnknownCharacterSet = terror.ClassDDL.New(codeUnknownCharacterSet, "Unknown character set: '%s'") // ErrUnknownCollation returns unknown collation. ErrUnknownCollation = terror.ClassDDL.New(codeUnknownCollation, "Unknown collation: '%s'") // ErrCollationCharsetMismatch returns when collation not match the charset. ErrCollationCharsetMismatch = terror.ClassDDL.New(codeCollationCharsetMismatch, mysql.MySQLErrName[mysql.ErrCollationCharsetMismatch]) // ErrConflictingDeclarations return conflict declarations. ErrConflictingDeclarations = terror.ClassDDL.New(codeConflictingDeclarations, "Conflicting declarations: 'CHARACTER SET %s' and 'CHARACTER SET %s'") // ErrPrimaryCantHaveNull returns All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead ErrPrimaryCantHaveNull = terror.ClassDDL.New(codePrimaryCantHaveNull, mysql.MySQLErrName[mysql.ErrPrimaryCantHaveNull]) // ErrNotAllowedTypeInPartition returns not allowed type error when creating table partiton with unsupport expression type. ErrNotAllowedTypeInPartition = terror.ClassDDL.New(codeErrFieldTypeNotAllowedAsPartitionField, mysql.MySQLErrName[mysql.ErrFieldTypeNotAllowedAsPartitionField]) // ErrPartitionMgmtOnNonpartitioned returns it's not a partition table. ErrPartitionMgmtOnNonpartitioned = terror.ClassDDL.New(codePartitionMgmtOnNonpartitioned, "Partition management on a not partitioned table is not possible") // ErrDropPartitionNonExistent returns error in list of partition. ErrDropPartitionNonExistent = terror.ClassDDL.New(codeDropPartitionNonExistent, " Error in list of partitions to %s") // ErrSameNamePartition returns duplicate partition name. ErrSameNamePartition = terror.ClassDDL.New(codeSameNamePartition, "Duplicate partition name %s") // ErrRangeNotIncreasing returns values less than value must be strictly increasing for each partition. ErrRangeNotIncreasing = terror.ClassDDL.New(codeRangeNotIncreasing, "VALUES LESS THAN value must be strictly increasing for each partition") // ErrPartitionMaxvalue returns maxvalue can only be used in last partition definition. ErrPartitionMaxvalue = terror.ClassDDL.New(codePartitionMaxvalue, "MAXVALUE can only be used in last partition definition") //ErrDropLastPartition returns cannot remove all partitions, use drop table instead. ErrDropLastPartition = terror.ClassDDL.New(codeDropLastPartition, mysql.MySQLErrName[mysql.ErrDropLastPartition]) //ErrTooManyPartitions returns too many partitions were defined. ErrTooManyPartitions = terror.ClassDDL.New(codeTooManyPartitions, mysql.MySQLErrName[mysql.ErrTooManyPartitions]) //ErrPartitionFunctionIsNotAllowed returns this partition function is not allowed. ErrPartitionFunctionIsNotAllowed = terror.ClassDDL.New(codePartitionFunctionIsNotAllowed, mysql.MySQLErrName[mysql.ErrPartitionFunctionIsNotAllowed]) // ErrPartitionFuncNotAllowed returns partition function returns the wrong type. ErrPartitionFuncNotAllowed = terror.ClassDDL.New(codeErrPartitionFuncNotAllowed, mysql.MySQLErrName[mysql.ErrPartitionFuncNotAllowed]) // ErrUniqueKeyNeedAllFieldsInPf returns must include all columns in the table's partitioning function. ErrUniqueKeyNeedAllFieldsInPf = terror.ClassDDL.New(codeUniqueKeyNeedAllFieldsInPf, mysql.MySQLErrName[mysql.ErrUniqueKeyNeedAllFieldsInPf]) // ErrWarnDataTruncated returns data truncated error. ErrWarnDataTruncated = terror.ClassDDL.New(codeWarnDataTruncated, mysql.MySQLErrName[mysql.WarnDataTruncated]) // ErrCoalesceOnlyOnHashPartition returns coalesce partition can only be used on hash/key partitions. ErrCoalesceOnlyOnHashPartition = terror.ClassDDL.New(codeCoalesceOnlyOnHashPartition, mysql.MySQLErrName[mysql.ErrCoalesceOnlyOnHashPartition]) // ErrViewWrongList returns create view must include all columns in the select clause ErrViewWrongList = terror.ClassDDL.New(codeViewWrongList, mysql.MySQLErrName[mysql.ErrViewWrongList]) // ErrAlterOperationNotSupported returns when alter operations is not supported. ErrAlterOperationNotSupported = terror.ClassDDL.New(codeNotSupportedAlterOperation, mysql.MySQLErrName[mysql.ErrAlterOperationNotSupportedReason]) // ErrWrongObject returns for wrong object. ErrWrongObject = terror.ClassDDL.New(codeErrWrongObject, mysql.MySQLErrName[mysql.ErrWrongObject]) // ErrTableCantHandleFt returns FULLTEXT keys are not supported by table type ErrTableCantHandleFt = terror.ClassDDL.New(codeErrTableCantHandleFt, mysql.MySQLErrName[mysql.ErrTableCantHandleFt]) // ErrFieldNotFoundPart returns an error when 'partition by columns' are not found in table columns. ErrFieldNotFoundPart = terror.ClassDDL.New(codeFieldNotFoundPart, mysql.MySQLErrName[mysql.ErrFieldNotFoundPart]) // ErrWrongTypeColumnValue returns 'Partition column values of incorrect type' ErrWrongTypeColumnValue = terror.ClassDDL.New(codeWrongTypeColumnValue, mysql.MySQLErrName[mysql.ErrWrongTypeColumnValue]) )
var ReorgWaitTimeout = 5 * time.Second
ReorgWaitTimeout is the timeout that wait ddl in write reorganization stage.
Functions ¶
func NewMockSchemaSyncer ¶
func NewMockSchemaSyncer() util.SchemaSyncer
NewMockSchemaSyncer creates a new mock SchemaSyncer.
Types ¶
type AddIndexWorker ¶
type AddIndexWorker struct {
// contains filtered or unexported fields
}
func (*AddIndexWorker) CleanError ¶
func (a *AddIndexWorker) CleanError()
func (*AddIndexWorker) GetError ¶
func (a *AddIndexWorker) GetError() error
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) 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 schema is changed. OnChanged(err error) error // 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, dbmeta *model.DatabaseMeta) error CreateTable(ctx sessionctx.Context, tbmeta *model.TableMeta, isexists bool) error DropTable(ctx sessionctx.Context, db, table string, ifexists bool) error CreateIndex(ctx sessionctx.Context, db, table string, indexMeta *model.IndexMeta, ifNotExists bool) error //AddColumn(ctx sessionctx.Context, req *tspb.AddColumnRequest) error AddColumn(ctx sessionctx.Context, dbName, tblName string, cols []*model.ColumnMeta) error SchemaSyncer() util.SchemaSyncer GetID() string Stop() error IsOwner() bool }
DDL is responsible for updating schema in data store and maintaining in-memory InfoSchema cache.
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) CloseCleanWork ¶
func (s *MockSchemaSyncer) CloseCleanWork()
CloseCleanWork implements SchemaSyncer.CloseCleanWork 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) RemoveSelfVersionPath ¶
func (s *MockSchemaSyncer) RemoveSelfVersionPath() error
RemoveSelfVersionPath implements SchemaSyncer.RemoveSelfVersionPath 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 WorkerPool ¶
type WorkerPool struct {
// contains filtered or unexported fields
}
func NewWorkerPool ¶
func NewWorkerPool() *WorkerPool
func (*WorkerPool) AddTask ¶
func (p *WorkerPool) AddTask(t Task)
func (*WorkerPool) AddWorkers ¶
func (p *WorkerPool) AddWorkers(w Worker) error
func (*WorkerPool) Reset ¶
func (p *WorkerPool) Reset()
func (*WorkerPool) Run ¶
func (p *WorkerPool) Run() (bool, error)
Return whether to continue or not.