backend

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2022 License: Apache-2.0 Imports: 17 Imported by: 12

Documentation

Index

Constants

View Source
const (

	// DefaultSlice means default slice for namespace
	DefaultSlice = "slice-0"
)
View Source
const (
	PING_PEROID = 5 * time.Second
)

Variables

View Source
var (
	// ErrConnectionPoolClosed means pool closed error
	ErrConnectionPoolClosed = errors.New("connection pool is closed")
	// DefaultCapacity default capacity of connection pool
	DefaultCapacity = 64
)

Functions

This section is empty.

Types

type ConnectionPool

type ConnectionPool interface {
	Open()
	Addr() string
	Close()
	Get(ctx context.Context) (PooledConnect, error)
	Put(pc PooledConnect)

	SetCapacity(capacity int) (err error)
	SetIdleTimeout(idleTimeout time.Duration)
	StatsJSON() string
	Capacity() int64
	Available() int64
	Active() int64
	InUse() int64
	MaxCap() int64
	WaitCount() int64
	WaitTime() time.Duration
	IdleTimeout() time.Duration
	IdleClosed() int64
}

func NewConnectionPool

func NewConnectionPool(addr, user, password, db string, capacity, maxCapacity int, idleTimeout time.Duration, charset string, collationID mysql.CollationID) ConnectionPool

NewConnectionPool create connection pool

type DirectConnection

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

DirectConnection means connection to backend mysql

func NewDirectConnection

func NewDirectConnection(addr string, user string, password string, db string, charset string, collationID mysql.CollationID) (*DirectConnection, error)

NewDirectConnection return direct and authorised connection to mysql with real net connection

func (*DirectConnection) Begin

func (dc *DirectConnection) Begin() error

Begin send ComQuery with 'begin' to backend mysql to start transaction

func (*DirectConnection) Close

func (dc *DirectConnection) Close()

Close close connection to backend mysql and reset conn structure

func (*DirectConnection) Commit

func (dc *DirectConnection) Commit() error

Commit send ComQuery with 'commit' to backend mysql to commit transaction

func (*DirectConnection) Execute

func (dc *DirectConnection) Execute(sql string, maxRows int) (*mysql.Result, error)

Execute send ComQuery or ComStmtPrepare/ComStmtExecute/ComStmtClose to backend mysql

func (*DirectConnection) FieldList

func (dc *DirectConnection) FieldList(table string, wildcard string) ([]*mysql.Field, error)

FieldList send ComFieldList to backend mysql

func (*DirectConnection) GetAddr

func (dc *DirectConnection) GetAddr() string

GetAddr return addr of backend mysql

func (*DirectConnection) GetCharset

func (dc *DirectConnection) GetCharset() string

GetCharset return charset of specific connection

func (*DirectConnection) GetDB

func (dc *DirectConnection) GetDB() string

GetDB return database name

func (*DirectConnection) IsAutoCommit

func (dc *DirectConnection) IsAutoCommit() bool

IsAutoCommit check if autocommit

func (*DirectConnection) IsClosed

func (dc *DirectConnection) IsClosed() bool

IsClosed check if connection closed

func (*DirectConnection) IsInTransaction

func (dc *DirectConnection) IsInTransaction() bool

IsInTransaction check if in transaction

func (*DirectConnection) Ping

func (dc *DirectConnection) Ping() error

Ping implements mysql ping command.

func (*DirectConnection) ResetConnection

func (dc *DirectConnection) ResetConnection() error

ResetConnection reset connection stattus, include transaction、autocommit、charset、sql_mode .etc

func (*DirectConnection) Rollback

func (dc *DirectConnection) Rollback() error

Rollback send ComQuery with 'rollback' to backend mysql to rollback transaction

func (*DirectConnection) SetAutoCommit

func (dc *DirectConnection) SetAutoCommit(v uint8) error

SetAutoCommit trun on/off autocommit

func (*DirectConnection) SetCharset

func (dc *DirectConnection) SetCharset(charset string, collation mysql.CollationID) (bool, error)

SetCharset set charset of connection to backend mysql

func (*DirectConnection) SetSessionVariables

func (dc *DirectConnection) SetSessionVariables(frontend *mysql.SessionVariables) (bool, error)

SetSessionVariables set direction variables according to Session

func (*DirectConnection) UseDB

func (dc *DirectConnection) UseDB(dbName string) error

UseDB send ComInitDB to backend mysql

func (*DirectConnection) WriteSetStatement

func (dc *DirectConnection) WriteSetStatement() error

WriteSetStatement execute sql

type PooledConnect added in v1.2.3

type PooledConnect interface {
	Recycle()
	Reconnect() error
	Close()
	IsClosed() bool
	UseDB(db string) error
	Execute(sql string, maxRows int) (*mysql.Result, error)
	SetAutoCommit(v uint8) error
	Begin() error
	Commit() error
	Rollback() error
	Ping() error
	SetCharset(charset string, collation mysql.CollationID) (bool, error)
	FieldList(table string, wildcard string) ([]*mysql.Field, error)
	GetAddr() string
	SetSessionVariables(frontend *mysql.SessionVariables) (bool, error)
	WriteSetStatement() error
	GetConnectionID() int64
	GetReturnTime() time.Time
}

type Slice

type Slice struct {
	Cfg models.Slice
	sync.RWMutex

	Master ConnectionPool

	Slave []ConnectionPool

	StatisticSlave []ConnectionPool
	// contains filtered or unexported fields
}

Slice means one slice of the mysql cluster

func (*Slice) Close

func (s *Slice) Close() error

Close close the pool in slice

func (*Slice) GetConn

func (s *Slice) GetConn(fromSlave bool, userType int) (pc PooledConnect, err error)

GetConn get backend connection from different node based on fromSlave and userType

func (*Slice) GetDirectConn added in v1.2.3

func (s *Slice) GetDirectConn(addr string) (*DirectConnection, error)

func (*Slice) GetMasterConn

func (s *Slice) GetMasterConn() (PooledConnect, error)

GetMasterConn return a connection in master pool

func (*Slice) GetSlaveConn

func (s *Slice) GetSlaveConn() (PooledConnect, error)

GetSlaveConn return a connection in slave pool

func (*Slice) GetSliceName

func (s *Slice) GetSliceName() string

GetSliceName return name of slice

func (*Slice) GetStatisticSlaveConn

func (s *Slice) GetStatisticSlaveConn() (PooledConnect, error)

GetStatisticSlaveConn return a connection in statistic slave pool

func (*Slice) ParseMaster

func (s *Slice) ParseMaster(masterStr string) error

ParseMaster create master connection pool

func (*Slice) ParseSlave

func (s *Slice) ParseSlave(slaves []string) error

ParseSlave create connection pool of slaves (127.0.0.1:3306@2,192.168.0.12:3306@3)

func (*Slice) ParseStatisticSlave

func (s *Slice) ParseStatisticSlave(statisticSlaves []string) error

ParseStatisticSlave create connection pool of statistic slaves slaveStr(127.0.0.1:3306@2,192.168.0.12:3306@3)

func (*Slice) SetCharsetInfo

func (s *Slice) SetCharsetInfo(charset string, collationID mysql.CollationID)

SetCharsetInfo set charset

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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