shardmeta

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MetaTableFormat is used in meta table name constructor
	MetaTableFormat = "%s_syncer_sharding_meta"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DDLItem

type DDLItem struct {
	FirstPos mysql.Position `json:"first-pos"` // first DDL's binlog Pos, not the End_log_pos of the event
	DDLs     []string       `json:"ddls"`      // DDLs, these ddls are in the same QueryEvent
	Source   string         `json:"source"`    // source table ID
}

DDLItem records ddl information used in sharding sequence organization

func NewDDLItem

func NewDDLItem(pos mysql.Position, ddls []string, source string) *DDLItem

NewDDLItem creates a new DDLItem

func (*DDLItem) String

func (item *DDLItem) String() string

String returns the item's format string value

type ShardingMeta

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

ShardingMeta stores sharding ddl sequence including global sequence and each source's own sequence NOTE: sharding meta is not thread safe, it must be used in thread safe context

func NewShardingMeta

func NewShardingMeta(schema, table string) *ShardingMeta

NewShardingMeta creates a new ShardingMeta

func (*ShardingMeta) ActiveDDLFirstPos

func (meta *ShardingMeta) ActiveDDLFirstPos() (mysql.Position, error)

ActiveDDLFirstPos returns the first binlog position of active DDL

func (*ShardingMeta) ActiveIdx

func (meta *ShardingMeta) ActiveIdx() int

ActiveIdx returns the activeIdx of sharding meta

func (*ShardingMeta) AddItem

func (meta *ShardingMeta) AddItem(item *DDLItem) (active bool, err error)

AddItem adds a new coming DDLItem into ShardingMeta 1. if DDLItem already exists in source sequence, check whether it is active DDL only 2. add the DDLItem into its related source sequence 3. if it is a new DDL in global sequence, add it into global sequence 4. check the source sequence is the prefix-sequence of global sequence, if not, return an error returns:

active: whether the DDL will be processed in this round

func (*ShardingMeta) FlushData

func (meta *ShardingMeta) FlushData(sourceID, tableID string) ([]string, [][]interface{})

FlushData returns sharding meta flush SQL and args

func (*ShardingMeta) GetActiveDDLItem

func (meta *ShardingMeta) GetActiveDDLItem(tableSource string) *DDLItem

GetActiveDDLItem returns the source table's active DDLItem if in DDL unsynced procedure, the active DDLItem means the syncing DDL if in re-sync procedure, the active DDLItem means the next syncing DDL in DDL syncing sequence, may be nil

func (*ShardingMeta) GetGlobalActiveDDL

func (meta *ShardingMeta) GetGlobalActiveDDL() *DDLItem

GetGlobalActiveDDL returns activeDDL in global sequence

func (*ShardingMeta) GetGlobalItems

func (meta *ShardingMeta) GetGlobalItems() []*DDLItem

GetGlobalItems returns global DDLItems

func (*ShardingMeta) InSequenceSharding

func (meta *ShardingMeta) InSequenceSharding() bool

InSequenceSharding returns whether in sequence sharding

func (*ShardingMeta) Reinitialize added in v1.0.6

func (meta *ShardingMeta) Reinitialize()

Reinitialize reinitialize the shardingmeta

func (*ShardingMeta) ResolveShardingDDL

func (meta *ShardingMeta) ResolveShardingDDL() bool

ResolveShardingDDL resolves one sharding DDL and increase activeIdx if activeIdx equals to the length of global sharding sequence, it means all sharding DDL in this ShardingMeta sequence is resolved and will reinitialize the ShardingMeta, return true if all DDLs are resolved.

func (*ShardingMeta) RestoreFromData

func (meta *ShardingMeta) RestoreFromData(sourceTableID string, activeIdx int, isGlobal bool, data []byte) error

RestoreFromData restores ShardingMeta from given data

type ShardingSequence

type ShardingSequence struct {
	Items []*DDLItem `json:"items"`
}

ShardingSequence records a list of DDLItem

func (*ShardingSequence) IsPrefixSequence

func (seq *ShardingSequence) IsPrefixSequence(other *ShardingSequence) bool

IsPrefixSequence checks whether a ShardingSequence is the prefix sequence of other.

func (*ShardingSequence) String

func (seq *ShardingSequence) String() string

String returns the ShardingSequence's json string

Jump to

Keyboard shortcuts

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