shardmeta

package
v0.0.0-...-8ba21cc Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DDLItem

type DDLItem struct {
	FirstLocation binlog.Location `json:"-"`      // 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

	// just used for json's marshal and unmarshal, because gtid set in FirstLocation is interface,
	// can't be marshal and unmarshal
	FirstPosition mysql.Position `json:"first-position"`
	FirstGTIDSet  string         `json:"first-gtid-set"`
}

DDLItem records ddl information used in sharding sequence organization.

func NewDDLItem

func NewDDLItem(location binlog.Location, 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, enableGTID bool) *ShardingMeta

NewShardingMeta creates a new ShardingMeta.

func (*ShardingMeta) ActiveDDLFirstLocation

func (meta *ShardingMeta) ActiveDDLFirstLocation() (binlog.Location, error)

ActiveDDLFirstLocation 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, which means len(source.Items) > len(global.Items), 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) CheckAndUpdate

func (meta *ShardingMeta) CheckAndUpdate(logger log.Logger, targetID string, schemaMap map[string]string, tablesMap map[string]map[string]string) ([]string, [][]interface{}, error)

CheckAndUpdate check and fix schema and table names for all the sharding groups.

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

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, flavor string) 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