Documentation ¶
Index ¶
- Constants
- Variables
- func AutoRandomTableIDKey(tableID int64) []byte
- func AutoTableIDKey(tableID int64) []byte
- func BackupAndRestoreAutoIDs(m *Meta, databaseID, tableID int64, newDatabaseID, newTableID int64) (err error)
- func DBkey(dbID int64) []byte
- func DDLJobHistoryKey(m *Meta, jobID int64) []byte
- func DefaultGroupMeta4Test() *model.ResourceGroupInfo
- func IsAutoRandomTableIDKey(key []byte) bool
- func IsAutoTableIDKey(key []byte) bool
- func IsDBkey(dbKey []byte) bool
- func IsSequenceKey(key []byte) bool
- func IsTableKey(tableKey []byte) bool
- func ParseAutoRandomTableIDKey(key []byte) (int64, error)
- func ParseAutoTableIDKey(key []byte) (int64, error)
- func ParseDBKey(dbkey []byte) (int64, error)
- func ParseSequenceKey(key []byte) (int64, error)
- func ParseTableKey(tableKey []byte) (int64, error)
- func SequenceKey(sequenceID int64) []byte
- func TableKey(tableID int64) []byte
- type AccessorPicker
- type AutoIDAccessor
- type AutoIDAccessors
- type AutoIDGroup
- type DDLTableVersion
- type Element
- type ElementKeyType
- type HLastJobIterator
- type JobListKeyType
- type LastJobIterator
- type Meta
- func (m *Meta) AddHistoryDDLJob(job *model.Job, updateRawArgs bool) error
- func (m *Meta) AddResourceGroup(group *model.ResourceGroupInfo) error
- func (m *Meta) AdvanceGlobalIDs(n int) (int64, error)
- func (m *Meta) CheckDDLTableVersion() (DDLTableVersion, error)
- func (m *Meta) CheckTableExists(dbID int64, tableID int64) (bool, error)
- func (m *Meta) CreateDatabase(dbInfo *model.DBInfo) error
- func (m *Meta) CreateMySQLDatabaseIfNotExists() (int64, error)
- func (m *Meta) CreatePolicy(policy *model.PolicyInfo) error
- func (m *Meta) CreateSequenceAndSetSeqValue(dbID int64, tableInfo *model.TableInfo, seqValue int64) error
- func (m *Meta) CreateTableAndSetAutoID(dbID int64, tableInfo *model.TableInfo, autoIncID, autoRandID int64) error
- func (m *Meta) CreateTableOrView(dbID int64, tableInfo *model.TableInfo) error
- func (m *Meta) DropDatabase(dbID int64) error
- func (m *Meta) DropPolicy(policyID int64) error
- func (m *Meta) DropResourceGroup(groupID int64) error
- func (m *Meta) DropSequence(dbID int64, tblID int64) error
- func (m *Meta) DropTableOrView(dbID int64, tblID int64) error
- func (m *Meta) EnQueueDDLJob(job *model.Job, jobListKeys ...JobListKeyType) error
- func (m *Meta) EncodeSchemaDiffKey(schemaVersion int64) kv.Key
- func (m *Meta) FinishBootstrap(version int64) error
- func (m *Meta) GenAutoTableIDKeyValue(dbID, tableID, autoID int64) (key, value []byte)
- func (m *Meta) GenGlobalID() (int64, error)
- func (m *Meta) GenGlobalIDs(n int) ([]int64, error)
- func (m *Meta) GenPlacementPolicyID() (int64, error)
- func (m *Meta) GenSchemaVersion() (int64, error)
- func (m *Meta) GenSchemaVersions(count int64) (int64, error)
- func (m *Meta) GetAllDDLJobsInQueue(jobListKeys ...JobListKeyType) ([]*model.Job, error)
- func (m *Meta) GetAutoIDAccessors(dbID, tableID int64) AutoIDAccessors
- func (m *Meta) GetBootstrapVersion() (int64, error)
- func (m *Meta) GetDatabase(dbID int64) (*model.DBInfo, error)
- func (m *Meta) GetGlobalID() (int64, error)
- func (m *Meta) GetHistoryDDLCount() (uint64, error)
- func (m *Meta) GetHistoryDDLJob(id int64) (*model.Job, error)
- func (m *Meta) GetHistoryDDLJobsIterator(startJobID int64) (LastJobIterator, error)
- func (m *Meta) GetLastHistoryDDLJobsIterator() (LastJobIterator, error)
- func (m *Meta) GetMetadataLock() (enable bool, isNull bool, err error)
- func (m *Meta) GetPolicy(policyID int64) (*model.PolicyInfo, error)
- func (m *Meta) GetPolicyID() (int64, error)
- func (m *Meta) GetResourceGroup(groupID int64) (*model.ResourceGroupInfo, error)
- func (m *Meta) GetSchemaDiff(schemaVersion int64) (*model.SchemaDiff, error)
- func (m *Meta) GetSchemaVersion() (int64, error)
- func (m *Meta) GetSchemaVersionWithNonEmptyDiff() (int64, error)
- func (m *Meta) GetSystemDBID() (int64, error)
- func (m *Meta) GetTable(dbID int64, tableID int64) (*model.TableInfo, error)
- func (m *Meta) IterTables(dbID int64, fn func(info *model.TableInfo) error) error
- func (m *Meta) ListDatabases() ([]*model.DBInfo, error)
- func (m *Meta) ListPolicies() ([]*model.PolicyInfo, error)
- func (m *Meta) ListResourceGroups() ([]*model.ResourceGroupInfo, error)
- func (m *Meta) ListTables(dbID int64) ([]*model.TableInfo, error)
- func (m *Meta) RestartSequenceValue(dbID int64, tableInfo *model.TableInfo, seqValue int64) error
- func (m *Meta) SetDDLTables(ddlTableVersion DDLTableVersion) error
- func (m *Meta) SetMetadataLock(b bool) error
- func (m *Meta) SetSchemaDiff(diff *model.SchemaDiff) error
- func (m *Meta) UpdateDatabase(dbInfo *model.DBInfo) error
- func (m *Meta) UpdatePolicy(policy *model.PolicyInfo) error
- func (m *Meta) UpdateResourceGroup(group *model.ResourceGroupInfo) error
- func (m *Meta) UpdateTable(dbID int64, tableInfo *model.TableInfo) error
Constants ¶
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 ¶
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 ¶
AutoRandomTableIDKey encodes the auto random tableID key.
func AutoTableIDKey ¶
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 DDLJobHistoryKey ¶
DDLJobHistoryKey is only used for testing.
func DefaultGroupMeta4Test ¶
func DefaultGroupMeta4Test() *model.ResourceGroupInfo
DefaultGroupMeta4Test return the default group info for test usage.
func IsAutoRandomTableIDKey ¶
IsAutoRandomTableIDKey checks whether the key is auto random tableID key.
func IsAutoTableIDKey ¶
IsAutoTableIDKey checks whether the key is auto tableID key.
func IsSequenceKey ¶
IsSequenceKey checks whether the key is sequence key.
func IsTableKey ¶
IsTableKey checks whether the tableKey comes from TableKey().
func ParseAutoRandomTableIDKey ¶
ParseAutoRandomTableIDKey decodes the tableID from the auto random tableID key.
func ParseAutoTableIDKey ¶
ParseAutoTableIDKey decodes the tableID from the auto tableID key.
func ParseDBKey ¶
ParseDBKey decodes the dbkey to get dbID.
func ParseSequenceKey ¶
ParseSequenceKey decodes the tableID from the sequence key.
func ParseTableKey ¶
ParseTableKey decodes the tableKey to get tableID.
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 ¶
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 ¶
Element has the information of the backfill job's type and ID.
func DecodeElement ¶
DecodeElement decodes values from a byte slice generated with an element. It's exported for testing.
func (*Element) EncodeElement ¶
EncodeElement encodes an Element into a byte slice. It's exported for testing.
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 ¶
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 ¶
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 ¶
NewSnapshotMeta creates a Meta with snapshot.
func (*Meta) AddHistoryDDLJob ¶
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 ¶
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 ¶
CheckTableExists checks if the table is existed with dbID and tableID.
func (*Meta) CreateDatabase ¶
CreateDatabase creates a database with db info.
func (*Meta) CreateMySQLDatabaseIfNotExists ¶
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 ¶
CreateTableOrView creates a table with tableInfo in database.
func (*Meta) DropDatabase ¶
DropDatabase drops whole database.
func (*Meta) DropPolicy ¶
DropPolicy drops the specified policy.
func (*Meta) DropResourceGroup ¶
DropResourceGroup drops a resource group.
func (*Meta) DropSequence ¶
DropSequence drops sequence in database. Sequence is made of table struct and kv value pair.
func (*Meta) DropTableOrView ¶
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 ¶
EncodeSchemaDiffKey returns the raw kv key for a schema diff
func (*Meta) FinishBootstrap ¶
FinishBootstrap finishes bootstrap.
func (*Meta) GenAutoTableIDKeyValue ¶
GenAutoTableIDKeyValue generates meta key by dbID, tableID and corresponding value by autoID.
func (*Meta) GenGlobalID ¶
GenGlobalID generates next id globally.
func (*Meta) GenGlobalIDs ¶
GenGlobalIDs generates the next n global IDs.
func (*Meta) GenPlacementPolicyID ¶
GenPlacementPolicyID generates next placement policy id globally.
func (*Meta) GenSchemaVersion ¶
GenSchemaVersion generates next schema version.
func (*Meta) GenSchemaVersions ¶
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 ¶
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 ¶
GetDatabase gets the database value with ID.
func (*Meta) GetGlobalID ¶
GetGlobalID gets current global id.
func (*Meta) GetHistoryDDLCount ¶
GetHistoryDDLCount the count of all history DDL jobs.
func (*Meta) GetHistoryDDLJob ¶
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 ¶
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 ¶
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 ¶
GetSchemaVersion gets current global schema version.
func (*Meta) GetSchemaVersionWithNonEmptyDiff ¶
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 ¶
GetSystemDBID gets the system DB ID. return (0, nil) indicates that the system DB does not exist.
func (*Meta) IterTables ¶
IterTables iterates all the table at once, in order to avoid oom.
func (*Meta) ListDatabases ¶
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 ¶
ListTables shows all tables in database.
func (*Meta) RestartSequenceValue ¶
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 ¶
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 ¶
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.