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 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 Element
- type ElementKeyType
- type HLastJobIterator
- type JobListKeyType
- type LastJobIterator
- type Meta
- func (m *Meta) AddHistoryDDLJob(job *model.Job, updateRawArgs bool) error
- func (m *Meta) AdvanceGlobalIDs(n int) (int64, error)
- func (m *Meta) CheckDDLTableExists() (bool, error)
- func (m *Meta) CheckMDLTableExists() (bool, error)
- func (m *Meta) ClearALLDDLJob() error
- func (m *Meta) ClearAllDDLReorgHandle() error
- func (m *Meta) ClearAllHistoryJob() 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) DDLJobQueueLen(jobListKeys ...JobListKeyType) (int64, error)
- func (m *Meta) DeQueueDDLJob() (*model.Job, error)
- func (m *Meta) DropDatabase(dbID int64) error
- func (m *Meta) DropPolicy(policyID 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) EnQueueDDLJobNoUpdate(job *model.Job, jobListKeys ...JobListKeyType) error
- 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) GetDDLJobByIdx(index int64, jobListKeys ...JobListKeyType) (*model.Job, error)
- func (m *Meta) GetDDLReorgHandle(job *model.Job) (element *Element, startKey, endKey kv.Key, physicalTableID int64, err 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) 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) IsConcurrentDDL() (bool, error)
- func (m *Meta) ListDatabases() ([]*model.DBInfo, error)
- func (m *Meta) ListPolicies() ([]*model.PolicyInfo, error)
- func (m *Meta) ListTables(dbID int64) ([]*model.TableInfo, error)
- func (m *Meta) RemoveDDLReorgHandle(job *model.Job, elements []*Element) error
- func (m *Meta) RemoveReorgElement(job *model.Job) error
- func (m *Meta) RestartSequenceValue(dbID int64, tableInfo *model.TableInfo, seqValue int64) error
- func (m *Meta) SetConcurrentDDL(b bool) error
- func (m *Meta) SetDDLTables() error
- func (m *Meta) SetMDLTables() error
- func (m *Meta) SetMetadataLock(b bool) error
- func (m *Meta) SetSchemaDiff(diff *model.SchemaDiff) error
- func (m *Meta) UpdateDDLJob(index int64, job *model.Job, updateRawArgs bool, jobListKeys ...JobListKeyType) error
- func (m *Meta) UpdateDDLReorgHandle(jobID int64, startKey, endKey kv.Key, physicalTableID int64, element *Element) error
- func (m *Meta) UpdateDDLReorgStartHandle(job *model.Job, element *Element, startKey kv.Key) error
- func (m *Meta) UpdateDatabase(dbInfo *model.DBInfo) error
- func (m *Meta) UpdatePolicy(policy *model.PolicyInfo) 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) // 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 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 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, jobListKeys ...JobListKeyType) *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) AdvanceGlobalIDs ¶
AdvanceGlobalIDs advances the global ID by n. return the old global ID.
func (*Meta) CheckDDLTableExists ¶
CheckDDLTableExists check if the tables related to concurrent DDL exists.
func (*Meta) CheckMDLTableExists ¶
CheckMDLTableExists check if the tables related to concurrent DDL exists.
func (*Meta) ClearALLDDLJob ¶
ClearALLDDLJob clears all DDL jobs.
func (*Meta) ClearAllDDLReorgHandle ¶
ClearAllDDLReorgHandle clears all reorganization related handles.
func (*Meta) ClearAllHistoryJob ¶
ClearAllHistoryJob clears all history jobs. **IT IS VERY DANGEROUS**
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) DDLJobQueueLen ¶
func (m *Meta) DDLJobQueueLen(jobListKeys ...JobListKeyType) (int64, error)
DDLJobQueueLen returns the DDL job queue length. 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) DeQueueDDLJob ¶
DeQueueDDLJob pops a DDL job from the list.
func (*Meta) DropDatabase ¶
DropDatabase drops whole database.
func (*Meta) DropPolicy ¶
DropPolicy drops the specified policy.
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) EnQueueDDLJobNoUpdate ¶
func (m *Meta) EnQueueDDLJobNoUpdate(job *model.Job, jobListKeys ...JobListKeyType) error
EnQueueDDLJobNoUpdate adds a DDL job to the list without update raw args.
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) GetDDLJobByIdx ¶
GetDDLJobByIdx returns the corresponding DDL job by the index. 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) GetDDLReorgHandle ¶
func (m *Meta) GetDDLReorgHandle(job *model.Job) (element *Element, startKey, endKey kv.Key, physicalTableID int64, err error)
GetDDLReorgHandle gets the latest processed DDL reorganize position.
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) 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) IsConcurrentDDL ¶
IsConcurrentDDL returns true if the concurrent DDL flag is set.
func (*Meta) ListDatabases ¶
ListDatabases shows all databases.
func (*Meta) ListPolicies ¶
func (m *Meta) ListPolicies() ([]*model.PolicyInfo, error)
ListPolicies shows all policies.
func (*Meta) ListTables ¶
ListTables shows all tables in database.
func (*Meta) RemoveDDLReorgHandle ¶
RemoveDDLReorgHandle removes the job reorganization related handles.
func (*Meta) RemoveReorgElement ¶
RemoveReorgElement removes the element of the reorganization information.
func (*Meta) RestartSequenceValue ¶
RestartSequenceValue resets the the sequence value.
func (*Meta) SetConcurrentDDL ¶
SetConcurrentDDL set the concurrent DDL flag.
func (*Meta) SetDDLTables ¶
SetDDLTables write a key into storage.
func (*Meta) SetMDLTables ¶
SetMDLTables 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) UpdateDDLJob ¶
func (m *Meta) UpdateDDLJob(index int64, job *model.Job, updateRawArgs bool, jobListKeys ...JobListKeyType) error
UpdateDDLJob updates the DDL job with index. updateRawArgs is used to determine whether to update the raw args when encode the job. 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) UpdateDDLReorgHandle ¶
func (m *Meta) UpdateDDLReorgHandle(jobID int64, startKey, endKey kv.Key, physicalTableID int64, element *Element) error
UpdateDDLReorgHandle saves the job reorganization latest processed information for later resuming.
func (*Meta) UpdateDDLReorgStartHandle ¶
UpdateDDLReorgStartHandle saves the job reorganization latest processed element and start handle for later resuming.
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.