backend

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MockBackendConfigAttach added in v1.0.7

func MockBackendConfigAttach(name, addr string) *config.BackendConfig

MockBackendConfigAttach mocks new attach backend config.

func MockBackendConfigDefault

func MockBackendConfigDefault(name, addr string) *config.BackendConfig

MockBackendConfigDefault mocks new normal backend config.

func MockBackendConfigReplica added in v1.1.1

func MockBackendConfigReplica(name, addr, replica string) *config.BackendConfig

MockBackendConfigReplica mocks new backend config with replica.

func MockScatterDefault added in v1.0.2

func MockScatterDefault(log *xlog.Log) *config.ScatterConfig

MockScatterDefault mocks new xacheck config.

func MockScatterDefault2 added in v1.0.2

func MockScatterDefault2(dir string) *config.ScatterConfig

MockScatterDefault2 mocks new xacheck config with dir.

func MockTxnMgrScatter added in v1.0.2

func MockTxnMgrScatter(log *xlog.Log, n int) (*fakedb.DB, *TxnManager, map[string]*Poolz, []string, *Scatter, func())

MockTxnMgrScatter used to mock a txnMgr and a scatter. commit err and rollback err will WriteXaCommitErrLog, need the scatter

Types

type Connection

type Connection interface {
	ID() uint32
	Dial() error
	Ping() error
	Close()
	Closed() bool
	LastErr() error
	UseDB(string) error
	Kill(string) error
	Recycle()
	Address() string
	SetTimestamp(int64)
	Timestamp() int64
	Execute(string) (*sqltypes.Result, error)
	ExecuteStreamFetch(string) (driver.Rows, error)
	ExecuteWithLimits(query string, timeout int, maxmem int) (*sqltypes.Result, error)
}

Connection tuple.

func MockClient

func MockClient(log *xlog.Log, addr string) (Connection, func())

MockClient mocks a client connection.

func MockClientWithConfig

func MockClientWithConfig(log *xlog.Log, conf *config.BackendConfig) (Connection, func())

MockClientWithConfig mocks a client with backendconfig.

func NewConnection

func NewConnection(log *xlog.Log, pool *Pool) Connection

NewConnection creates a new connection.

type Pool

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

Pool tuple.

func NewPool

func NewPool(log *xlog.Log, conf *config.BackendConfig, address string) *Pool

NewPool creates the new Pool.

func (*Pool) Close

func (p *Pool) Close()

Close used to close the pool.

func (*Pool) Get

func (p *Pool) Get() (Connection, error)

Get used to get a connection from the pool.

func (*Pool) JSON

func (p *Pool) JSON() string

JSON returns the available string. available is the number of currently unused connections.

func (*Pool) Put

func (p *Pool) Put(conn Connection)

Put used to put a connection to pool.

type Poolz added in v1.1.1

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

Poolz ... Add replica and normal pool to distribute SQL between read and write in some cases for load-balance.

func NewPoolz added in v1.1.1

func NewPoolz(log *xlog.Log, conf *config.BackendConfig) *Poolz

NewPoolz create the new Poolz.

func (*Poolz) Close added in v1.1.1

func (p *Poolz) Close()

Close used to close the poolz.

func (*Poolz) JSON added in v1.1.1

func (p *Poolz) JSON() string

JSON returns the available string.

type QueryDetail

type QueryDetail struct {
	ID uint64
	// contains filtered or unexported fields
}

QueryDetail is a simple wrapper for Query

func NewQueryDetail

func NewQueryDetail(conn Connection, query string) *QueryDetail

NewQueryDetail creates a new QueryDetail

type QueryDetailzRow

type QueryDetailzRow struct {
	Start    time.Time
	Duration time.Duration
	ConnID   uint32
	Query    string
	Address  string
	Color    string
}

QueryDetailzRow is used for rendering QueryDetail in a template

type Queryz

type Queryz struct {
	ID uint64
	// contains filtered or unexported fields
}

Queryz holds a thread safe list of QueryDetails

func NewQueryz

func NewQueryz() *Queryz

NewQueryz creates a new Queryz

func (*Queryz) Add

func (qz *Queryz) Add(qd *QueryDetail)

Add adds a QueryDetail to Queryz

func (*Queryz) GetQueryzRows

func (qz *Queryz) GetQueryzRows() byStartTime

GetQueryzRows returns a list of QueryDetailzRow sorted by start time

func (*Queryz) Remove

func (qz *Queryz) Remove(qd *QueryDetail)

Remove removes a QueryDetail from Queryz

type Scatter

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

Scatter tuple.

func MockScatter

func MockScatter(log *xlog.Log, n int) (*Scatter, *fakedb.DB, func())

MockScatter used to mock a scatter.

func NewScatter

func NewScatter(log *xlog.Log, metadir string) *Scatter

NewScatter creates a new scatter.

func (*Scatter) Add

func (scatter *Scatter) Add(config *config.BackendConfig) error

Add used to add a new backend to scatter.

func (*Scatter) AllBackends added in v1.0.7

func (scatter *Scatter) AllBackends() []string

AllBackends returns all backends.

func (*Scatter) BackendConfigsClone

func (scatter *Scatter) BackendConfigsClone() []*config.BackendConfig

BackendConfigsClone used to clone all the backend configs.

func (*Scatter) Backends

func (scatter *Scatter) Backends() []string

Backends returns all normal backends.

func (*Scatter) CheckBackend added in v1.0.8

func (scatter *Scatter) CheckBackend(backenName string) bool

func (*Scatter) Close

func (scatter *Scatter) Close()

Close used to clean the pools connections.

func (*Scatter) CreateTransaction

func (scatter *Scatter) CreateTransaction() (*Txn, error)

CreateTransaction used to create a transaction.

func (*Scatter) FlushConfig

func (scatter *Scatter) FlushConfig() error

FlushConfig used to write the backends to file.

func (*Scatter) Init added in v1.0.2

func (scatter *Scatter) Init(scatterConf *config.ScatterConfig) error

Init is used to init the xaCheck and start the xaCheck thread.

func (*Scatter) LoadConfig

func (scatter *Scatter) LoadConfig() error

LoadConfig used to load all backends from metadir/backend.json file.

func (*Scatter) MySQLStats

func (scatter *Scatter) MySQLStats() *stats.Timings

MySQLStats returns the mysql stats.

func (*Scatter) PoolzClone added in v1.1.1

func (scatter *Scatter) PoolzClone() map[string]*Poolz

PoolzClone used to copy backends to new map.

func (*Scatter) QueryRates

func (scatter *Scatter) QueryRates() *stats.Rates

QueryRates returns the query rates.

func (*Scatter) QueryStats

func (scatter *Scatter) QueryStats() *stats.Timings

QueryStats returns the query stats.

func (*Scatter) Queryz

func (scatter *Scatter) Queryz() *Queryz

Queryz returns the queryz.

func (*Scatter) Remove

func (scatter *Scatter) Remove(config *config.BackendConfig) error

Remove used to remove a backend from the scatter.

func (*Scatter) TxnCounters

func (scatter *Scatter) TxnCounters() *stats.Counters

TxnCounters returns the txn counters.

func (*Scatter) Txnz

func (scatter *Scatter) Txnz() *Txnz

Txnz returns the txnz.

type Transaction

type Transaction interface {
	XID() string
	TxID() uint64
	State() int32
	XaState() int32
	Abort() error

	Begin() error
	Rollback() error
	Commit() error
	Finish() error

	BeginScatter() error
	CommitScatter() error
	RollbackScatter() error
	SetMultiStmtTxn()
	SetSessionID(id uint32)

	SetIsExecOnRep(isExecOnRep bool)
	SetTimeout(timeout int)
	SetMaxResult(max int)
	SetMaxJoinRows(max int)
	MaxJoinRows() int

	Execute(req *xcontext.RequestContext) (*sqltypes.Result, error)
	ExecuteRaw(database string, query string) (*sqltypes.Result, error)
}

Transaction interface.

type Txn

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

Txn tuple.

func NewTxn

func NewTxn(log *xlog.Log, txid uint64, mgr *TxnManager, backends map[string]*Poolz) (*Txn, error)

NewTxn creates the new Txn.

func (*Txn) Abort

func (txn *Txn) Abort() error

Abort used to abort all txn connections.

func (*Txn) Begin

func (txn *Txn) Begin() error

Begin used to start a XA transaction. Begin only does: 1. set twopc to true

func (*Txn) BeginScatter added in v1.0.3

func (txn *Txn) BeginScatter() error

BeginScatter used to start a XA transaction in the multiple-statement transaction

func (*Txn) Commit

func (txn *Txn) Commit() error

Commit does: 1. XA END 2. XA PREPARE 3. XA COMMIT

func (*Txn) CommitScatter added in v1.0.3

func (txn *Txn) CommitScatter() error

CommitScatter is used in the multiple-statement transaction

func (*Txn) Execute

func (txn *Txn) Execute(req *xcontext.RequestContext) (*sqltypes.Result, error)

Execute used to execute the query. If the txn is in twopc mode, we do the xaStart before the real query execute.

func (*Txn) ExecuteOnThisBackend

func (txn *Txn) ExecuteOnThisBackend(backend string, query string) (*sqltypes.Result, error)

ExecuteOnThisBackend used to send the query to this backend.

func (*Txn) ExecuteRaw

func (txn *Txn) ExecuteRaw(database string, query string) (*sqltypes.Result, error)

ExecuteRaw used to execute raw query, txn not implemented.

func (*Txn) ExecuteScatter

func (txn *Txn) ExecuteScatter(query string) (*sqltypes.Result, error)

ExecuteScatter used to execute query on all shards.

func (*Txn) ExecuteSingle

func (txn *Txn) ExecuteSingle(query string) (*sqltypes.Result, error)

ExecuteSingle used to execute query on one shard.

func (*Txn) ExecuteStreamFetch

func (txn *Txn) ExecuteStreamFetch(req *xcontext.RequestContext, callback func(*sqltypes.Result) error, streamBufferSize int) error

ExecuteStreamFetch used to execute stream fetch query.

func (*Txn) Finish

func (txn *Txn) Finish() error

Finish used to finish a transaction. If the lastErr is nil, we will recycle all the twopc connections to the pool for reuse, otherwise we wil close all of the them.

func (*Txn) MaxJoinRows added in v1.0.7

func (txn *Txn) MaxJoinRows() int

MaxJoinRows returns txn maxJoinRows.

func (*Txn) Rollback

func (txn *Txn) Rollback() error

Rollback used to rollback a XA transaction. 1. XA END 2. XA PREPARE 3. XA ROLLBACK

func (*Txn) RollbackPhaseOne added in v1.1.2

func (txn *Txn) RollbackPhaseOne() error

RollbackPhaseOne used to rollback when the SQL return error at the phase one. won't do `XA PREPARE` which will write log to binlog, especially when large Transactions happen. 1. XA END 2. XA ROLLBACK

func (*Txn) RollbackScatter added in v1.0.3

func (txn *Txn) RollbackScatter() error

RollbackScatter is used in the multiple-statement transaction

func (*Txn) SetIsExecOnRep added in v1.1.1

func (txn *Txn) SetIsExecOnRep(isExecOnRep bool)

SetIsExecOnRep used to set the txn isExecOnRep, true -- execute on the replica.

func (*Txn) SetMaxJoinRows added in v1.0.7

func (txn *Txn) SetMaxJoinRows(max int)

SetMaxJoinRows used to set the txn max join rows.

func (*Txn) SetMaxResult

func (txn *Txn) SetMaxResult(max int)

SetMaxResult used to set the txn max result.

func (*Txn) SetMultiStmtTxn added in v1.0.4

func (txn *Txn) SetMultiStmtTxn()

SetMultiStmtTxn --

func (*Txn) SetSessionID added in v1.0.6

func (txn *Txn) SetSessionID(id uint32)

SetSessionID -- bind the txn to session id, for debug.

func (*Txn) SetTimeout

func (txn *Txn) SetTimeout(timeout int)

SetTimeout used to set the txn timeout.

func (*Txn) State

func (txn *Txn) State() int32

State returns txn.state.

func (*Txn) TxID

func (txn *Txn) TxID() uint64

TxID returns txn id.

func (*Txn) WriteXaCommitErrLog added in v1.0.2

func (txn *Txn) WriteXaCommitErrLog(state string) error

WriteXaCommitErrLog used to write the error xaid to the log.

func (*Txn) XID

func (txn *Txn) XID() string

XID returns txn xid.

func (*Txn) XaState

func (txn *Txn) XaState() int32

XaState returns txn xastate.

type TxnDetail

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

TxnDetail is a simple wrapper for Query

func NewTxnDetail

func NewTxnDetail(txn Transaction) *TxnDetail

NewTxnDetail creates a new TxnDetail

type TxnDetailzRow

type TxnDetailzRow struct {
	Start    time.Time
	Duration time.Duration
	TxnID    uint64
	XAID     string
	Query    string
	State    string
	XaState  string
	Color    string
}

TxnDetailzRow is used for rendering TxnDetail in a template

type TxnManager

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

TxnManager tuple.

func MockTxnMgr

func MockTxnMgr(log *xlog.Log, n int) (*fakedb.DB, *TxnManager, map[string]*Poolz, []string, func())

MockTxnMgr mocks txn manager.

func MockTxnMgrWithAttach added in v1.0.7

func MockTxnMgrWithAttach(log *xlog.Log, n int) (*fakedb.DB, *TxnManager, map[string]*Poolz, []string, func())

MockTxnMgrWithAttach mocks txn manager with attach backend.

func MockTxnMgrWithReplica added in v1.1.1

func MockTxnMgrWithReplica(log *xlog.Log, n int) (*fakedb.DB, *TxnManager, map[string]*Poolz, []string, func())

MockTxnMgrWithReplica mocks txn manager with replica-address.

func NewTxnManager

func NewTxnManager(log *xlog.Log) *TxnManager

NewTxnManager creates new TxnManager.

func (*TxnManager) Add

func (mgr *TxnManager) Add() error

Add used to add a txn to mgr.

func (*TxnManager) Close added in v1.0.2

func (mgr *TxnManager) Close()

Close is used to close the async worker xaCheck.

func (*TxnManager) CommitLock

func (mgr *TxnManager) CommitLock()

CommitLock used to acquire the commit.

func (*TxnManager) CommitRLock

func (mgr *TxnManager) CommitRLock()

CommitRLock used to acquire the read lock of commit.

func (*TxnManager) CommitRUnlock

func (mgr *TxnManager) CommitRUnlock()

CommitRUnlock used to release the read lock of commit.

func (*TxnManager) CommitUnlock

func (mgr *TxnManager) CommitUnlock()

CommitUnlock used to release the commit.

func (*TxnManager) CreateTxn

func (mgr *TxnManager) CreateTxn(backends map[string]*Poolz) (*Txn, error)

CreateTxn creates new txn.

func (*TxnManager) GetID

func (mgr *TxnManager) GetID() uint64

GetID returns a new txnid.

func (*TxnManager) Init added in v1.0.2

func (mgr *TxnManager) Init(scatter *Scatter, ScatterConf *config.ScatterConfig) error

Init is used to init the async worker xaCheck.

func (*TxnManager) Remove

func (mgr *TxnManager) Remove() error

Remove used to remove a txn from mgr.

type Txnz

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

Txnz holds a thread safe list of TxnDetails

func NewTxnz

func NewTxnz() *Txnz

NewTxnz creates a new Txnz

func (*Txnz) Add

func (tz *Txnz) Add(td *TxnDetail)

Add adds a TxnDetail to Txnz

func (*Txnz) GetTxnzRows

func (tz *Txnz) GetTxnzRows() []TxnDetailzRow

GetTxnzRows returns a list of TxnDetailzRow sorted by start time

func (*Txnz) Remove

func (tz *Txnz) Remove(td *TxnDetail)

Remove removes a TxnDetail from Txnz

type XaCheck added in v1.0.2

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

XaCheck tuple.

func NewXaCheck added in v1.0.2

func NewXaCheck(scatter *Scatter, conf *config.ScatterConfig) *XaCheck

NewXaCheck creates the XaCheck tuple.

func (*XaCheck) Close added in v1.0.2

func (xc *XaCheck) Close()

Close is used to close the xacheck goroutine

func (*XaCheck) GetRetrysLen added in v1.0.2

func (xc *XaCheck) GetRetrysLen() int

GetRetrysLen return the retrys num

func (*XaCheck) GetXaCheckFile added in v1.0.2

func (xc *XaCheck) GetXaCheckFile() string

GetXaCheckFile get the XaCheck log file

func (*XaCheck) Init added in v1.0.2

func (xc *XaCheck) Init() error

Init used to init xa check goroutine.

func (*XaCheck) LoadXaCommitErrLogs added in v1.0.2

func (xc *XaCheck) LoadXaCommitErrLogs() error

LoadXaCommitErrLogs is used to load all XaCommitErr from metadir/xacheck.json file.

func (*XaCheck) ReadXaCommitErrLogs added in v1.0.2

func (xc *XaCheck) ReadXaCommitErrLogs(data string) (*XaCommitErrs, error)

ReadXaCommitErrLogs is used to read the Xaredologs config from the data.

func (*XaCheck) RemoveXaCommitErrLogs added in v1.0.2

func (xc *XaCheck) RemoveXaCommitErrLogs() error

RemoveXaCommitErrLogs is only used to test to avoid the noise, XaCommitErrLogs can not be removed in the production environment, it is so important.

func (*XaCheck) WriteXaCommitErrLog added in v1.0.2

func (xc *XaCheck) WriteXaCommitErrLog(txn *Txn, state string) error

WriteXaCommitErrLog is used to write the xaCommitErrLog into the xacheck file.

type XaCommitErr added in v1.0.2

type XaCommitErr struct {
	Time  string `json:"time"`
	Xaid  string `json:"xaid"`
	State string `json:"state"`
	Times int    `json:"times"`
}

XaCommitErr tuple.

type XaCommitErrs added in v1.0.2

type XaCommitErrs struct {
	Logs []*XaCommitErr `json:"xacommit-errs"`
}

XaCommitErrs tuple

Jump to

Keyboard shortcuts

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