schematracker

package
v1.1.0-beta.0...-0ffac36 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ConstructResultOfShowCreateDatabase should be assigned to executor.ConstructResultOfShowCreateDatabase.
	// It is used to break cycle import.
	ConstructResultOfShowCreateDatabase func(sessionctx.Context, *model.DBInfo, bool, *bytes.Buffer) error
	// ConstructResultOfShowCreateTable should be assigned to executor.ConstructResultOfShowCreateTable.
	// It is used to break cycle import.
	ConstructResultOfShowCreateTable func(sessionctx.Context, *model.TableInfo, autoid.Allocators, *bytes.Buffer) error
)

Functions

func NewStorageDDLInjector

func NewStorageDDLInjector(s kv.Storage) kv.Storage

NewStorageDDLInjector creates a new StorageDDLInjector to inject Checker.

func UnwrapStorage

func UnwrapStorage(s kv.Storage) kv.Storage

UnwrapStorage unwraps StorageDDLInjector for one level.

Types

type Checker

type Checker struct {
	// contains filtered or unexported fields
}

Checker is used to check the result of SchemaTracker is same as real DDL.

func NewChecker

func NewChecker(realDDL ddl.DDL, realExecutor ddl.Executor, infoCache *infoschema.InfoCache) *Checker

NewChecker creates a Checker.

func (*Checker) AddResourceGroup

func (*Checker) AddResourceGroup(_ sessionctx.Context, _ *ast.CreateResourceGroupStmt) error

AddResourceGroup implements the DDL interface. ResourceGroup do not affect the transaction.

func (*Checker) AlterPlacementPolicy

func (*Checker) AlterPlacementPolicy(_ sessionctx.Context, _ *ast.AlterPlacementPolicyStmt) error

AlterPlacementPolicy implements the DDL interface.

func (*Checker) AlterResourceGroup

func (*Checker) AlterResourceGroup(_ sessionctx.Context, _ *ast.AlterResourceGroupStmt) error

AlterResourceGroup implements the DDL interface.

func (*Checker) AlterSchema

func (d *Checker) AlterSchema(sctx sessionctx.Context, stmt *ast.AlterDatabaseStmt) error

AlterSchema implements the DDL interface.

func (*Checker) AlterSequence

func (*Checker) AlterSequence(_ sessionctx.Context, _ *ast.AlterSequenceStmt) error

AlterSequence implements the DDL interface.

func (*Checker) AlterTable

func (d *Checker) AlterTable(ctx context.Context, sctx sessionctx.Context, stmt *ast.AlterTableStmt) error

AlterTable implements the DDL interface.

func (*Checker) BatchCreateTableWithInfo

func (*Checker) BatchCreateTableWithInfo(_ sessionctx.Context, _ pmodel.CIStr, _ []*model.TableInfo, _ ...ddl.CreateTableOption) error

BatchCreateTableWithInfo implements the DDL interface.

func (*Checker) CleanupTableLock

func (d *Checker) CleanupTableLock(ctx sessionctx.Context, tables []*ast.TableName) error

CleanupTableLock implements the DDL interface.

func (*Checker) CreateIndex

func (d *Checker) CreateIndex(ctx sessionctx.Context, stmt *ast.CreateIndexStmt) error

CreateIndex implements the DDL interface.

func (*Checker) CreatePlacementPolicy

func (*Checker) CreatePlacementPolicy(_ sessionctx.Context, _ *ast.CreatePlacementPolicyStmt) error

CreatePlacementPolicy implements the DDL interface.

func (*Checker) CreatePlacementPolicyWithInfo

func (*Checker) CreatePlacementPolicyWithInfo(_ sessionctx.Context, _ *model.PolicyInfo, _ ddl.OnExist) error

CreatePlacementPolicyWithInfo implements the DDL interface.

func (*Checker) CreateSchema

func (d *Checker) CreateSchema(ctx sessionctx.Context, stmt *ast.CreateDatabaseStmt) error

CreateSchema implements the DDL interface.

func (*Checker) CreateSchemaWithInfo

func (d *Checker) CreateSchemaWithInfo(ctx sessionctx.Context, info *model.DBInfo, onExist ddl.OnExist) error

CreateSchemaWithInfo implements the DDL interface.

func (*Checker) CreateSequence

func (*Checker) CreateSequence(_ sessionctx.Context, _ *ast.CreateSequenceStmt) error

CreateSequence implements the DDL interface.

func (*Checker) CreateTable

func (d *Checker) CreateTable(ctx sessionctx.Context, stmt *ast.CreateTableStmt) error

CreateTable implements the DDL interface.

func (*Checker) CreateTableWithInfo

CreateTableWithInfo implements the DDL interface.

func (*Checker) CreateTestDB

func (d *Checker) CreateTestDB(ctx sessionctx.Context)

CreateTestDB creates a `test` database like the default behaviour of TiDB.

func (*Checker) CreateView

func (d *Checker) CreateView(ctx sessionctx.Context, stmt *ast.CreateViewStmt) error

CreateView implements the DDL interface.

func (*Checker) Disable

func (d *Checker) Disable()

Disable turns off check.

func (*Checker) DoDDLJob

func (d *Checker) DoDDLJob(ctx sessionctx.Context, job *model.Job) error

DoDDLJob implements the DDL interface.

func (*Checker) DoDDLJobWrapper

func (d *Checker) DoDDLJobWrapper(ctx sessionctx.Context, jobW *ddl.JobWrapper) error

DoDDLJobWrapper implements the DDL interface.

func (*Checker) DropIndex

func (d *Checker) DropIndex(ctx sessionctx.Context, stmt *ast.DropIndexStmt) error

DropIndex implements the DDL interface.

func (*Checker) DropPlacementPolicy

func (*Checker) DropPlacementPolicy(_ sessionctx.Context, _ *ast.DropPlacementPolicyStmt) error

DropPlacementPolicy implements the DDL interface.

func (*Checker) DropResourceGroup

func (*Checker) DropResourceGroup(_ sessionctx.Context, _ *ast.DropResourceGroupStmt) error

DropResourceGroup implements the DDL interface.

func (*Checker) DropSchema

func (d *Checker) DropSchema(ctx sessionctx.Context, stmt *ast.DropDatabaseStmt) error

DropSchema implements the DDL interface.

func (*Checker) DropSequence

func (*Checker) DropSequence(_ sessionctx.Context, _ *ast.DropSequenceStmt) (err error)

DropSequence implements the DDL interface.

func (*Checker) DropTable

func (d *Checker) DropTable(ctx sessionctx.Context, stmt *ast.DropTableStmt) (err error)

DropTable implements the DDL interface.

func (*Checker) DropView

func (d *Checker) DropView(ctx sessionctx.Context, stmt *ast.DropTableStmt) (err error)

DropView implements the DDL interface.

func (*Checker) Enable

func (d *Checker) Enable()

Enable turns on check.

func (*Checker) FlashbackCluster

func (*Checker) FlashbackCluster(_ sessionctx.Context, _ uint64) (err error)

FlashbackCluster implements the DDL interface.

func (*Checker) GetID

func (d *Checker) GetID() string

GetID implements the DDL interface.

func (*Checker) GetMinJobIDRefresher

func (d *Checker) GetMinJobIDRefresher() *systable.MinJobIDRefresher

GetMinJobIDRefresher implements the DDL interface.

func (*Checker) GetScope

func (d *Checker) GetScope(status string) variable.ScopeFlag

GetScope implements the DDL interface.

func (*Checker) LockTables

func (d *Checker) LockTables(ctx sessionctx.Context, stmt *ast.LockTablesStmt) error

LockTables implements the DDL interface.

func (*Checker) OwnerManager

func (d *Checker) OwnerManager() owner.Manager

OwnerManager implements the DDL interface.

func (*Checker) RecoverSchema

func (*Checker) RecoverSchema(_ sessionctx.Context, _ *model.RecoverSchemaInfo) (err error)

RecoverSchema implements the DDL interface.

func (*Checker) RecoverTable

func (*Checker) RecoverTable(_ sessionctx.Context, _ *model.RecoverTableInfo) (err error)

RecoverTable implements the DDL interface.

func (*Checker) RegisterStatsHandle

func (d *Checker) RegisterStatsHandle(h *handle.Handle)

RegisterStatsHandle implements the DDL interface.

func (*Checker) RenameTable

func (d *Checker) RenameTable(ctx sessionctx.Context, stmt *ast.RenameTableStmt) error

RenameTable implements the DDL interface.

func (*Checker) RepairTable

func (*Checker) RepairTable(_ sessionctx.Context, _ *ast.CreateTableStmt) error

RepairTable implements the DDL interface.

func (*Checker) SchemaSyncer

func (d *Checker) SchemaSyncer() schemaver.Syncer

SchemaSyncer implements the DDL interface.

func (*Checker) Start

func (d *Checker) Start(startMode ddl.StartMode, ctxPool *pools.ResourcePool) error

Start implements the DDL interface.

func (*Checker) StateSyncer

func (d *Checker) StateSyncer() serverstate.Syncer

StateSyncer implements the DDL interface.

func (*Checker) Stats

func (d *Checker) Stats(vars *variable.SessionVars) (map[string]any, error)

Stats implements the DDL interface.

func (*Checker) Stop

func (d *Checker) Stop() error

Stop implements the DDL interface.

func (*Checker) TruncateTable

func (*Checker) TruncateTable(_ sessionctx.Context, _ ast.Ident) error

TruncateTable implements the DDL interface.

func (*Checker) UnlockTables

func (d *Checker) UnlockTables(ctx sessionctx.Context, lockedTables []model.TableLockTpInfo) error

UnlockTables implements the DDL interface.

func (*Checker) UpdateTableReplicaInfo

func (*Checker) UpdateTableReplicaInfo(_ sessionctx.Context, _ int64, _ bool) error

UpdateTableReplicaInfo implements the DDL interface.

type InfoStore

type InfoStore struct {
	// contains filtered or unexported fields
}

InfoStore is a simple structure that stores DBInfo and TableInfo. It's modifiable and not thread-safe.

func NewInfoStore

func NewInfoStore(lowerCaseTableNames int) *InfoStore

NewInfoStore creates a InfoStore.

func (*InfoStore) AllSchemaNames

func (i *InfoStore) AllSchemaNames() []string

AllSchemaNames returns all the schemas' names.

func (*InfoStore) AllTableNamesOfSchema

func (i *InfoStore) AllTableNamesOfSchema(schema pmodel.CIStr) ([]string, error)

AllTableNamesOfSchema return all table names of a schema.

func (*InfoStore) DeleteSchema

func (i *InfoStore) DeleteSchema(name pmodel.CIStr) bool

DeleteSchema deletes the schema from InfoSchema. Returns true when the schema exists, false otherwise.

func (*InfoStore) DeleteTable

func (i *InfoStore) DeleteTable(schema, table pmodel.CIStr) error

DeleteTable deletes the TableInfo, it will return ErrDatabaseNotExists or ErrTableNotExists when schema or table does not exist.

func (*InfoStore) PutSchema

func (i *InfoStore) PutSchema(dbInfo *model.DBInfo)

PutSchema puts a DBInfo, it will overwrite the old one.

func (*InfoStore) PutTable

func (i *InfoStore) PutTable(schemaName pmodel.CIStr, tblInfo *model.TableInfo) error

PutTable puts a TableInfo, it will overwrite the old one. If the schema doesn't exist, it will return ErrDatabaseNotExists.

func (*InfoStore) SchemaByName

func (i *InfoStore) SchemaByName(name pmodel.CIStr) *model.DBInfo

SchemaByName returns the DBInfo of given name. nil if not found.

func (*InfoStore) TableByName

func (i *InfoStore) TableByName(_ context.Context, schema, table pmodel.CIStr) (*model.TableInfo, error)

TableByName returns the TableInfo. It will also return the error like an infoschema.

func (*InfoStore) TableClonedByName

func (i *InfoStore) TableClonedByName(schema, table pmodel.CIStr) (*model.TableInfo, error)

TableClonedByName is like TableByName, plus it will clone the TableInfo.

type InfoStoreAdaptor

type InfoStoreAdaptor struct {
	infoschema.InfoSchema
	// contains filtered or unexported fields
}

InfoStoreAdaptor convert InfoStore to InfoSchema, it only implements a part of InfoSchema interface to be used by DDL interface.

func (InfoStoreAdaptor) SchemaByName

func (i InfoStoreAdaptor) SchemaByName(schema pmodel.CIStr) (*model.DBInfo, bool)

SchemaByName implements the InfoSchema interface.

func (InfoStoreAdaptor) TableByName

func (i InfoStoreAdaptor) TableByName(ctx context.Context, schema, table pmodel.CIStr) (t table.Table, err error)

TableByName implements the InfoSchema interface.

func (InfoStoreAdaptor) TableExists

func (i InfoStoreAdaptor) TableExists(schema, table pmodel.CIStr) bool

TableExists implements the InfoSchema interface.

func (InfoStoreAdaptor) TableInfoByName

func (i InfoStoreAdaptor) TableInfoByName(schema, table pmodel.CIStr) (*model.TableInfo, error)

TableInfoByName implements the InfoSchema interface.

type SchemaTracker

type SchemaTracker struct {
	*InfoStore
}

SchemaTracker is used to track schema changes by DM. It implements ddl.Executor interface and by applying DDL, it updates the table structure to keep tracked with upstream changes.

It embeds an InfoStore which stores DBInfo and TableInfo. The DBInfo and TableInfo can be treated as immutable, so after reading them by SchemaByName or TableByName, later modifications made by SchemaTracker will not change them. SchemaTracker is not thread-safe.

func NewSchemaTracker

func NewSchemaTracker(lowerCaseTableNames int) SchemaTracker

NewSchemaTracker creates a SchemaTracker. lowerCaseTableNames has the same meaning as MySQL variable lower_case_table_names.

func (*SchemaTracker) AddResourceGroup

AddResourceGroup implements the DDL interface, it's no-op in DM's case.

func (*SchemaTracker) AlterPlacementPolicy

func (*SchemaTracker) AlterPlacementPolicy(_ sessionctx.Context, _ *ast.AlterPlacementPolicyStmt) error

AlterPlacementPolicy implements the DDL interface, it's no-op in DM's case.

func (*SchemaTracker) AlterResourceGroup

func (*SchemaTracker) AlterResourceGroup(_ sessionctx.Context, _ *ast.AlterResourceGroupStmt) error

AlterResourceGroup implements the DDL interface, it's no-op in DM's case.

func (*SchemaTracker) AlterSchema

func (d *SchemaTracker) AlterSchema(ctx sessionctx.Context, stmt *ast.AlterDatabaseStmt) (err error)

AlterSchema implements the DDL interface.

func (*SchemaTracker) AlterSequence

AlterSequence implements the DDL interface, it's no-op in DM's case.

func (*SchemaTracker) AlterTable

func (d *SchemaTracker) AlterTable(ctx context.Context, sctx sessionctx.Context, stmt *ast.AlterTableStmt) (err error)

AlterTable implements the DDL interface.

func (*SchemaTracker) BatchCreateTableWithInfo

func (d *SchemaTracker) BatchCreateTableWithInfo(ctx sessionctx.Context, schema pmodel.CIStr, info []*model.TableInfo, cs ...ddl.CreateTableOption) error

BatchCreateTableWithInfo implements the DDL interface, it will call CreateTableWithInfo for each table.

func (*SchemaTracker) CleanupTableLock

func (*SchemaTracker) CleanupTableLock(_ sessionctx.Context, _ []*ast.TableName) error

CleanupTableLock implements the DDL interface, it's no-op in DM's case.

func (*SchemaTracker) CreateIndex

func (d *SchemaTracker) CreateIndex(ctx sessionctx.Context, stmt *ast.CreateIndexStmt) error

CreateIndex implements the DDL interface.

func (*SchemaTracker) CreatePlacementPolicy

func (*SchemaTracker) CreatePlacementPolicy(_ sessionctx.Context, _ *ast.CreatePlacementPolicyStmt) error

CreatePlacementPolicy implements the DDL interface, it's no-op in DM's case.

func (*SchemaTracker) CreatePlacementPolicyWithInfo

func (*SchemaTracker) CreatePlacementPolicyWithInfo(_ sessionctx.Context, _ *model.PolicyInfo, _ ddl.OnExist) error

CreatePlacementPolicyWithInfo implements the DDL interface, it's no-op in DM's case.

func (*SchemaTracker) CreateSchema

func (d *SchemaTracker) CreateSchema(ctx sessionctx.Context, stmt *ast.CreateDatabaseStmt) error

CreateSchema implements the DDL interface.

func (*SchemaTracker) CreateSchemaWithInfo

func (d *SchemaTracker) CreateSchemaWithInfo(_ sessionctx.Context, dbInfo *model.DBInfo, onExist ddl.OnExist) error

CreateSchemaWithInfo implements the DDL interface.

func (*SchemaTracker) CreateSequence

CreateSequence implements the DDL interface, it's no-op in DM's case.

func (*SchemaTracker) CreateTable

func (d *SchemaTracker) CreateTable(ctx sessionctx.Context, s *ast.CreateTableStmt) error

CreateTable implements the DDL interface.

func (*SchemaTracker) CreateTableWithInfo

func (d *SchemaTracker) CreateTableWithInfo(
	_ sessionctx.Context,
	dbName pmodel.CIStr,
	info *model.TableInfo,
	_ []model.InvolvingSchemaInfo,
	cs ...ddl.CreateTableOption,
) error

CreateTableWithInfo implements the DDL interface.

func (*SchemaTracker) CreateTestDB

func (d *SchemaTracker) CreateTestDB(ctx sessionctx.Context)

CreateTestDB creates the `test` database, which is the default behavior of TiDB.

func (*SchemaTracker) CreateView

func (d *SchemaTracker) CreateView(ctx sessionctx.Context, s *ast.CreateViewStmt) error

CreateView implements the DDL interface.

func (*SchemaTracker) DropIndex

func (d *SchemaTracker) DropIndex(ctx sessionctx.Context, stmt *ast.DropIndexStmt) error

DropIndex implements the DDL interface.

func (*SchemaTracker) DropPlacementPolicy

func (*SchemaTracker) DropPlacementPolicy(_ sessionctx.Context, _ *ast.DropPlacementPolicyStmt) error

DropPlacementPolicy implements the DDL interface, it's no-op in DM's case.

func (*SchemaTracker) DropResourceGroup

func (*SchemaTracker) DropResourceGroup(_ sessionctx.Context, _ *ast.DropResourceGroupStmt) error

DropResourceGroup implements the DDL interface, it's no-op in DM's case.

func (*SchemaTracker) DropSchema

func (d *SchemaTracker) DropSchema(_ sessionctx.Context, stmt *ast.DropDatabaseStmt) error

DropSchema implements the DDL interface.

func (*SchemaTracker) DropSequence

func (*SchemaTracker) DropSequence(_ sessionctx.Context, _ *ast.DropSequenceStmt) (err error)

DropSequence implements the DDL interface, it's no-op in DM's case.

func (*SchemaTracker) DropTable

func (d *SchemaTracker) DropTable(_ sessionctx.Context, stmt *ast.DropTableStmt) (err error)

DropTable implements the DDL interface.

func (*SchemaTracker) DropView

func (d *SchemaTracker) DropView(_ sessionctx.Context, stmt *ast.DropTableStmt) (err error)

DropView implements the DDL interface.

func (*SchemaTracker) FlashbackCluster

func (*SchemaTracker) FlashbackCluster(_ sessionctx.Context, _ uint64) (err error)

FlashbackCluster implements the DDL interface, which is no-op in DM's case.

func (*SchemaTracker) LockTables

LockTables implements the DDL interface, it's no-op in DM's case.

func (*SchemaTracker) RecoverSchema

func (*SchemaTracker) RecoverSchema(_ sessionctx.Context, _ *model.RecoverSchemaInfo) (err error)

RecoverSchema implements the DDL interface, which is no-op in DM's case.

func (*SchemaTracker) RecoverTable

func (*SchemaTracker) RecoverTable(_ sessionctx.Context, _ *model.RecoverTableInfo) (err error)

RecoverTable implements the DDL interface, which is no-op in DM's case.

func (*SchemaTracker) RenameTable

func (d *SchemaTracker) RenameTable(ctx sessionctx.Context, stmt *ast.RenameTableStmt) error

RenameTable implements the DDL interface.

func (*SchemaTracker) RepairTable

RepairTable implements the DDL interface, it's no-op in DM's case.

func (*SchemaTracker) TruncateTable

func (*SchemaTracker) TruncateTable(_ sessionctx.Context, _ ast.Ident) error

TruncateTable implements the DDL interface, it's no-op in DM's case.

func (*SchemaTracker) UnlockTables

UnlockTables implements the DDL interface, it's no-op in DM's case.

func (*SchemaTracker) UpdateTableReplicaInfo

func (*SchemaTracker) UpdateTableReplicaInfo(_ sessionctx.Context, _ int64, _ bool) error

UpdateTableReplicaInfo implements the DDL interface, it's no-op in DM's case.

type StorageDDLInjector

type StorageDDLInjector struct {
	Injector func(ddl.DDL, ddl.Executor, *infoschema.InfoCache) *Checker
	// contains filtered or unexported fields
}

StorageDDLInjector wraps kv.Storage to inject checker to domain's DDL in bootstrap time.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL