本文整理匯總了Golang中github.com/flike/kingshard/backend.Node類的典型用法代碼示例。如果您正苦於以下問題:Golang Node類的具體用法?Golang Node怎麽用?Golang Node使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Node類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: parseNode
func (s *Server) parseNode(cfg config.NodeConfig) (*backend.Node, error) {
n := new(backend.Node)
//n.server = s
n.Cfg = cfg
n.DownAfterNoAlive = time.Duration(cfg.DownAfterNoAlive) * time.Second
if len(cfg.Master) == 0 {
return nil, fmt.Errorf("must setting master MySQL node.")
}
var err error
if n.Master, err = n.OpenDB(cfg.Master); err != nil {
return nil, err
}
//n.db = n.Master
if len(cfg.Slave) > 0 {
if n.Slave, err = n.OpenDB(cfg.Slave); err != nil {
golog.Error("ClientConn", "handleShowProxy", err.Error(), 0)
n.Slave = nil
}
}
go n.Run()
return n, nil
}
示例2: getBackendConn
func (c *ClientConn) getBackendConn(n *backend.Node, fromSlave bool) (co *backend.BackendConn, err error) {
if !c.isInTransaction() {
if fromSlave {
co, err = n.GetSlaveConn()
if err != nil {
co, err = n.GetMasterConn()
}
} else {
co, err = n.GetMasterConn()
}
if err != nil {
golog.Error("server", "getBackendConn", err.Error(), 0)
return
}
} else {
var ok bool
co, ok = c.txConns[n]
if !ok {
if co, err = n.GetMasterConn(); err != nil {
return
}
if !c.isAutoCommit() {
if err = co.SetAutoCommit(0); err != nil {
return
}
} else {
if err = co.Begin(); err != nil {
return
}
}
c.txConns[n] = co
}
}
if err = co.UseDB(c.db); err != nil {
//reset the database to null
c.db = ""
return
}
if err = co.SetCharset(c.charset, c.collation); err != nil {
return
}
return
}
示例3: parseNode
func (s *Server) parseNode(cfg config.NodeConfig) (*backend.Node, error) {
var err error
n := new(backend.Node)
n.Cfg = cfg
n.DownAfterNoAlive = time.Duration(cfg.DownAfterNoAlive) * time.Second
err = n.ParseMaster(cfg.Master)
if err != nil {
return nil, err
}
err = n.ParseSlave(cfg.Slave)
if err != nil {
return nil, err
}
go n.CheckNode()
return n, nil
}
示例4: getBackendConn
func (c *ClientConn) getBackendConn(n *backend.Node, fromSlave bool) (co *backend.BackendConn, err error) {
if !c.needBeginTx() {
if fromSlave {
co, err = n.GetSlaveConn()
if err != nil {
co, err = n.GetMasterConn()
}
} else {
co, err = n.GetMasterConn()
}
if err != nil {
golog.Error("server", "getBackendConn", err.Error(), 0)
return
}
} else {
var ok bool
c.Lock()
co, ok = c.txConns[n]
c.Unlock()
if !ok {
if co, err = n.GetMasterConn(); err != nil {
return
}
if err = co.Begin(); err != nil {
return
}
c.Lock()
c.txConns[n] = co
c.Unlock()
}
}
//todo, set conn charset, etc...
if err = co.UseDB(c.db); err != nil {
return
}
if err = co.SetCharset(c.charset); err != nil {
return
}
return
}