本文整理匯總了Golang中github.com/wandoulabs/zkhelper.Conn.Get方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.Get方法的具體用法?Golang Conn.Get怎麽用?Golang Conn.Get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/wandoulabs/zkhelper.Conn
的用法示例。
在下文中一共展示了Conn.Get方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RemoveServer
func (self *ServerGroup) RemoveServer(zkConn zkhelper.Conn, addr string) error {
zkPath := fmt.Sprintf("/zk/codis/db_%s/servers/group_%d/%s", self.ProductName, self.Id, addr)
data, _, err := zkConn.Get(zkPath)
if err != nil {
return errors.Trace(err)
}
var s Server
err = json.Unmarshal(data, &s)
if err != nil {
return errors.Trace(err)
}
log.Info(s)
if s.Type == SERVER_TYPE_MASTER {
return errors.Errorf("cannot remove master, use promote first")
}
err = zkConn.Delete(zkPath, -1)
if err != nil {
return errors.Trace(err)
}
// update server list
for i := 0; i < len(self.Servers); i++ {
if self.Servers[i].Addr == s.Addr {
self.Servers = append(self.Servers[:i], self.Servers[i+1:]...)
break
}
}
// remove slave won't need proxy confirm
err = NewAction(zkConn, self.ProductName, ACTION_TYPE_SERVER_GROUP_CHANGED, self, "", false)
return errors.Trace(err)
}
示例2: GetServer
func GetServer(zkConn zkhelper.Conn, zkPath string) (*Server, error) {
data, _, err := zkConn.Get(zkPath)
if err != nil {
return nil, errors.Trace(err)
}
srv := Server{}
if err := json.Unmarshal(data, &srv); err != nil {
return nil, errors.Trace(err)
}
return &srv, nil
}
示例3: GetActionObject
func GetActionObject(zkConn zkhelper.Conn, productName string, seq int64, act interface{}, provider string) error {
data, _, err := zkConn.Get(path.Join(GetWatchActionPath(productName), zkConn.Seq2Str(seq)))
if err != nil {
return errors.Trace(err)
}
if err := json.Unmarshal(data, act); err != nil {
return errors.Trace(err)
}
return nil
}
示例4: GetActionWithSeq
func GetActionWithSeq(zkConn zkhelper.Conn, productName string, seq int64, provider string) (*Action, error) {
var act Action
data, _, err := zkConn.Get(path.Join(GetWatchActionPath(productName), zkConn.Seq2Str(seq)))
if err != nil {
return nil, errors.Trace(err)
}
if err := json.Unmarshal(data, &act); err != nil {
return nil, errors.Trace(err)
}
return &act, nil
}
示例5: GetSlot
func GetSlot(zkConn zkhelper.Conn, productName string, id int) (*Slot, error) {
zkPath := GetSlotPath(productName, id)
data, _, err := zkConn.Get(zkPath)
if err != nil {
return nil, errors.Trace(err)
}
var slot Slot
if err := json.Unmarshal(data, &slot); err != nil {
return nil, errors.Trace(err)
}
return &slot, nil
}
示例6: GetProxyInfo
func GetProxyInfo(zkConn zkhelper.Conn, productName string, proxyName string) (*ProxyInfo, error) {
var pi ProxyInfo
data, _, err := zkConn.Get(path.Join(GetProxyPath(productName), proxyName))
if err != nil {
return nil, errors.Trace(err)
}
if err := json.Unmarshal(data, &pi); err != nil {
return nil, errors.Trace(err)
}
return &pi, nil
}
示例7: Slots
func Slots(zkConn zkhelper.Conn, productName string) ([]*Slot, error) {
zkPath := GetSlotBasePath(productName)
children, _, err := zkConn.Children(zkPath)
if err != nil {
return nil, errors.Trace(err)
}
var slots []*Slot
for _, p := range children {
data, _, err := zkConn.Get(path.Join(zkPath, p))
if err != nil {
return nil, errors.Trace(err)
}
slot := &Slot{}
if err := json.Unmarshal(data, &slot); err != nil {
return nil, errors.Trace(err)
}
slots = append(slots, slot)
}
return slots, nil
}
示例8: ActionGC
func ActionGC(zkConn zkhelper.Conn, productName string, gcType int, keep int) error {
prefix := GetWatchActionPath(productName)
respPrefix := GetActionResponsePath(productName)
exists, err := zkhelper.NodeExists(zkConn, prefix)
if err != nil {
return errors.Trace(err)
}
if !exists {
// if action path not exists just return nil
return nil
}
actions, _, err := zkConn.Children(prefix)
if err != nil {
return errors.Trace(err)
}
var act Action
currentTs := time.Now().Unix()
if gcType == GC_TYPE_N {
sort.Strings(actions)
// keep last 500 actions
if len(actions)-500 <= keep {
return nil
}
for _, action := range actions[:len(actions)-keep-500] {
if err := zkhelper.DeleteRecursive(zkConn, path.Join(prefix, action), -1); err != nil {
return errors.Trace(err)
}
err := zkhelper.DeleteRecursive(zkConn, path.Join(respPrefix, action), -1)
if err != nil && !zkhelper.ZkErrorEqual(err, zk.ErrNoNode) {
return errors.Trace(err)
}
}
} else if gcType == GC_TYPE_SEC {
secs := keep
for _, action := range actions {
b, _, err := zkConn.Get(path.Join(prefix, action))
if err != nil {
return errors.Trace(err)
}
if err := json.Unmarshal(b, &act); err != nil {
return errors.Trace(err)
}
log.Infof("action = %s, timestamp = %s", action, act.Ts)
ts, _ := strconv.ParseInt(act.Ts, 10, 64)
if currentTs-ts > int64(secs) {
if err := zkhelper.DeleteRecursive(zkConn, path.Join(prefix, action), -1); err != nil {
return errors.Trace(err)
}
err := zkhelper.DeleteRecursive(zkConn, path.Join(respPrefix, action), -1)
if err != nil && !zkhelper.ZkErrorEqual(err, zk.ErrNoNode) {
return errors.Trace(err)
}
}
}
actionResps, _, err := zkConn.Children(respPrefix)
if err != nil {
return errors.Trace(err)
}
for _, action := range actionResps {
b, _, err := zkConn.Get(path.Join(respPrefix, action))
if err != nil {
return errors.Trace(err)
}
if err := json.Unmarshal(b, &act); err != nil {
return errors.Trace(err)
}
log.Infof("action = %s, timestamp = %s", action, act.Ts)
ts, _ := strconv.ParseInt(act.Ts, 10, 64)
if currentTs-ts > int64(secs) {
if err := zkhelper.DeleteRecursive(zkConn, path.Join(respPrefix, action), -1); err != nil {
return errors.Trace(err)
}
}
}
}
return nil
}