db

package
v0.17.6 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const Error1045 = "Access denied for user"
View Source
const Error3159 = "Error 3159:"

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

func ExecOrchestrator added in v0.15.0

func ExecOrchestrator(query string, args ...any) (sql.Result, error)

ExecOrchestrator will execute given query on the orchestrator backend database.

func IsSQLite added in v0.15.0

func IsSQLite() bool

func OpenDiscovery added in v0.15.0

func OpenDiscovery(host string, port int) (*sql.DB, error)

OpenDiscovery returns a DB instance to access a topology instance. It has lower read timeout than OpenTopology and is intended to be used with low-latency discovery queries.

func OpenOrchestrator added in v0.15.0

func OpenOrchestrator() (db *sql.DB, err error)

OpenTopology returns the DB instance for the orchestrator backed database

func OpenTopology added in v0.15.0

func OpenTopology(host string, port int) (*sql.DB, error)

OpenTopology returns a DB instance to access a topology instance.

func QueryOrchestrator added in v0.15.0

func QueryOrchestrator(query string, argsArray []any, onRow func(sqlutils.RowMap) error) error

QueryOrchestrator

func SetupMySQLOrchestratorTLS added in v0.15.0

func SetupMySQLOrchestratorTLS(uri string) (string, error)

SetupMySQLOrchestratorTLS creates a TLS configuration from the config supplied CA, Certificate, and Private key. Register the TLS config with the mysql drivers as the "orchestrator" config Modify the supplied URI to call the TLS config

func SetupMySQLTopologyTLS added in v0.15.0

func SetupMySQLTopologyTLS(uri string) (string, error)

SetupMySQLTopologyTLS creates a TLS configuration from the config supplied CA, Certificate, and Private key. Register the TLS config with the mysql drivers as the "topology" config Modify the supplied URI to call the TLS config

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 DB added in v0.15.0

type DB interface {
	QueryOrchestrator(query string, argsArray []any, onRow func(sqlutils.RowMap) error) error
}
var (
	EmptyArgs []any
	Db        DB = (*vtorcDB)(nil)
)

type DummySQLResult added in v0.15.0

type DummySQLResult struct {
}

func (DummySQLResult) LastInsertId added in v0.15.0

func (dummyRes DummySQLResult) LastInsertId() (int64, error)

func (DummySQLResult) RowsAffected added in v0.15.0

func (dummyRes DummySQLResult) RowsAffected() (int64, error)

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