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) } }
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) } }
// 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 }
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 }
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 }