model

package
v0.0.0-...-c605b0d Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2017 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionType

type ActionType byte

ActionType is the type for DDL action.

const (
	ActionNone ActionType = iota
	ActionCreateSchema
	ActionDropSchema
	ActionCreateTable
	ActionDropTable
	ActionAddColumn
	ActionDropColumn
	ActionAddIndex
	ActionDropIndex
	ActionAddForeignKey
	ActionDropForeignKey
	ActionTruncateTable
	ActionModifyColumn
	ActionRenameTable
	ActionSetDefaultValue
)

List DDL actions.

func (ActionType) String

func (action ActionType) String() string

type CIStr

type CIStr struct {
	O string `json:"O"` // Original string.
	L string `json:"L"` // Lower case string.
}

CIStr is case insensitive string.

func NewCIStr

func NewCIStr(s string) (cs CIStr)

NewCIStr creates a new CIStr.

func (CIStr) String

func (cis CIStr) String() string

String implements fmt.Stringer interface.

type ColumnInfo

type ColumnInfo struct {
	ID                  int64               `json:"id"`
	Name                CIStr               `json:"name"`
	Offset              int                 `json:"offset"`
	OriginDefaultValue  interface{}         `json:"origin_default"`
	DefaultValue        interface{}         `json:"default"`
	GeneratedExprString string              `json:"generated_expr_string"`
	GeneratedStored     bool                `json:"generated_stored"`
	Dependences         map[string]struct{} `json:"dependences"`
	types.FieldType     `json:"type"`
	State               SchemaState `json:"state"`
	Comment             string      `json:"comment"`
}

ColumnInfo provides meta data describing of a table column.

func (*ColumnInfo) Clone

func (c *ColumnInfo) Clone() *ColumnInfo

Clone clones ColumnInfo.

type DBInfo

type DBInfo struct {
	ID      int64        `json:"id"`      // Database ID
	Name    CIStr        `json:"db_name"` // DB name.
	Charset string       `json:"charset"`
	Collate string       `json:"collate"`
	Tables  []*TableInfo `json:"-"` // Tables in the DB.
	State   SchemaState  `json:"state"`
}

DBInfo provides meta data describing a DB.

func (*DBInfo) Clone

func (db *DBInfo) Clone() *DBInfo

Clone clones DBInfo.

type FKInfo

type FKInfo struct {
	ID       int64       `json:"id"`
	Name     CIStr       `json:"fk_name"`
	RefTable CIStr       `json:"ref_table"`
	RefCols  []CIStr     `json:"ref_cols"`
	Cols     []CIStr     `json:"cols"`
	OnDelete int         `json:"on_delete"`
	OnUpdate int         `json:"on_update"`
	State    SchemaState `json:"state"`
}

FKInfo provides meta data describing a foreign key constraint.

func (*FKInfo) Clone

func (fk *FKInfo) Clone() *FKInfo

Clone clones FKInfo.

type HistoryInfo

type HistoryInfo struct {
	SchemaVersion int64
	DBInfo        *DBInfo
	TableInfo     *TableInfo
}

HistoryInfo is used for binlog.

func (*HistoryInfo) AddDBInfo

func (h *HistoryInfo) AddDBInfo(schemaVer int64, dbInfo *DBInfo)

AddDBInfo adds schema version and schema information that are used for binlog. dbInfo is added in the following operations: create database, drop database.

func (*HistoryInfo) AddTableInfo

func (h *HistoryInfo) AddTableInfo(schemaVer int64, tblInfo *TableInfo)

AddTableInfo adds schema version and table information that are used for binlog. tblInfo is added except for the following operations: create database, drop database.

type IndexColumn

type IndexColumn struct {
	Name   CIStr `json:"name"`   // Index name
	Offset int   `json:"offset"` // Index offset
	// Length of prefix when using column prefix
	// for indexing;
	// UnspecifedLength if not using prefix indexing
	Length int `json:"length"`
}

IndexColumn provides index column info.

func (*IndexColumn) Clone

func (i *IndexColumn) Clone() *IndexColumn

Clone clones IndexColumn.

type IndexInfo

type IndexInfo struct {
	ID      int64          `json:"id"`
	Name    CIStr          `json:"idx_name"`   // Index name.
	Table   CIStr          `json:"tbl_name"`   // Table name.
	Columns []*IndexColumn `json:"idx_cols"`   // Index columns.
	Unique  bool           `json:"is_unique"`  // Whether the index is unique.
	Primary bool           `json:"is_primary"` // Whether the index is primary key.
	State   SchemaState    `json:"state"`
	Comment string         `json:"comment"`    // Comment
	Tp      IndexType      `json:"index_type"` // Index type: Btree or Hash
}

IndexInfo provides meta data describing a DB index. It corresponds to the statement `CREATE INDEX Name ON Table (Column);` See https://dev.mysql.com/doc/refman/5.7/en/create-index.html

func (*IndexInfo) Clone

func (index *IndexInfo) Clone() *IndexInfo

Clone clones IndexInfo.

func (*IndexInfo) HasPrefixIndex

func (index *IndexInfo) HasPrefixIndex() bool

HasPrefixIndex returns whether any columns of this index uses prefix length.

type IndexType

type IndexType int

IndexType is the type of index

const (
	IndexTypeInvalid IndexType = iota
	IndexTypeBtree
	IndexTypeHash
)

IndexTypes

func (IndexType) String

func (t IndexType) String() string

String implements Stringer interface.

type Job

type Job struct {
	ID       int64         `json:"id"`
	Type     ActionType    `json:"type"`
	SchemaID int64         `json:"schema_id"`
	TableID  int64         `json:"table_id"`
	State    JobState      `json:"state"`
	Error    *terror.Error `json:"err"`
	// ErrorCount will be increased, every time we meet an error when running job.
	ErrorCount int64 `json:"err_count"`
	// RowCount means the number of rows that are processed.
	RowCount int64         `json:"row_count"`
	Mu       sync.Mutex    `json:"-"`
	Args     []interface{} `json:"-"`
	// RawArgs : We must use json raw message to delay parsing special args.
	RawArgs     json.RawMessage `json:"raw_args"`
	SchemaState SchemaState     `json:"schema_state"`
	// SnapshotVer means snapshot version for this job.
	SnapshotVer uint64 `json:"snapshot_ver"`
	// LastUpdateTS now uses unix nano seconds
	// TODO: Use timestamp allocated by TSO.
	LastUpdateTS int64 `json:"last_update_ts"`
	// Query string of the ddl job.
	Query      string       `json:"query"`
	BinlogInfo *HistoryInfo `json:"binlog"`
}

Job is for a DDL operation.

func (*Job) Decode

func (job *Job) Decode(b []byte) error

Decode decodes job from the json buffer, we must use DecodeArgs later to decode special args for this job.

func (*Job) DecodeArgs

func (job *Job) DecodeArgs(args ...interface{}) error

DecodeArgs decodes job args.

func (*Job) Encode

func (job *Job) Encode(updateRawArgs bool) ([]byte, error)

Encode encodes job with json format. updateRawArgs is used to determine whether to update the raw args.

func (*Job) GetRowCount

func (job *Job) GetRowCount() int64

GetRowCount gets the number of rows. Make sure it can pass `make race`.

func (*Job) IsCancelled

func (job *Job) IsCancelled() bool

IsCancelled returns whether the job is cancelled or not.

func (*Job) IsDone

func (job *Job) IsDone() bool

IsDone returns whether job is done.

func (*Job) IsFinished

func (job *Job) IsFinished() bool

IsFinished returns whether job is finished or not. If the job state is Done or Cancelled, it is finished.

func (*Job) IsRunning

func (job *Job) IsRunning() bool

IsRunning returns whether job is still running or not.

func (*Job) IsSynced

func (job *Job) IsSynced() bool

IsSynced returns whether the DDL modification is synced among all TiDB servers.

func (*Job) SetRowCount

func (job *Job) SetRowCount(count int64)

SetRowCount sets the number of rows. Make sure it can pass `make race`.

func (*Job) String

func (job *Job) String() string

String implements fmt.Stringer interface.

type JobState

type JobState byte

JobState is for job state.

const (
	JobNone JobState = iota
	JobRunning
	// When DDL encountered an unrecoverable error at reorganization state,
	// some keys has been added already, we need to remove them.
	// JobRollback is the state to do rollback work.
	JobRollback
	JobRollbackDone
	JobDone
	JobCancelled
	// JobSynced is used to mark the information about the completion of this job
	// has been synchronized to all servers.
	JobSynced
)

List job states.

func (JobState) String

func (s JobState) String() string

String implements fmt.Stringer interface.

type SchemaDiff

type SchemaDiff struct {
	Version  int64      `json:"version"`
	Type     ActionType `json:"type"`
	SchemaID int64      `json:"schema_id"`
	TableID  int64      `json:"table_id"`

	// OldTableID is the table ID before truncate, only used by truncate table DDL.
	OldTableID int64 `json:"old_table_id"`
	// OldSchemaID is the schema ID before rename table, only used by rename table DDL.
	OldSchemaID int64 `json:"old_schema_id"`
}

SchemaDiff contains the schema modification at a particular schema version. It is used to reduce schema reload cost.

type SchemaState

type SchemaState byte

SchemaState is the state for schema elements.

const (
	// StateNone means this schema element is absent and can't be used.
	StateNone SchemaState = iota
	// StateDeleteOnly means we can only delete items for this schema element.
	StateDeleteOnly
	// StateWriteOnly means we can use any write operation on this schema element,
	// but outer can't read the changed data.
	StateWriteOnly
	// StateWriteReorganization means we are re-organizating whole data after write only state.
	StateWriteReorganization
	// StateDeleteReorganization means we are re-organizating whole data after delete only state.
	StateDeleteReorganization
	// StatePublic means this schema element is ok for all write and read operations.
	StatePublic
)

func (SchemaState) String

func (s SchemaState) String() string

String implements fmt.Stringer interface.

type TableInfo

type TableInfo struct {
	ID      int64  `json:"id"`
	Name    CIStr  `json:"name"`
	Charset string `json:"charset"`
	Collate string `json:"collate"`
	// Columns are listed in the order in which they appear in the schema.
	Columns     []*ColumnInfo `json:"cols"`
	Indices     []*IndexInfo  `json:"index_info"`
	ForeignKeys []*FKInfo     `json:"fk_info"`
	State       SchemaState   `json:"state"`
	PKIsHandle  bool          `json:"pk_is_handle"`
	Comment     string        `json:"comment"`
	AutoIncID   int64         `json:"auto_inc_id"`
	MaxColumnID int64         `json:"max_col_id"`
	MaxIndexID  int64         `json:"max_idx_id"`
	// OldSchemaID :
	// Because auto increment ID has schemaID as prefix,
	// We need to save original schemaID to keep autoID unchanged
	// while renaming a table from one database to another.
	OldSchemaID int64 `json:"old_schema_id,omitempty"`
}

TableInfo provides meta data describing a DB table.

func (*TableInfo) Clone

func (t *TableInfo) Clone() *TableInfo

Clone clones TableInfo.

func (*TableInfo) ColumnIsInIndex

func (t *TableInfo) ColumnIsInIndex(c *ColumnInfo) bool

ColumnIsInIndex checks whether c is included in any indices of t.

func (*TableInfo) GetPkColInfo

func (t *TableInfo) GetPkColInfo() *ColumnInfo

GetPkColInfo gets the ColumnInfo of pk if exists. Make sure PkIsHandle checked before call this method.

func (*TableInfo) GetPkName

func (t *TableInfo) GetPkName() CIStr

GetPkName will return the pk name if pk exists.

Jump to

Keyboard shortcuts

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