schema

package
v0.0.0-...-64b8ef3 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StorageType_Boltdb string = "boltdb"
	StorageType_Mysql  string = "mysql"
)
View Source
const (
	TypeDecimal   byte = 0
	TypeTiny      byte = 1
	TypeShort     byte = 2
	TypeLong      byte = 3
	TypeFloat     byte = 4
	TypeDouble    byte = 5
	TypeNull      byte = 6
	TypeTimestamp byte = 7
	TypeLonglong  byte = 8
	TypeInt24     byte = 9
	TypeDate      byte = 10
	/* Original name was TypeTime, renamed to Duration to resolve the conflict with Go type Time.*/
	TypeDuration byte = 11
	TypeDatetime byte = 12
	TypeYear     byte = 13
	TypeNewDate  byte = 14
	TypeVarchar  byte = 15
	TypeBit      byte = 16

	TypeJSON       byte = 0xf5
	TypeNewDecimal byte = 0xf6
	TypeEnum       byte = 0xf7
	TypeSet        byte = 0xf8
	TypeTinyBlob   byte = 0xf9
	TypeMediumBlob byte = 0xfa
	TypeLongBlob   byte = 0xfb
	TypeBlob       byte = 0xfc
	TypeVarString  byte = 0xfd
	TypeString     byte = 0xfe
	TypeGeometry   byte = 0xff
)

MySQL type information.

View Source
const (
	IndexType_NONE IndexType = ""
	IndexType_PRI            = "PRI"
	IndexType_UNI            = "UNI"
	IndexType_MUL            = "MUL"
)

Variables

View Source
var HAHealthCheckSchema = "mysql.ha_health_check"

Functions

func NewBoltdbStorage

func NewBoltdbStorage(path string) (*boltdbStorage, error)

func NewMysqlStorage

func NewMysqlStorage(addr string, user string, password string, database string) (*mysqlStorage, error)

Types

type ColumnDef

type ColumnDef struct {
	Name      string    `json:"name"`
	Type      string    `json:"type"`
	InnerType byte      `json:"inner_type"`
	Key       IndexType `json:"key"`
	Charset   string    `json:"charset"`
	Unsigned  bool      `json:"unsigned"`
	Nullable  bool      `json:"nullable"`
}

type IndexType

type IndexType string

type Iterator

type Iterator interface {
	First() (string, string, mysql.Position, error)
	Next() (string, string, mysql.Position, error)
	End() bool
}

type SchemaStorage

type SchemaStorage interface {
	// SaveSnapshot will be called when schema tracker decides to save a snapshot
	SaveSnapshot(data []byte, pos mysql.Position) error

	// SaveSnapshot will be called when schema tracker decides to save a ddl statement
	SaveStatement(db string, statement string, pos mysql.Position) error

	// LoadLastSnapshot will be called when schema tracker need to restore snapshot, as base data
	LoadLastSnapshot() ([]byte, mysql.Position, error)

	// Reset will be called to get a empty storage
	Reset() error

	// StatementIterator return an iterator which can iterate all ddl statements after last snapshot
	StatementIterator() Iterator
}

type SchemaTracker

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

func NewSchemaTracker

func NewSchemaTracker(cfg *TrackerConfig) (*SchemaTracker, error)

New a schema tracker that can track DDL statements, making a schema mirror.

func (*SchemaTracker) Exec

func (o *SchemaTracker) Exec(db string, statement string) error

Exec ddl statement, but don't persistent the schema info

func (*SchemaTracker) ExecAndPersist

func (o *SchemaTracker) ExecAndPersist(db string, statement string, pos mysql.Position) error

Exec ddl statement, and persistent the schema info into storage

func (*SchemaTracker) GetDatabases

func (o *SchemaTracker) GetDatabases() []string

Get all db names, like 'SHOW DATABASES'

func (*SchemaTracker) GetTableDef

func (o *SchemaTracker) GetTableDef(db string, table string) (*TableDef, error)

func (*SchemaTracker) GetTables

func (o *SchemaTracker) GetTables(db string) ([]string, error)

Get all table names in specified db, like 'SHOW TABLES'

func (*SchemaTracker) IsDdl

func (o *SchemaTracker) IsDdl(sql string) (bool, error)

Check whether the SQL statement is DDL, means not DML/DCL

func (*SchemaTracker) Persist

func (o *SchemaTracker) Persist(pos mysql.Position) error

Persistent the schema info into storage. Before Persist is called, must ensure the binlog DML events previous is synced.

func (*SchemaTracker) Reset

func (o *SchemaTracker) Reset() error

Reset executor's schema info and storage

type TableDef

type TableDef struct {
	Database string       `json:"database"`
	Name     string       `json:"name"`
	Columns  []*ColumnDef `json:"columns"`
	Charset  string       `json:"charset"`
}

type TrackerConfig

type TrackerConfig struct {
	// The charset_set_server of source mysql, we need
	// this charset to handle ddl statement
	CharsetServer string

	// Storage type to store schema data, may be boltdb or mysql
	Storage string

	// Boltdb file path to store data
	Dir string

	// MySQL info to connect
	Addr     string
	User     string
	Password string
	Database string
}

Jump to

Keyboard shortcuts

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