本文整理匯總了Golang中github.com/flike/kingshard/backend.BackendConn類的典型用法代碼示例。如果您正苦於以下問題:Golang BackendConn類的具體用法?Golang BackendConn怎麽用?Golang BackendConn使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了BackendConn類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: executeInNode
func (c *ClientConn) executeInNode(conn *backend.BackendConn, sql string, args []interface{}) ([]*mysql.Result, error) {
var state string
startTime := time.Now().UnixNano()
r, err := conn.Execute(sql, args...)
if err != nil {
state = "ERROR"
} else {
state = "OK"
}
execTime := float64(time.Now().UnixNano()-startTime) / float64(time.Millisecond)
if strings.ToLower(c.proxy.logSql[c.proxy.logSqlIndex]) != golog.LogSqlOff &&
execTime > float64(c.proxy.slowLogTime[c.proxy.slowLogTimeIndex]) {
c.proxy.counter.IncrSlowLogTotal()
golog.OutputSql(state, "%.1fms - %s->%s:%s",
execTime,
c.c.RemoteAddr(),
conn.GetAddr(),
sql,
)
}
if err != nil {
return nil, err
}
return []*mysql.Result{r}, err
}
示例2: handleUseDB
func (c *ClientConn) handleUseDB(dbName string) error {
var co *backend.BackendConn
var err error
if len(dbName) == 0 {
return fmt.Errorf("must have database, the length of dbName is zero")
}
if c.schema == nil {
return mysql.NewDefaultError(mysql.ER_NO_DB_ERROR)
}
nodeName := c.schema.rule.DefaultRule.Nodes[0]
n := c.proxy.GetNode(nodeName)
//get the connection from slave preferentially
co, err = n.GetSlaveConn()
if err != nil {
co, err = n.GetMasterConn()
}
defer c.closeConn(co, false)
if err != nil {
return err
}
if err = co.UseDB(dbName); err != nil {
return err
}
c.db = dbName
return c.writeOK(nil)
}
示例3: closeConn
func (c *ClientConn) closeConn(conn *backend.BackendConn, rollback bool) {
if c.isInTransaction() {
return
}
if rollback {
conn.Rollback()
}
conn.Close()
}
示例4: executeInNode
func (c *ClientConn) executeInNode(conn *backend.BackendConn, sql string, args []interface{}) ([]*mysql.Result, error) {
var state string
r, err := conn.Execute(sql, args...)
if err != nil {
state = "ERROR"
} else {
state = "INFO"
}
if strings.ToLower(c.proxy.cfg.LogSql) != golog.LogSqlOff {
golog.OutputSql(state, "%s->%s:%s",
c.c.RemoteAddr(),
conn.GetAddr(),
sql,
)
}
if err != nil {
return nil, err
}
return []*mysql.Result{r}, err
}