proto

package
v2.0.0-alpha4+incompat... Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2015 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TableBaseTable indicates the table type is a base table.
	TableBaseTable = "BASE TABLE"
	// TableView indicates the table type is a view.
	TableView = "VIEW"
)

Variables

This section is empty.

Functions

func DbPermissionToProto

func DbPermissionToProto(d *DbPermission) *pbt.DbPermission

DbPermissionToProto translates a DbPermission to proto

func DiffPermissions

func DiffPermissions(leftName string, left *Permissions, rightName string, right *Permissions, er concurrency.ErrorRecorder)

func DiffPermissionsToArray

func DiffPermissionsToArray(leftName string, left *Permissions, rightName string, right *Permissions) (result []string)

func DiffSchema

func DiffSchema(leftName string, left *SchemaDefinition, rightName string, right *SchemaDefinition, er concurrency.ErrorRecorder)

DiffSchema generates a report on what's different between two SchemaDefinitions including views.

func DiffSchemaToArray

func DiffSchemaToArray(leftName string, left *SchemaDefinition, rightName string, right *SchemaDefinition) (result []string)

DiffSchemaToArray diffs two schemas and return the schema diffs if there is any.

func EncodeGTID

func EncodeGTID(gtid GTID) string

EncodeGTID returns a string that contains both the flavor and value of the GTID, so that the correct parser can be selected when that string is passed to DecodeGTID.

func EncodeReplicationPosition

func EncodeReplicationPosition(rp ReplicationPosition) string

EncodeReplicationPosition returns a string that contains both the flavor and value of the ReplicationPosition, so that the correct parser can be selected when that string is passed to DecodeReplicationPosition.

func HostPermissionToProto

func HostPermissionToProto(h *HostPermission) *pbt.HostPermission

HostPermissionToProto translates a HostPermission to proto

func PermissionsToProto

func PermissionsToProto(h *Permissions) *pbt.Permissions

PermissionsToProto translates a Permissions to proto

func ReplicationStatusToProto

func ReplicationStatusToProto(r ReplicationStatus) *pb.Status

ReplicationStatusToProto translates a ReplicationStatus to proto, or panics

func SchemaDefinitionToProto

func SchemaDefinitionToProto(s *SchemaDefinition) *pbt.SchemaDefinition

SchemaDefinitionToProto translates a SchemaDefinition to proto

func TableDefinitionToProto

func TableDefinitionToProto(t *TableDefinition) *pbt.TableDefinition

TableDefinitionToProto translates a TableDefinition to proto

func UserPermissionToProto

func UserPermissionToProto(u *UserPermission) *pbt.UserPermission

UserPermissionToProto translates a UserPermission to proto

Types

type DbPermission

type DbPermission struct {
	Host       string
	Db         string
	User       string
	Privileges map[string]string
}

DbPermission describes a single row in the mysql.db table Primary key is Host+Db+User

func NewDbPermission

func NewDbPermission(fields []proto.Field, values []sqltypes.Value) *DbPermission

func ProtoToDbPermission

func ProtoToDbPermission(d *pbt.DbPermission) *DbPermission

ProtoToDbPermission translates a proto to a DbPermission

func (*DbPermission) PrimaryKey

func (dp *DbPermission) PrimaryKey() string

func (*DbPermission) String

func (dp *DbPermission) String() string

type DbPermissionList

type DbPermissionList []*DbPermission

func (DbPermissionList) Get

func (upl DbPermissionList) Get(i int) Permission

func (DbPermissionList) Len

func (upl DbPermissionList) Len() int

type GTID

type GTID interface {
	// String returns the canonical printed form of the GTID as expected by a
	// particular flavor of MySQL.
	String() string

	// Flavor returns the key under which the corresponding GTID parser function
	// is registered in the gtidParsers map.
	Flavor() string

	// SourceServer returns the ID of the server that generated the transaction.
	SourceServer() interface{}

	// SequenceNumber returns the ID number that increases with each transaction.
	// It is only valid to compare the sequence numbers of two GTIDs if they have
	// the same domain value.
	SequenceNumber() interface{}

	// SequenceDomain returns the ID of the domain within which two sequence
	// numbers can be meaningfully compared.
	SequenceDomain() interface{}

	// GTIDSet returns a GTIDSet of the same flavor as this GTID, containing only
	// this GTID.
	GTIDSet() GTIDSet
}

GTID represents a Global Transaction ID, also known as Transaction Group ID. Each flavor of MySQL has its own format for the GTID. This interface is used along with various MysqlFlavor implementations to abstract the differences.

Types that implement GTID should use a non-pointer receiver. This ensures that comparing GTID interface values with == has the expected semantics.

func DecodeGTID

func DecodeGTID(s string) (GTID, error)

DecodeGTID converts a string in the format returned by EncodeGTID back into a GTID interface value with the correct underlying flavor.

func MustDecodeGTID

func MustDecodeGTID(s string) GTID

MustDecodeGTID calls DecodeGTID and panics on error.

func MustParseGTID

func MustParseGTID(flavor, value string) GTID

MustParseGTID calls ParseGTID and panics on error.

func ParseGTID

func ParseGTID(flavor, value string) (GTID, error)

ParseGTID calls the GTID parser for the specified flavor.

type GTIDField

type GTIDField struct {
	Value GTID
}

GTIDField is a concrete struct that contains a GTID interface value. This can be used as a field inside marshalable structs, which cannot contain interface values because there would be no way to know which concrete type to instantiate upon unmarshaling.

Note: GTIDField should not implement GTID, because it would tend to create subtle bugs. For example, the compiler would allow something like this:

GTIDField{googleGTID{1234}} == googleGTID{1234}

But it would evaluate to false (because the underlying types don't match), which is probably not what was expected.

func (GTIDField) MarshalBson

func (gf GTIDField) MarshalBson(buf *bytes2.ChunkedWriter, key string)

MarshalBson bson-encodes GTIDField.

func (GTIDField) MarshalJSON

func (gf GTIDField) MarshalJSON() ([]byte, error)

MarshalJSON implements encoding/json.Marshaler.

func (GTIDField) String

func (gf GTIDField) String() string

String returns a string representation of the underlying GTID. If the GTID value is nil, it returns "<nil>" in the style of Sprintf("%v", nil).

func (*GTIDField) UnmarshalBson

func (gf *GTIDField) UnmarshalBson(buf *bytes.Buffer, kind byte)

UnmarshalBson bson-decodes into GTIDField.

func (*GTIDField) UnmarshalJSON

func (gf *GTIDField) UnmarshalJSON(buf []byte) error

UnmarshalJSON implements encoding/json.Unmarshaler.

type GTIDSet

type GTIDSet interface {
	// String returns the canonical printed form of the set as expected by a
	// particular flavor of MySQL.
	String() string

	// Flavor returns the key under which the corresponding parser function is
	// registered in the transactionSetParsers map.
	Flavor() string

	// ContainsGTID returns true if the set contains the specified transaction.
	ContainsGTID(GTID) bool

	// Contains returns true if the set is a superset of another set.
	Contains(GTIDSet) bool

	// Equal returns true if the set is equal to another set.
	Equal(GTIDSet) bool

	// AddGTID returns a new GTIDSet that is expanded to contain the given GTID.
	AddGTID(GTID) GTIDSet
}

GTIDSet represents the set of transactions received or applied by a server. In some flavors, a single GTID is enough to specify the set of all transactions that came before it, but in others a more complex structure is required.

GTIDSet is wrapped by ReplicationPosition, which is a concrete struct that enables JSON and BSON marshaling. Most code outside of this package should use ReplicationPosition rather than GTIDSet.

type HostPermission

type HostPermission struct {
	Host       string
	Db         string
	Privileges map[string]string
}

HostPermission describes a single row in the mysql.host table Primary key is Host+Db

func NewHostPermission

func NewHostPermission(fields []proto.Field, values []sqltypes.Value) *HostPermission

func ProtoToHostPermission

func ProtoToHostPermission(h *pbt.HostPermission) *HostPermission

ProtoToHostPermission translates a proto to a HostPermission

func (*HostPermission) PrimaryKey

func (hp *HostPermission) PrimaryKey() string

func (*HostPermission) String

func (hp *HostPermission) String() string

type HostPermissionList

type HostPermissionList []*HostPermission

func (HostPermissionList) Get

func (upl HostPermissionList) Get(i int) Permission

func (HostPermissionList) Len

func (upl HostPermissionList) Len() int

type MariadbGTID

type MariadbGTID struct {
	// Domain is the ID number of the domain within which sequence numbers apply.
	Domain uint32
	// Server is the ID of the server that generated the transaction.
	Server uint32
	// Sequence is the sequence number of the transaction within the domain.
	Sequence uint64
}

MariadbGTID implements GTID.

func (MariadbGTID) AddGTID

func (gtid MariadbGTID) AddGTID(other GTID) GTIDSet

AddGTID implements GTIDSet.AddGTID().

func (MariadbGTID) Contains

func (gtid MariadbGTID) Contains(other GTIDSet) bool

Contains implements GTIDSet.Contains().

func (MariadbGTID) ContainsGTID

func (gtid MariadbGTID) ContainsGTID(other GTID) bool

ContainsGTID implements GTIDSet.ContainsGTID().

func (MariadbGTID) Equal

func (gtid MariadbGTID) Equal(other GTIDSet) bool

Equal implements GTIDSet.Equal().

func (MariadbGTID) Flavor

func (gtid MariadbGTID) Flavor() string

Flavor implements GTID.Flavor().

func (MariadbGTID) GTIDSet

func (gtid MariadbGTID) GTIDSet() GTIDSet

GTIDSet implements GTID.GTIDSet().

func (MariadbGTID) SequenceDomain

func (gtid MariadbGTID) SequenceDomain() interface{}

SequenceDomain implements GTID.SequenceDomain().

func (MariadbGTID) SequenceNumber

func (gtid MariadbGTID) SequenceNumber() interface{}

SequenceNumber implements GTID.SequenceNumber().

func (MariadbGTID) SourceServer

func (gtid MariadbGTID) SourceServer() interface{}

SourceServer implements GTID.SourceServer().

func (MariadbGTID) String

func (gtid MariadbGTID) String() string

String implements GTID.String().

type Mysql56GTID

type Mysql56GTID struct {
	// Server is the SID of the server that originally committed the transaction.
	Server SID
	// Sequence is the sequence number of the transaction within a given Server's
	// scope.
	Sequence int64
}

Mysql56GTID implements GTID

func (Mysql56GTID) Flavor

func (gtid Mysql56GTID) Flavor() string

Flavor implements GTID.Flavor().

func (Mysql56GTID) GTIDSet

func (gtid Mysql56GTID) GTIDSet() GTIDSet

GTIDSet implements GTID.GTIDSet().

func (Mysql56GTID) SequenceDomain

func (gtid Mysql56GTID) SequenceDomain() interface{}

SequenceDomain implements GTID.SequenceDomain().

func (Mysql56GTID) SequenceNumber

func (gtid Mysql56GTID) SequenceNumber() interface{}

SequenceNumber implements GTID.SequenceNumber().

func (Mysql56GTID) SourceServer

func (gtid Mysql56GTID) SourceServer() interface{}

SourceServer implements GTID.SourceServer().

func (Mysql56GTID) String

func (gtid Mysql56GTID) String() string

String implements GTID.String().

type Mysql56GTIDSet

type Mysql56GTIDSet map[SID][]interval

Mysql56GTIDSet implements GTIDSet for MySQL 5.6.

func (Mysql56GTIDSet) AddGTID

func (set Mysql56GTIDSet) AddGTID(gtid GTID) GTIDSet

AddGTID implements GTIDSet.

func (Mysql56GTIDSet) Contains

func (set Mysql56GTIDSet) Contains(other GTIDSet) bool

Contains implements GTIDSet.

func (Mysql56GTIDSet) ContainsGTID

func (set Mysql56GTIDSet) ContainsGTID(gtid GTID) bool

ContainsGTID implements GTIDSet.

func (Mysql56GTIDSet) Equal

func (set Mysql56GTIDSet) Equal(other GTIDSet) bool

Equal implements GTIDSet.

func (Mysql56GTIDSet) Flavor

func (Mysql56GTIDSet) Flavor() string

Flavor implements GTIDSet.

func (Mysql56GTIDSet) SIDBlock

func (set Mysql56GTIDSet) SIDBlock() []byte

SIDBlock returns the binary encoding of a MySQL 5.6 GTID set as expected by internal commands that refer to an "SID block".

e.g. https://dev.mysql.com/doc/internals/en/com-binlog-dump-gtid.html

func (Mysql56GTIDSet) SIDs

func (set Mysql56GTIDSet) SIDs() []SID

SIDs returns a sorted list of SIDs in the set.

func (Mysql56GTIDSet) String

func (set Mysql56GTIDSet) String() string

String implements GTIDSet.

type Permission

type Permission interface {
	PrimaryKey() string
	String() string
}

type PermissionList

type PermissionList interface {
	Get(int) Permission
	Len() int
}

type Permissions

type Permissions struct {
	UserPermissions UserPermissionList
	DbPermissions   DbPermissionList
	HostPermissions HostPermissionList
}

Permissions have all the rows in mysql.{user,db,host} tables, (all rows are sorted by primary key)

func ProtoToPermissions

func ProtoToPermissions(h *pbt.Permissions) *Permissions

ProtoToPermissions translates a proto to a Permissions

func (*Permissions) String

func (permissions *Permissions) String() string

type ReplicationPosition

type ReplicationPosition struct {
	GTIDSet GTIDSet
	// contains filtered or unexported fields
}

ReplicationPosition represents the information necessary to describe which transactions a server has seen, so that it can request a replication stream from a new master that picks up where it left off.

This must be a concrete struct because custom Unmarshalers can't be registered on an interface.

The == operator should not be used with ReplicationPosition, because the underlying GTIDSet might use slices, which are not comparable. Using == in those cases will result in a run-time panic.

func AppendGTID

func AppendGTID(rp ReplicationPosition, gtid GTID) ReplicationPosition

AppendGTID returns a new ReplicationPosition that represents the position after the given GTID is replicated.

func DecodeReplicationPosition

func DecodeReplicationPosition(s string) (rp ReplicationPosition, err error)

DecodeReplicationPosition converts a string in the format returned by EncodeReplicationPosition back into a ReplicationPosition value with the correct underlying flavor.

func MustParseReplicationPosition

func MustParseReplicationPosition(flavor, value string) ReplicationPosition

MustParseReplicationPosition calls ParseReplicationPosition and panics on error.

func ParseReplicationPosition

func ParseReplicationPosition(flavor, value string) (rp ReplicationPosition, err error)

ParseReplicationPosition calls the parser for the specified flavor.

func (ReplicationPosition) AtLeast

func (rp ReplicationPosition) AtLeast(other ReplicationPosition) bool

AtLeast returns true if this position is equal to or after another.

func (ReplicationPosition) Equal

Equal returns true if this position is equal to another.

func (ReplicationPosition) IsZero

func (rp ReplicationPosition) IsZero() bool

IsZero returns true if this is the zero value, ReplicationPosition{}.

func (ReplicationPosition) MarshalBson

func (rp ReplicationPosition) MarshalBson(buf *bytes2.ChunkedWriter, key string)

MarshalBson bson-encodes ReplicationPosition.

func (ReplicationPosition) MarshalJSON

func (rp ReplicationPosition) MarshalJSON() ([]byte, error)

MarshalJSON implements encoding/json.Marshaler.

func (ReplicationPosition) String

func (rp ReplicationPosition) String() string

String returns a string representation of the underlying GTIDSet. If the set is nil, it returns "<nil>" in the style of Sprintf("%v", nil).

func (*ReplicationPosition) UnmarshalBson

func (rp *ReplicationPosition) UnmarshalBson(buf *bytes.Buffer, kind byte)

UnmarshalBson bson-decodes into ReplicationPosition.

func (*ReplicationPosition) UnmarshalJSON

func (rp *ReplicationPosition) UnmarshalJSON(buf []byte) error

UnmarshalJSON implements encoding/json.Unmarshaler.

type ReplicationStatus

type ReplicationStatus struct {
	Position            ReplicationPosition
	SlaveIORunning      bool
	SlaveSQLRunning     bool
	SecondsBehindMaster uint
	MasterHost          string
	MasterPort          int
	MasterConnectRetry  int
}

ReplicationStatus holds replication information from SHOW SLAVE STATUS.

func NewReplicationStatus

func NewReplicationStatus(masterAddr string) (*ReplicationStatus, error)

NewReplicationStatus creates a ReplicationStatus pointing to masterAddr.

func ProtoToReplicationStatus

func ProtoToReplicationStatus(r *pb.Status) ReplicationStatus

ProtoToReplicationStatus translates a proto ReplicationStatus, or panics

func (*ReplicationStatus) MasterAddr

func (rs *ReplicationStatus) MasterAddr() string

MasterAddr returns the host:port address of the master.

func (*ReplicationStatus) SlaveRunning

func (rs *ReplicationStatus) SlaveRunning() bool

SlaveRunning returns true iff both the Slave IO and Slave SQL threads are running.

type SID

type SID [16]byte

SID is the 16-byte unique ID of a MySQL 5.6 server.

func ParseSID

func ParseSID(s string) (sid SID, err error)

ParseSID parses an SID in the form used by MySQL 5.6.

func (SID) String

func (sid SID) String() string

String prints an SID in the form used by MySQL 5.6.

type SchemaChange

type SchemaChange struct {
	Sql              string
	Force            bool
	AllowReplication bool
	BeforeSchema     *SchemaDefinition
	AfterSchema      *SchemaDefinition
}

SchemaChange contains all necessary information to apply a schema change.

type SchemaChangeResult

type SchemaChangeResult struct {
	BeforeSchema *SchemaDefinition
	AfterSchema  *SchemaDefinition
}

SchemaChangeResult contains before and after table schemas for a schema change sql.

type SchemaDefinition

type SchemaDefinition struct {
	// the 'CREATE DATABASE...' statement, with db name as {{.DatabaseName}}
	DatabaseSchema string

	// ordered by TableDefinition.Name by default
	TableDefinitions TableDefinitions

	// the md5 of the concatenation of TableDefinition.Schema
	Version string
}

SchemaDefinition defines schema for a certain database.

func ProtoToSchemaDefinition

func ProtoToSchemaDefinition(s *pbt.SchemaDefinition) *SchemaDefinition

ProtoToSchemaDefinition translates a proto to a SchemaDefinition

func (*SchemaDefinition) FilterTables

func (sd *SchemaDefinition) FilterTables(tables, excludeTables []string, includeViews bool) (*SchemaDefinition, error)

FilterTables returns a copy which includes only whitelisted tables (tables), no blacklisted tables (excludeTables) and optionally views (includeViews).

func (*SchemaDefinition) GenerateSchemaVersion

func (sd *SchemaDefinition) GenerateSchemaVersion()

GenerateSchemaVersion return a unique schema version string based on its TableDefinitions.

func (*SchemaDefinition) GetTable

func (sd *SchemaDefinition) GetTable(table string) (td *TableDefinition, ok bool)

GetTable returns TableDefinition for a given table name.

func (*SchemaDefinition) ToSQLStrings

func (sd *SchemaDefinition) ToSQLStrings() []string

ToSQLStrings converts a SchemaDefinition to an array of SQL strings. The array contains all the SQL statements needed for creating the database, tables, and views - in that order. All SQL statements will have {{.DatabaseName}} in place of the actual db name.

type TableDefinition

type TableDefinition struct {
	Name              string   // the table name
	Schema            string   // the SQL to run to create the table
	Columns           []string // the columns in the order that will be used to dump and load the data
	PrimaryKeyColumns []string // the columns used by the primary key, in order
	Type              string   // TableBaseTable or TableView
	DataLength        uint64   // how much space the data file takes.
	RowCount          uint64   // how many rows in the table (may

}

TableDefinition contains all schema information about a table.

func ProtoToTableDefinition

func ProtoToTableDefinition(t *pbt.TableDefinition) *TableDefinition

ProtoToTableDefinition translates a proto into a TableDefinition

type TableDefinitions

type TableDefinitions []*TableDefinition

TableDefinitions is a list of TableDefinition.

func (TableDefinitions) Len

func (tds TableDefinitions) Len() int

Len returns TableDefinitions length.

func (TableDefinitions) Swap

func (tds TableDefinitions) Swap(i, j int)

Swap used for sorting TableDefinitions.

type UserPermission

type UserPermission struct {
	Host             string
	User             string
	PasswordChecksum uint64
	Privileges       map[string]string
}

UserPermission describes a single row in the mysql.user table Primary key is Host+User PasswordChecksum is the crc64 of the password, for security reasons

func NewUserPermission

func NewUserPermission(fields []proto.Field, values []sqltypes.Value) *UserPermission

func ProtoToUserPermission

func ProtoToUserPermission(u *pbt.UserPermission) *UserPermission

ProtoToUserPermission translates a proto to a UserPermission

func (*UserPermission) PrimaryKey

func (up *UserPermission) PrimaryKey() string

func (*UserPermission) String

func (up *UserPermission) String() string

type UserPermissionList

type UserPermissionList []*UserPermission

func (UserPermissionList) Get

func (upl UserPermissionList) Get(i int) Permission

func (UserPermissionList) Len

func (upl UserPermissionList) Len() int

Jump to

Keyboard shortcuts

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