本文整理匯總了Golang中github.com/wandoulabs/zkhelper.Conn.GetW方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.GetW方法的具體用法?Golang Conn.GetW怎麽用?Golang Conn.GetW使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/wandoulabs/zkhelper.Conn
的用法示例。
在下文中一共展示了Conn.GetW方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: waitForProxyMarkOffline
func waitForProxyMarkOffline(zkConn zkhelper.Conn, proxyName string) {
_, _, c, _ := zkConn.GetW(path.Join(GetProxyPath(productName), proxyName))
<-c
info, _ := GetProxyInfo(zkConn, productName, proxyName)
if info.State == PROXY_STATE_MARK_OFFLINE {
SetProxyStatus(zkConn, productName, proxyName, PROXY_STATE_OFFLINE)
}
}
示例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)
}
// 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 && slot.State.Status != SLOT_STATUS_MIGRATE {
return errors.Errorf("slot %v is not online or migrate", 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.Infof("proxy: %s offline success!", proxyName)
return nil
}
}
}
return nil
}