backend

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultSlice means default slice for namespace
	DefaultSlice = "slice-0"
)

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 struct {
	// contains filtered or unexported fields
}

ConnectionPool means connection pool with specific addr

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

func (*ConnectionPool) Active

func (cp *ConnectionPool) Active() int64

Active returns the number of active connections in the pool

func (*ConnectionPool) Addr

func (cp *ConnectionPool) Addr() string

Addr return addr of connection pool

func (*ConnectionPool) Available

func (cp *ConnectionPool) Available() int64

Available returns the number of available connections in the pool

func (*ConnectionPool) Capacity

func (cp *ConnectionPool) Capacity() int64

Capacity return the pool capacity

func (*ConnectionPool) Close

func (cp *ConnectionPool) Close()

Close close connection pool

func (*ConnectionPool) Get

Get return a connection, you should call PooledConnection's Recycle once done

func (*ConnectionPool) IdleClosed

func (cp *ConnectionPool) IdleClosed() int64

IdleClosed return the number of closed connections for the pool

func (*ConnectionPool) IdleTimeout

func (cp *ConnectionPool) IdleTimeout() time.Duration

IdleTimeout returns the idle timeout for the pool

func (*ConnectionPool) InUse

func (cp *ConnectionPool) InUse() int64

InUse returns the number of in-use connections in the pool

func (*ConnectionPool) MaxCap

func (cp *ConnectionPool) MaxCap() int64

MaxCap returns the maximum size of the pool

func (*ConnectionPool) Open

func (cp *ConnectionPool) Open()

Open open connection pool without error, should be called before use the pool

func (*ConnectionPool) Put

func (cp *ConnectionPool) Put(pc *PooledConnection)

Put recycle a connection into the pool

func (*ConnectionPool) SetCapacity

func (cp *ConnectionPool) SetCapacity(capacity int) (err error)

SetCapacity alert the size of the pool at runtime

func (*ConnectionPool) SetIdleTimeout

func (cp *ConnectionPool) SetIdleTimeout(idleTimeout time.Duration)

SetIdleTimeout set the idleTimeout of the pool

func (*ConnectionPool) StatsJSON

func (cp *ConnectionPool) StatsJSON() string

StatsJSON return the pool stats as JSON object.

func (*ConnectionPool) WaitCount

func (cp *ConnectionPool) WaitCount() int64

WaitCount returns how many clients are waitting for a connection

func (*ConnectionPool) WaitTime

func (cp *ConnectionPool) WaitTime() time.Duration

WaitTime returns the time wait for a connection

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) (*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 PooledConnection

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

PooledConnection app use this object to exec sql

func (*PooledConnection) Begin

func (pc *PooledConnection) Begin() error

Begin wrapper of direct connection, begin transaction

func (*PooledConnection) Close

func (pc *PooledConnection) Close()

Close implement util.Resource interface

func (*PooledConnection) Commit

func (pc *PooledConnection) Commit() error

Commit wrapper of direct connection, commit transaction

func (*PooledConnection) Execute

func (pc *PooledConnection) Execute(sql string) (*mysql.Result, error)

Execute wrapper of direct connection, execute sql

func (*PooledConnection) FieldList

func (pc *PooledConnection) FieldList(table string, wildcard string) ([]*mysql.Field, error)

FieldList wrapper of direct connection, send field list to mysql

func (*PooledConnection) GetAddr

func (pc *PooledConnection) GetAddr() string

GetAddr wrapper of return addr of direct connection

func (*PooledConnection) IsClosed

func (pc *PooledConnection) IsClosed() bool

IsClosed check if pooled connection closed

func (*PooledConnection) Reconnect

func (pc *PooledConnection) Reconnect() error

Reconnect replaces the existing underlying connection with a new one. If we get "MySQL server has gone away (errno 2006)", then call Reconnect

func (*PooledConnection) Recycle

func (pc *PooledConnection) Recycle()

Recycle return PooledConnection to the pool

func (*PooledConnection) Rollback

func (pc *PooledConnection) Rollback() error

Rollback wrapper of direct connection, rollback transaction

func (*PooledConnection) SetAutoCommit

func (pc *PooledConnection) SetAutoCommit(v uint8) error

SetAutoCommit wrapper of direct connection, set autocommit

func (*PooledConnection) SetCharset

func (pc *PooledConnection) SetCharset(charset string, collation mysql.CollationID) (bool, error)

SetCharset wrapper of direct connection, set charset of connection

func (*PooledConnection) SetSessionVariables

func (pc *PooledConnection) SetSessionVariables(frontend *mysql.SessionVariables) (bool, error)

SetSessionVariables set pc variables according to session

func (*PooledConnection) UseDB

func (pc *PooledConnection) UseDB(db string) error

UseDB wrapper of direct connection, init database

func (*PooledConnection) WriteSetStatement

func (pc *PooledConnection) WriteSetStatement() error

WriteSetStatement exec sql

type Slice

type Slice struct {
	Cfg models.Slice

	sync.RWMutex
	Master *ConnectionPool

	Slave          []*ConnectionPool
	LastSlaveIndex int
	RoundRobinQ    []int
	SlaveWeights   []int

	StatisticSlave            []*ConnectionPool
	LastStatisticSlaveIndex   int
	StatisticSlaveRoundRobinQ []int
	StatisticSlaveWeights     []int
	// 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 *PooledConnection, err error)

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

func (*Slice) GetMasterConn

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

GetMasterConn return a connection in master pool

func (*Slice) GetSlaveConn

func (s *Slice) GetSlaveConn() (*PooledConnection, 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() (*PooledConnection, 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

Jump to

Keyboard shortcuts

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