Documentation ¶
Index ¶
- Constants
- Variables
- type ConnectionPool
- type DirectConnection
- func (dc *DirectConnection) Begin() error
- func (dc *DirectConnection) Close()
- func (dc *DirectConnection) Commit() error
- func (dc *DirectConnection) Execute(sql string, maxRows int) (*mysql.Result, error)
- func (dc *DirectConnection) FieldList(table string, wildcard string) ([]*mysql.Field, error)
- func (dc *DirectConnection) GetAddr() string
- func (dc *DirectConnection) GetCharset() string
- func (dc *DirectConnection) GetDB() string
- func (dc *DirectConnection) IsAutoCommit() bool
- func (dc *DirectConnection) IsClosed() bool
- func (dc *DirectConnection) IsInTransaction() bool
- func (dc *DirectConnection) Ping() error
- func (dc *DirectConnection) ResetConnection() error
- func (dc *DirectConnection) Rollback() error
- func (dc *DirectConnection) SetAutoCommit(v uint8) error
- func (dc *DirectConnection) SetCharset(charset string, collation mysql.CollationID) (bool, error)
- func (dc *DirectConnection) SetSessionVariables(frontend *mysql.SessionVariables) (bool, error)
- func (dc *DirectConnection) UseDB(dbName string) error
- func (dc *DirectConnection) WriteSetStatement() error
- type PooledConnect
- type Slice
- func (s *Slice) Close() error
- func (s *Slice) GetConn(fromSlave bool, userType int) (pc PooledConnect, err error)
- func (s *Slice) GetDirectConn(addr string) (*DirectConnection, error)
- func (s *Slice) GetMasterConn() (PooledConnect, error)
- func (s *Slice) GetSlaveConn() (PooledConnect, error)
- func (s *Slice) GetSliceName() string
- func (s *Slice) GetStatisticSlaveConn() (PooledConnect, error)
- func (s *Slice) ParseMaster(masterStr string) error
- func (s *Slice) ParseSlave(slaves []string) error
- func (s *Slice) ParseStatisticSlave(statisticSlaves []string) error
- func (s *Slice) SetCharsetInfo(charset string, collationID mysql.CollationID)
Constants ¶
const (
// DefaultSlice means default slice for namespace
DefaultSlice = "slice-0"
)
const (
PING_PEROID = 5 * time.Second
)
Variables ¶
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 ¶
Execute send ComQuery or ComStmtPrepare/ComStmtExecute/ComStmtClose 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) 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 ¶
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 ¶
ParseMaster create master connection pool
func (*Slice) ParseSlave ¶
ParseSlave create connection pool of slaves (127.0.0.1:3306@2,192.168.0.12:3306@3)
func (*Slice) ParseStatisticSlave ¶
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