本文整理匯總了Golang中github.com/ngaut/zkhelper.Conn.GetW方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.GetW方法的具體用法?Golang Conn.GetW怎麽用?Golang Conn.GetW使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ngaut/zkhelper.Conn
的用法示例。
在下文中一共展示了Conn.GetW方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: waitForProxyMarkOffline
func waitForProxyMarkOffline(coordConn zkhelper.Conn, proxyName string) {
_, _, c, _ := coordConn.GetW(path.Join(GetProxyPath(productName), proxyName))
<-c
// test action need response, if proxy not responsed, then marked offline
info, _ := GetProxyInfo(coordConn, productName, proxyName)
if info.State == PROXY_STATE_MARK_OFFLINE {
SetProxyStatus(coordConn, productName, proxyName, PROXY_STATE_OFFLINE)
}
}
示例3: GetWatchLeader
// GetWatchLeader gets the leader tso address in zookeeper and returns a watcher for leader change.
func GetWatchLeader(conn zkhelper.Conn, rootPath string) (string, <-chan zk.Event, error) {
data, _, watcher, err := conn.GetW(getLeaderPath(rootPath))
if err != nil {
return "", nil, errors.Trace(err)
}
addr, err := getLeader(data)
if err != nil {
return "", nil, errors.Trace(err)
}
// if err != checkLeaderExists(conn); err != nil {
// return "", errors.Trace(err)
// }
return addr, watcher, nil
}
示例4: 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
}
示例5: 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
}