schema

package
v0.0.0-...-4624acb Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTableNotExists

func IsTableNotExists(err error) bool

IsTableNotExists checks if err means the database or table does not exist.

Types

type DownstreamTableInfo

type DownstreamTableInfo struct {
	TableInfo   *model.TableInfo // tableInfo which comes from parse create statement syntaxtree
	WhereHandle *sqlmodel.WhereHandle
}

DownstreamTableInfo contains tableinfo and index cache.

type Tracker

type Tracker struct {
	// The Tracker uses tidb DDL library to track table structure changes.
	// where there was basically no parallel operation at the beginning.
	// However, since the validator is introduced and heavily dependent on the Tracker, we need to make sure
	// the synchronization between the reading from the validator and the modification from the syncer (e.g.
	// when the checkpoint is being rolled back, we have to make sure the validator can still vision the original tables)
	// From this point, we add an extra layer of the synchronization for the following operations:
	// 1. GetTableInfo: the validator reads table infos.
	// 2. Init: when the syncer restarts, it may re-initialize the Tracker while the validator may read the Tracker at the same time.
	// 3. Close: Being similar as above, the validator can read the Tracker while the syncer is closing the Tracker.
	sync.RWMutex
	// contains filtered or unexported fields
}

Tracker is used to track schema locally.

func NewTestTracker

func NewTestTracker(
	ctx context.Context,
	task string,
	downstreamConn *dbconn.DBConn,
	logger log.Logger,
) (*Tracker, error)

NewTestTracker creates an empty Tracker and initializes it subsequently. It is useful for test.

func NewTracker

func NewTracker() *Tracker

NewTracker simply returns an empty Tracker, which should be followed by an initialization before used.

func (*Tracker) AllSchemas

func (tr *Tracker) AllSchemas() []string

AllSchemas returns all schemas visible to the tracker (excluding system tables).

func (*Tracker) BatchCreateTableIfNotExist

func (tr *Tracker) BatchCreateTableIfNotExist(tablesToCreate map[string]map[string]*model.TableInfo) error

BatchCreateTableIfNotExist will batch creating tables per schema. If the schema does not exist, it will create it. The argument is { database name -> { table name -> TableInfo } }.

func (*Tracker) Close

func (tr *Tracker) Close()

Close closes a tracker.

func (*Tracker) CreateSchemaIfNotExists

func (tr *Tracker) CreateSchemaIfNotExists(db string) error

CreateSchemaIfNotExists creates a SCHEMA of the given name if it did not exist.

func (*Tracker) CreateTableIfNotExists

func (tr *Tracker) CreateTableIfNotExists(table *filter.Table, ti *model.TableInfo) error

CreateTableIfNotExists creates a TABLE of the given name if it did not exist.

func (*Tracker) DropTable

func (tr *Tracker) DropTable(table *filter.Table) error

DropTable drops a table from this tracker.

func (*Tracker) Exec

func (tr *Tracker) Exec(ctx context.Context, db string, stmt ast.StmtNode) (errRet error)

Exec runs an SQL (DDL) statement.

func (*Tracker) GetCreateTable

func (tr *Tracker) GetCreateTable(ctx context.Context, table *filter.Table) (string, error)

GetCreateTable returns the `CREATE TABLE` statement of the table.

func (*Tracker) GetDownStreamTableInfo

func (tr *Tracker) GetDownStreamTableInfo(tctx *tcontext.Context, tableID string, originTI *model.TableInfo) (*DownstreamTableInfo, error)

GetDownStreamTableInfo gets downstream table info. note. this function will init downstreamTrack's table info.

func (*Tracker) GetSingleColumnIndices

func (tr *Tracker) GetSingleColumnIndices(db, tbl, col string) ([]*model.IndexInfo, error)

GetSingleColumnIndices returns indices of input column if input column only has single-column indices returns nil if input column has no indices, or has multi-column indices. TODO: move out of this package!

func (*Tracker) GetTableInfo

func (tr *Tracker) GetTableInfo(table *filter.Table) (*model.TableInfo, error)

GetTableInfo returns the schema associated with the table.

func (*Tracker) Init

func (tr *Tracker) Init(
	ctx context.Context,
	task string,
	lowerCaseTableNames int,
	downstreamConn *dbconn.DBConn,
	logger log.Logger,
) error

Init initializes the Tracker. `sessionCfg` will be set as tracker's session variables if specified, or retrieve some variable from downstream using `downstreamConn`. NOTE **sessionCfg is a reference to caller**.

func (*Tracker) ListSchemaTables

func (tr *Tracker) ListSchemaTables(schema string) ([]string, error)

ListSchemaTables lists all tables in the schema.

func (*Tracker) RemoveDownstreamSchema

func (tr *Tracker) RemoveDownstreamSchema(tctx *tcontext.Context, targetTables []*filter.Table)

RemoveDownstreamSchema just remove schema or table in downstreamTrack.

func (*Tracker) Reset

func (tr *Tracker) Reset()

Reset drops all tables inserted into this tracker.

func (*Tracker) SplitBatchCreateTableAndHandle

func (tr *Tracker) SplitBatchCreateTableAndHandle(schema pmodel.CIStr, info []*model.TableInfo, l int, r int) error

SplitBatchCreateTableAndHandle will split the batch if it exceeds the kv entry size limit.

Jump to

Keyboard shortcuts

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