本文整理匯總了Golang中github.com/ngaut/zkhelper.Conn.Set方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.Set方法的具體用法?Golang Conn.Set怎麽用?Golang Conn.Set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ngaut/zkhelper.Conn
的用法示例。
在下文中一共展示了Conn.Set方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: saveTimestamp
func saveTimestamp(conn zkhelper.Conn, rootPath string, ts int64) error {
var buf [8]byte
binary.BigEndian.PutUint64(buf[:], uint64(ts))
tsPath := getTimestampPath(rootPath)
_, err := conn.Set(tsPath, buf[:], -1)
if zkhelper.ZkErrorEqual(err, zk.ErrNoNode) {
_, err = conn.Create(tsPath, buf[:], 0, zk.WorldACL(zkhelper.PERM_FILE))
}
return errors.Trace(err)
}
示例2: SetProxyStatus
func SetProxyStatus(zkConn zkhelper.Conn, productName string, proxyName string, status string) error {
p, err := GetProxyInfo(zkConn, productName, proxyName)
if err != nil {
return errors.Trace(err)
}
if status != PROXY_STATE_ONLINE && status != PROXY_STATE_MARK_OFFLINE && status != PROXY_STATE_OFFLINE {
return errors.Errorf("%v, %s", ErrUnknownProxyStatus, status)
}
p.State = status
b, _ := json.Marshal(p)
_, err = zkConn.Set(path.Join(GetProxyPath(productName), proxyName), b, -1)
if err != nil {
return errors.Trace(err)
}
if status == PROXY_STATE_MARK_OFFLINE {
// wait for the proxy down
for {
_, _, c, err := zkConn.GetW(path.Join(GetProxyPath(productName), proxyName))
if zkhelper.ZkErrorEqual(err, zk.ErrNoNode) {
return nil
} else if err != nil {
return errors.Trace(err)
}
<-c
info, err := GetProxyInfo(zkConn, productName, proxyName)
log.Info("mark_offline, check proxy status:", proxyName, info, err)
if zkhelper.ZkErrorEqual(err, zk.ErrNoNode) {
log.Info("shutdown proxy successful")
return nil
} else if err != nil {
return errors.Trace(err)
}
if info.State == PROXY_STATE_OFFLINE {
log.Info("proxy:", proxyName, "offline success!")
return nil
}
}
}
return nil
}
示例3: SetProxyStatus
func SetProxyStatus(zkConn zkhelper.Conn, productName string, proxyName string, status string) error {
p, err := GetProxyInfo(zkConn, productName, proxyName)
if err != nil {
return errors.Trace(err)
}
if status != PROXY_STATE_ONLINE && status != PROXY_STATE_MARK_OFFLINE && status != PROXY_STATE_OFFLINE {
return errors.Errorf("%v, %s", ErrUnknownProxyStatus, status)
}
// check slot status before setting proxy online
if status == PROXY_STATE_ONLINE {
slots, err := Slots(zkConn, productName)
if err != nil {
return errors.Trace(err)
}
for _, slot := range slots {
if slot.State.Status != SLOT_STATUS_ONLINE {
return errors.Errorf("slot %v is not online", slot)
}
if slot.GroupId == INVALID_ID {
return errors.Errorf("slot %v has invalid group id", slot)
}
}
}
p.State = status
b, _ := json.Marshal(p)
_, err = zkConn.Set(path.Join(GetProxyPath(productName), proxyName), b, -1)
if err != nil {
return errors.Trace(err)
}
if status == PROXY_STATE_MARK_OFFLINE {
// wait for the proxy down
for {
_, _, c, err := zkConn.GetW(path.Join(GetProxyPath(productName), proxyName))
if zkhelper.ZkErrorEqual(err, zk.ErrNoNode) {
return nil
} else if err != nil {
return errors.Trace(err)
}
<-c
info, err := GetProxyInfo(zkConn, productName, proxyName)
log.Info("mark_offline, check proxy status:", proxyName, info, err)
if zkhelper.ZkErrorEqual(err, zk.ErrNoNode) {
log.Info("shutdown proxy successful")
return nil
} else if err != nil {
return errors.Trace(err)
}
if info.State == PROXY_STATE_OFFLINE {
log.Info("proxy:", proxyName, "offline success!")
return nil
}
}
}
return nil
}