meta

package
v0.0.0-...-503c688 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CurrentMagicByteVer is the current magic byte version, used for future meta compatibility.
	CurrentMagicByteVer byte = 0x00

	// MaxInt48 is the max value of int48.
	MaxInt48 = 0x0000FFFFFFFFFFFF
	// MaxGlobalID reserves 1000 IDs. Use MaxInt48 to reserves the high 2 bytes to compatible with Multi-tenancy.
	MaxGlobalID = MaxInt48 - 1000
)

Variables

View Source
var (
	// ErrDBExists is the error for db exists.
	ErrDBExists = dbterror.ClassMeta.NewStd(mysql.ErrDBCreateExists)
	// ErrDBNotExists is the error for db not exists.
	ErrDBNotExists = dbterror.ClassMeta.NewStd(mysql.ErrBadDB)
	// ErrPolicyExists is the error for policy exists.
	ErrPolicyExists = dbterror.ClassMeta.NewStd(errno.ErrPlacementPolicyExists)
	// ErrPolicyNotExists is the error for policy not exists.
	ErrPolicyNotExists = dbterror.ClassMeta.NewStd(errno.ErrPlacementPolicyNotExists)
	// ErrResourceGroupExists is the error for resource group exists.
	ErrResourceGroupExists = dbterror.ClassMeta.NewStd(errno.ErrResourceGroupExists)
	// ErrResourceGroupNotExists is the error for resource group not exists.
	ErrResourceGroupNotExists = dbterror.ClassMeta.NewStd(errno.ErrResourceGroupNotExists)
	// ErrTableExists is the error for table exists.
	ErrTableExists = dbterror.ClassMeta.NewStd(mysql.ErrTableExists)
	// ErrTableNotExists is the error for table not exists.
	ErrTableNotExists = dbterror.ClassMeta.NewStd(mysql.ErrNoSuchTable)
	// ErrDDLReorgElementNotExist is the error for reorg element not exists.
	ErrDDLReorgElementNotExist = dbterror.ClassMeta.NewStd(errno.ErrDDLReorgElementNotExist)
	// ErrInvalidString is the error for invalid string to parse
	ErrInvalidString = dbterror.ClassMeta.NewStd(errno.ErrInvalidCharacterString)
)

Functions

func AutoRandomTableIDKey

func AutoRandomTableIDKey(tableID int64) []byte

AutoRandomTableIDKey encodes the auto random tableID key.

func AutoTableIDKey

func AutoTableIDKey(tableID int64) []byte

AutoTableIDKey decodes the auto tableID key.

func BackupAndRestoreAutoIDs

func BackupAndRestoreAutoIDs(m *Meta, databaseID, tableID int64, newDatabaseID, newTableID int64) (err error)

BackupAndRestoreAutoIDs changes the meta key-values to fetch & delete all the auto IDs from an old table, and set them to a new table.

func DBkey

func DBkey(dbID int64) []byte

DBkey encodes the dbID into dbKey.

func DDLJobHistoryKey

func DDLJobHistoryKey(m *Meta, jobID int64) []byte

DDLJobHistoryKey is only used for testing.

func DefaultGroupMeta4Test

func DefaultGroupMeta4Test() *model.ResourceGroupInfo

DefaultGroupMeta4Test return the default group info for test usage.

func IsAutoRandomTableIDKey

func IsAutoRandomTableIDKey(key []byte) bool

IsAutoRandomTableIDKey checks whether the key is auto random tableID key.

func IsAutoTableIDKey

func IsAutoTableIDKey(key []byte) bool

IsAutoTableIDKey checks whether the key is auto tableID key.

func IsDBkey

func IsDBkey(dbKey []byte) bool

IsDBkey checks whether the dbKey comes from DBKey().

func IsSequenceKey

func IsSequenceKey(key []byte) bool

IsSequenceKey checks whether the key is sequence key.

func IsTableKey

func IsTableKey(tableKey []byte) bool

IsTableKey checks whether the tableKey comes from TableKey().

func ParseAutoRandomTableIDKey

func ParseAutoRandomTableIDKey(key []byte) (int64, error)

ParseAutoRandomTableIDKey decodes the tableID from the auto random tableID key.

func ParseAutoTableIDKey

func ParseAutoTableIDKey(key []byte) (int64, error)

ParseAutoTableIDKey decodes the tableID from the auto tableID key.

func ParseDBKey

func ParseDBKey(dbkey []byte) (int64, error)

ParseDBKey decodes the dbkey to get dbID.

func ParseSequenceKey

func ParseSequenceKey(key []byte) (int64, error)

ParseSequenceKey decodes the tableID from the sequence key.

func ParseTableKey

func ParseTableKey(tableKey []byte) (int64, error)

ParseTableKey decodes the tableKey to get tableID.

func SequenceKey

func SequenceKey(sequenceID int64) []byte

SequenceKey encodes the sequence key.

func TableKey

func TableKey(tableID int64) []byte

TableKey encodes the tableID into tableKey.

Types

type AccessorPicker

type AccessorPicker interface {
	RowID() AutoIDAccessor
	RandomID() AutoIDAccessor
	IncrementID(tableVersion uint16) AutoIDAccessor

	SequenceValue() AutoIDAccessor
	SequenceCycle() AutoIDAccessor
}

AccessorPicker is used to pick a type of auto ID accessor.

type AutoIDAccessor

type AutoIDAccessor interface {
	Get() (int64, error)
	Put(val int64) error
	Inc(step int64) (int64, error)
	Del() error
}

AutoIDAccessor represents the entry to retrieve/mutate auto IDs.

type AutoIDAccessors

type AutoIDAccessors interface {
	Get() (AutoIDGroup, error)
	Put(autoIDs AutoIDGroup) error
	Del() error

	AccessorPicker
}

AutoIDAccessors represents all the auto IDs of a table.

func NewAutoIDAccessors

func NewAutoIDAccessors(m *Meta, databaseID, tableID int64) AutoIDAccessors

NewAutoIDAccessors creates a new AutoIDAccessors.

type AutoIDGroup

type AutoIDGroup struct {
	RowID       int64
	IncrementID int64
	RandomID    int64
}

AutoIDGroup represents a group of auto IDs of a specific table.

type DDLTableVersion

type DDLTableVersion int

DDLTableVersion is to display ddl related table versions

const (
	// InitDDLTableVersion is the original version.
	InitDDLTableVersion DDLTableVersion = 0
	// BaseDDLTableVersion is for support concurrent DDL, it added tidb_ddl_job, tidb_ddl_reorg and tidb_ddl_history.
	BaseDDLTableVersion DDLTableVersion = 1
	// MDLTableVersion is for support MDL tables.
	MDLTableVersion DDLTableVersion = 2
	// BackfillTableVersion is for support distributed reorg stage, it added tidb_background_subtask, tidb_background_subtask_history.
	BackfillTableVersion DDLTableVersion = 3
)

func (DDLTableVersion) Bytes

func (ver DDLTableVersion) Bytes() []byte

Bytes returns the byte slice.

type Element

type Element struct {
	ID      int64
	TypeKey []byte
}

Element has the information of the backfill job's type and ID.

func DecodeElement

func DecodeElement(b []byte) (*Element, error)

DecodeElement decodes values from a byte slice generated with an element. It's exported for testing.

func (*Element) EncodeElement

func (e *Element) EncodeElement() []byte

EncodeElement encodes an Element into a byte slice. It's exported for testing.

func (*Element) String

func (e *Element) String() string

String defines a Stringer function for debugging and pretty printing.

type ElementKeyType

type ElementKeyType []byte

ElementKeyType is a key type of the element.

var (
	// ColumnElementKey is the key for column element.
	ColumnElementKey ElementKeyType = []byte("_col_")
	// IndexElementKey is the key for index element.
	IndexElementKey ElementKeyType = []byte("_idx_")
)

type HLastJobIterator

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

HLastJobIterator is the iterator for gets the latest history.

func (*HLastJobIterator) GetLastJobs

func (i *HLastJobIterator) GetLastJobs(num int, jobs []*model.Job) ([]*model.Job, error)

GetLastJobs gets last several jobs.

type JobListKeyType

type JobListKeyType []byte

JobListKeyType is a key type of the DDL job queue.

var (
	// DefaultJobListKey keeps all actions of DDL jobs except "add index".
	DefaultJobListKey JobListKeyType = mDDLJobListKey
	// AddIndexJobListKey only keeps the action of adding index.
	AddIndexJobListKey JobListKeyType = mDDLJobAddIdxList
)

type LastJobIterator

type LastJobIterator interface {
	GetLastJobs(num int, jobs []*model.Job) ([]*model.Job, error)
}

LastJobIterator is the iterator for gets latest history.

type Meta

type Meta struct {
	StartTS uint64 // StartTS is the txn's start TS.
	// contains filtered or unexported fields
}

Meta is for handling meta information in a transaction.

func NewMeta

func NewMeta(txn kv.Transaction) *Meta

NewMeta creates a Meta in transaction txn. If the current Meta needs to handle a job, jobListKey is the type of the job's list.

func NewSnapshotMeta

func NewSnapshotMeta(snapshot kv.Snapshot) *Meta

NewSnapshotMeta creates a Meta with snapshot.

func (*Meta) AddHistoryDDLJob

func (m *Meta) AddHistoryDDLJob(job *model.Job, updateRawArgs bool) error

AddHistoryDDLJob adds DDL job to history.

func (*Meta) AddResourceGroup

func (m *Meta) AddResourceGroup(group *model.ResourceGroupInfo) error

AddResourceGroup creates a resource group.

func (*Meta) AdvanceGlobalIDs

func (m *Meta) AdvanceGlobalIDs(n int) (int64, error)

AdvanceGlobalIDs advances the global ID by n. return the old global ID.

func (*Meta) CheckDDLTableVersion

func (m *Meta) CheckDDLTableVersion() (DDLTableVersion, error)

CheckDDLTableVersion check if the tables related to concurrent DDL exists.

func (*Meta) CheckTableExists

func (m *Meta) CheckTableExists(dbID int64, tableID int64) (bool, error)

CheckTableExists checks if the table is existed with dbID and tableID.

func (*Meta) CreateDatabase

func (m *Meta) CreateDatabase(dbInfo *model.DBInfo) error

CreateDatabase creates a database with db info.

func (*Meta) CreateMySQLDatabaseIfNotExists

func (m *Meta) CreateMySQLDatabaseIfNotExists() (int64, error)

CreateMySQLDatabaseIfNotExists creates mysql schema and return its DB ID.

func (*Meta) CreatePolicy

func (m *Meta) CreatePolicy(policy *model.PolicyInfo) error

CreatePolicy creates a policy.

func (*Meta) CreateSequenceAndSetSeqValue

func (m *Meta) CreateSequenceAndSetSeqValue(dbID int64, tableInfo *model.TableInfo, seqValue int64) error

CreateSequenceAndSetSeqValue creates sequence with tableInfo in database, and rebase the sequence seqValue.

func (*Meta) CreateTableAndSetAutoID

func (m *Meta) CreateTableAndSetAutoID(dbID int64, tableInfo *model.TableInfo, autoIncID, autoRandID int64) error

CreateTableAndSetAutoID creates a table with tableInfo in database, and rebases the table autoID.

func (*Meta) CreateTableOrView

func (m *Meta) CreateTableOrView(dbID int64, tableInfo *model.TableInfo) error

CreateTableOrView creates a table with tableInfo in database.

func (*Meta) DropDatabase

func (m *Meta) DropDatabase(dbID int64) error

DropDatabase drops whole database.

func (*Meta) DropPolicy

func (m *Meta) DropPolicy(policyID int64) error

DropPolicy drops the specified policy.

func (*Meta) DropResourceGroup

func (m *Meta) DropResourceGroup(groupID int64) error

DropResourceGroup drops a resource group.

func (*Meta) DropSequence

func (m *Meta) DropSequence(dbID int64, tblID int64) error

DropSequence drops sequence in database. Sequence is made of table struct and kv value pair.

func (*Meta) DropTableOrView

func (m *Meta) DropTableOrView(dbID int64, tblID int64) error

DropTableOrView drops table in database. If delAutoID is true, it will delete the auto_increment id key-value of the table. For rename table, we do not need to rename auto_increment id key-value.

func (*Meta) EnQueueDDLJob

func (m *Meta) EnQueueDDLJob(job *model.Job, jobListKeys ...JobListKeyType) error

EnQueueDDLJob adds a DDL job to the list.

func (*Meta) EncodeSchemaDiffKey

func (m *Meta) EncodeSchemaDiffKey(schemaVersion int64) kv.Key

EncodeSchemaDiffKey returns the raw kv key for a schema diff

func (*Meta) FinishBootstrap

func (m *Meta) FinishBootstrap(version int64) error

FinishBootstrap finishes bootstrap.

func (*Meta) GenAutoTableIDKeyValue

func (m *Meta) GenAutoTableIDKeyValue(dbID, tableID, autoID int64) (key, value []byte)

GenAutoTableIDKeyValue generates meta key by dbID, tableID and corresponding value by autoID.

func (*Meta) GenGlobalID

func (m *Meta) GenGlobalID() (int64, error)

GenGlobalID generates next id globally.

func (*Meta) GenGlobalIDs

func (m *Meta) GenGlobalIDs(n int) ([]int64, error)

GenGlobalIDs generates the next n global IDs.

func (*Meta) GenPlacementPolicyID

func (m *Meta) GenPlacementPolicyID() (int64, error)

GenPlacementPolicyID generates next placement policy id globally.

func (*Meta) GenSchemaVersion

func (m *Meta) GenSchemaVersion() (int64, error)

GenSchemaVersion generates next schema version.

func (*Meta) GenSchemaVersions

func (m *Meta) GenSchemaVersions(count int64) (int64, error)

GenSchemaVersions increases the schema version.

func (*Meta) GetAllDDLJobsInQueue

func (m *Meta) GetAllDDLJobsInQueue(jobListKeys ...JobListKeyType) ([]*model.Job, error)

GetAllDDLJobsInQueue gets all DDL Jobs in the current queue. The length of jobListKeys can only be 1 or 0. If its length is 1, we need to replace m.jobListKey with jobListKeys[0]. Otherwise, we use m.jobListKey directly.

func (*Meta) GetAutoIDAccessors

func (m *Meta) GetAutoIDAccessors(dbID, tableID int64) AutoIDAccessors

GetAutoIDAccessors gets the controller for auto IDs.

func (*Meta) GetBootstrapVersion

func (m *Meta) GetBootstrapVersion() (int64, error)

GetBootstrapVersion returns the version of the server which bootstrap the store. If the store is not bootstraped, the version will be zero.

func (*Meta) GetDatabase

func (m *Meta) GetDatabase(dbID int64) (*model.DBInfo, error)

GetDatabase gets the database value with ID.

func (*Meta) GetGlobalID

func (m *Meta) GetGlobalID() (int64, error)

GetGlobalID gets current global id.

func (*Meta) GetHistoryDDLCount

func (m *Meta) GetHistoryDDLCount() (uint64, error)

GetHistoryDDLCount the count of all history DDL jobs.

func (*Meta) GetHistoryDDLJob

func (m *Meta) GetHistoryDDLJob(id int64) (*model.Job, error)

GetHistoryDDLJob gets a history DDL job.

func (*Meta) GetHistoryDDLJobsIterator

func (m *Meta) GetHistoryDDLJobsIterator(startJobID int64) (LastJobIterator, error)

GetHistoryDDLJobsIterator gets the jobs iterator begin with startJobID.

func (*Meta) GetLastHistoryDDLJobsIterator

func (m *Meta) GetLastHistoryDDLJobsIterator() (LastJobIterator, error)

GetLastHistoryDDLJobsIterator gets latest N history ddl jobs iterator.

func (*Meta) GetMetadataLock

func (m *Meta) GetMetadataLock() (enable bool, isNull bool, err error)

GetMetadataLock gets the metadata lock.

func (*Meta) GetPolicy

func (m *Meta) GetPolicy(policyID int64) (*model.PolicyInfo, error)

GetPolicy gets the database value with ID.

func (*Meta) GetPolicyID

func (m *Meta) GetPolicyID() (int64, error)

GetPolicyID gets current policy global id.

func (*Meta) GetResourceGroup

func (m *Meta) GetResourceGroup(groupID int64) (*model.ResourceGroupInfo, error)

GetResourceGroup gets the database value with ID.

func (*Meta) GetSchemaDiff

func (m *Meta) GetSchemaDiff(schemaVersion int64) (*model.SchemaDiff, error)

GetSchemaDiff gets the modification information on a given schema version.

func (*Meta) GetSchemaVersion

func (m *Meta) GetSchemaVersion() (int64, error)

GetSchemaVersion gets current global schema version.

func (*Meta) GetSchemaVersionWithNonEmptyDiff

func (m *Meta) GetSchemaVersionWithNonEmptyDiff() (int64, error)

GetSchemaVersionWithNonEmptyDiff gets current global schema version, if diff is nil, we should return version - 1. Consider the following scenario:

// t1 t2 t3 t4 // | | | // update schema version | set diff // stale read ts

At the first time, t2 reads the schema version v10, but the v10's diff is not set yet, so it loads v9 infoSchema. But at t4 moment, v10's diff has been set and been cached in the memory, so stale read on t2 will get v10 schema from cache, and inconsistency happen. To solve this problem, we always check the schema diff at first, if the diff is empty, we know at t2 moment we can only see the v9 schema, so make neededSchemaVersion = neededSchemaVersion - 1. For `Reload`, we can also do this: if the newest version's diff is not set yet, it is ok to load the previous version's infoSchema, and wait for the next reload.

func (*Meta) GetSystemDBID

func (m *Meta) GetSystemDBID() (int64, error)

GetSystemDBID gets the system DB ID. return (0, nil) indicates that the system DB does not exist.

func (*Meta) GetTable

func (m *Meta) GetTable(dbID int64, tableID int64) (*model.TableInfo, error)

GetTable gets the table value in database with tableID.

func (*Meta) IterTables

func (m *Meta) IterTables(dbID int64, fn func(info *model.TableInfo) error) error

IterTables iterates all the table at once, in order to avoid oom.

func (*Meta) ListDatabases

func (m *Meta) ListDatabases() ([]*model.DBInfo, error)

ListDatabases shows all databases.

func (*Meta) ListPolicies

func (m *Meta) ListPolicies() ([]*model.PolicyInfo, error)

ListPolicies shows all policies.

func (*Meta) ListResourceGroups

func (m *Meta) ListResourceGroups() ([]*model.ResourceGroupInfo, error)

ListResourceGroups shows all resource groups.

func (*Meta) ListTables

func (m *Meta) ListTables(dbID int64) ([]*model.TableInfo, error)

ListTables shows all tables in database.

func (*Meta) RestartSequenceValue

func (m *Meta) RestartSequenceValue(dbID int64, tableInfo *model.TableInfo, seqValue int64) error

RestartSequenceValue resets the the sequence value.

func (*Meta) SetDDLTables

func (m *Meta) SetDDLTables(ddlTableVersion DDLTableVersion) error

SetDDLTables write a key into storage.

func (*Meta) SetMetadataLock

func (m *Meta) SetMetadataLock(b bool) error

SetMetadataLock sets the metadata lock.

func (*Meta) SetSchemaDiff

func (m *Meta) SetSchemaDiff(diff *model.SchemaDiff) error

SetSchemaDiff sets the modification information on a given schema version.

func (*Meta) UpdateDatabase

func (m *Meta) UpdateDatabase(dbInfo *model.DBInfo) error

UpdateDatabase updates a database with db info.

func (*Meta) UpdatePolicy

func (m *Meta) UpdatePolicy(policy *model.PolicyInfo) error

UpdatePolicy updates a policy.

func (*Meta) UpdateResourceGroup

func (m *Meta) UpdateResourceGroup(group *model.ResourceGroupInfo) error

UpdateResourceGroup updates a resource group.

func (*Meta) UpdateTable

func (m *Meta) UpdateTable(dbID int64, tableInfo *model.TableInfo) error

UpdateTable updates the table with table info.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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