db

package
v0.14.5 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrGroupSplitBrain is the error when mysql group is split-brain
	ErrGroupSplitBrain = errors.New("group has split brain")
	// ErrGroupBackoffError is either the transient error or network partition from the group
	ErrGroupBackoffError = errors.New("group backoff error")
	// ErrGroupOngoingBootstrap is the error when a bootstrap is in progress
	ErrGroupOngoingBootstrap = errors.New("group ongoing bootstrap")
	// ErrGroupInactive is the error when mysql group is inactive unexpectedly
	ErrGroupInactive = errors.New("group is inactive")
	// ErrInvalidInstance is the error when the instance key has empty hostname
	ErrInvalidInstance = errors.New("invalid mysql instance key")
)

Functions

This section is empty.

Types

type Agent

type Agent interface {
	// BootstrapGroupLocked bootstraps a mysql group
	// the caller should grab a lock before
	BootstrapGroupLocked(instanceKey *inst.InstanceKey) error

	// RebootstrapGroupLocked rebootstrap a group with an existing name
	RebootstrapGroupLocked(instanceKey *inst.InstanceKey, name string) error

	// StopGroupLocked stops a mysql group
	StopGroupLocked(instanceKey *inst.InstanceKey) error

	// JoinGroupLocked puts an instance into a mysql group based on primary instance
	// the caller should grab a lock before
	JoinGroupLocked(instanceKey *inst.InstanceKey, primaryKey *inst.InstanceKey) error

	// SetReadOnly set super_read_only variable
	// https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_super_read_only
	SetReadOnly(instanceKey *inst.InstanceKey, readOnly bool) error

	// FetchApplierGTIDSet fetches the GTID set from group_replication_applier channel
	FetchApplierGTIDSet(instanceKey *inst.InstanceKey) (mysql.GTIDSet, error)

	// Failover move the mysql primary to the node defined by memberUUID
	Failover(instance *inst.InstanceKey) error

	// FetchGroupView fetches group related information
	FetchGroupView(alias string, instanceKey *inst.InstanceKey) (*GroupView, error)
}

Agent is used by vtgr to interact with Mysql

type GroupMember

type GroupMember struct {
	HostName string
	Port     int
	Role     MemberRole
	State    MemberState
	ReadOnly bool
}

GroupMember represents a ROW we get from performance_schema

func NewGroupMember

func NewGroupMember(state, role, host string, port int, readonly bool) *GroupMember

NewGroupMember creates a new GroupMember

type GroupView

type GroupView struct {
	TabletAlias        string
	MySQLHost          string
	MySQLPort          int
	GroupName          string
	HeartbeatStaleness int
	UnresolvedMembers  []*GroupMember
}

GroupView is an instance's view for the group

func BuildGroupView

func BuildGroupView(alias, groupName, host string, port int, readOnly bool, stalenessResult int, inputs []TestGroupState) *GroupView

BuildGroupView builds gruop view from input

func NewGroupView

func NewGroupView(alias, host string, port int) *GroupView

NewGroupView creates a new GroupView

func (*GroupView) CreateInstanceKey

func (view *GroupView) CreateInstanceKey(member *GroupMember) inst.InstanceKey

CreateInstanceKey returns an InstanceKey based on group member input When the group is init for the first time, the hostname and port are not set, e.g., +---------------------------+-----------+-------------+-------------+--------------+-------------+ | CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | +---------------------------+-----------+-------------+-------------+--------------+-------------+ | group_replication_applier | | | NULL | OFFLINE | | +---------------------------+-----------+-------------+-------------+--------------+-------------+ therefore we substitute with view's local hostname and port

func (*GroupView) GetPrimaryView

func (view *GroupView) GetPrimaryView() (string, int, bool)

GetPrimaryView returns the view of primary member

func (*GroupView) ToString

func (view *GroupView) ToString() string

ToString make string for group view

type MemberRole

type MemberRole int

MemberRole is member role

const (
	UNKNOWNROLE MemberRole = iota
	SECONDARY
	PRIMARY
)

func (MemberRole) String

func (role MemberRole) String() string

type MemberState

type MemberState int

MemberState is member state

const (
	UNKNOWNSTATE MemberState = iota
	OFFLINE
	UNREACHABLE
	RECOVERING
	ONLINE
	ERROR
)

func (MemberState) String

func (state MemberState) String() string

type MockAgent

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

MockAgent is a mock of Agent interface

func NewMockAgent

func NewMockAgent(ctrl *gomock.Controller) *MockAgent

NewMockAgent creates a new mock instance

func (*MockAgent) BootstrapGroupLocked

func (m *MockAgent) BootstrapGroupLocked(instanceKey *inst.InstanceKey) error

BootstrapGroupLocked mocks base method

func (*MockAgent) EXPECT

func (m *MockAgent) EXPECT() *MockAgentMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockAgent) Failover

func (m *MockAgent) Failover(instance *inst.InstanceKey) error

Failover mocks base method

func (*MockAgent) FetchApplierGTIDSet

func (m *MockAgent) FetchApplierGTIDSet(instanceKey *inst.InstanceKey) (mysql.GTIDSet, error)

FetchApplierGTIDSet mocks base method

func (*MockAgent) FetchGroupView

func (m *MockAgent) FetchGroupView(alias string, instanceKey *inst.InstanceKey) (*GroupView, error)

FetchGroupView mocks base method

func (*MockAgent) JoinGroupLocked

func (m *MockAgent) JoinGroupLocked(instanceKey, primaryKey *inst.InstanceKey) error

JoinGroupLocked mocks base method

func (*MockAgent) RebootstrapGroupLocked

func (m *MockAgent) RebootstrapGroupLocked(instanceKey *inst.InstanceKey, name string) error

RebootstrapGroupLocked mocks base method

func (*MockAgent) SetReadOnly

func (m *MockAgent) SetReadOnly(instanceKey *inst.InstanceKey, readOnly bool) error

SetReadOnly mocks base method

func (*MockAgent) StopGroupLocked

func (m *MockAgent) StopGroupLocked(instanceKey *inst.InstanceKey) error

StopGroupLocked mocks base method

type MockAgentMockRecorder

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

MockAgentMockRecorder is the mock recorder for MockAgent

func (*MockAgentMockRecorder) BootstrapGroupLocked

func (mr *MockAgentMockRecorder) BootstrapGroupLocked(instanceKey any) *gomock.Call

BootstrapGroupLocked indicates an expected call of BootstrapGroupLocked

func (*MockAgentMockRecorder) Failover

func (mr *MockAgentMockRecorder) Failover(instance any) *gomock.Call

Failover indicates an expected call of Failover

func (*MockAgentMockRecorder) FetchApplierGTIDSet

func (mr *MockAgentMockRecorder) FetchApplierGTIDSet(instanceKey any) *gomock.Call

FetchApplierGTIDSet indicates an expected call of FetchApplierGTIDSet

func (*MockAgentMockRecorder) FetchGroupView

func (mr *MockAgentMockRecorder) FetchGroupView(alias, instanceKey any) *gomock.Call

FetchGroupView indicates an expected call of FetchGroupView

func (*MockAgentMockRecorder) JoinGroupLocked

func (mr *MockAgentMockRecorder) JoinGroupLocked(instanceKey, primaryKey any) *gomock.Call

JoinGroupLocked indicates an expected call of JoinGroupLocked

func (*MockAgentMockRecorder) RebootstrapGroupLocked

func (mr *MockAgentMockRecorder) RebootstrapGroupLocked(instanceKey, name any) *gomock.Call

RebootstrapGroupLocked indicates an expected call of RebootstrapGroupLocked

func (*MockAgentMockRecorder) SetReadOnly

func (mr *MockAgentMockRecorder) SetReadOnly(instanceKey, readOnly any) *gomock.Call

SetReadOnly indicates an expected call of SetReadOnly

func (*MockAgentMockRecorder) StopGroupLocked

func (mr *MockAgentMockRecorder) StopGroupLocked(instanceKey any) *gomock.Call

StopGroupLocked indicates an expected call of StopGroupLocked

type SQLAgentImpl

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

SQLAgentImpl implements Agent

func NewVTGRSqlAgent

func NewVTGRSqlAgent() *SQLAgentImpl

NewVTGRSqlAgent creates a SQLAgentImpl

func (*SQLAgentImpl) BootstrapGroupLocked

func (agent *SQLAgentImpl) BootstrapGroupLocked(instanceKey *inst.InstanceKey) error

BootstrapGroupLocked implements Agent interface

func (*SQLAgentImpl) Failover

func (agent *SQLAgentImpl) Failover(instance *inst.InstanceKey) error

Failover implements Agent interface

func (*SQLAgentImpl) FetchApplierGTIDSet

func (agent *SQLAgentImpl) FetchApplierGTIDSet(instanceKey *inst.InstanceKey) (mysql.GTIDSet, error)

FetchApplierGTIDSet implements Agent interface

func (*SQLAgentImpl) FetchGroupView

func (agent *SQLAgentImpl) FetchGroupView(alias string, instanceKey *inst.InstanceKey) (*GroupView, error)

FetchGroupView implements Agent interface

func (*SQLAgentImpl) JoinGroupLocked

func (agent *SQLAgentImpl) JoinGroupLocked(instanceKey *inst.InstanceKey, primaryInstanceKey *inst.InstanceKey) error

JoinGroupLocked implements Agent interface Note: caller should grab the lock before calling this

func (*SQLAgentImpl) RebootstrapGroupLocked

func (agent *SQLAgentImpl) RebootstrapGroupLocked(instanceKey *inst.InstanceKey, name string) error

func (*SQLAgentImpl) SetReadOnly

func (agent *SQLAgentImpl) SetReadOnly(instanceKey *inst.InstanceKey, readOnly bool) error

SetReadOnly implements Agent interface

func (*SQLAgentImpl) StopGroupLocked

func (agent *SQLAgentImpl) StopGroupLocked(instanceKey *inst.InstanceKey) error

StopGroupLocked implements Agent interface

type TestGroupState

type TestGroupState struct {
	MemberHost, MemberPort, MemberState, MemberRole string
}

TestGroupState mocks a row from mysql

Jump to

Keyboard shortcuts

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