func (self *ServerGroup) Exists(zkConn zkhelper.Conn) (bool, error) { zkPath := fmt.Sprintf("/zk/codis/db_%s/servers/group_%d", self.ProductName, self.Id) b, err := zkhelper.NodeExists(zkConn, zkPath) if err != nil { return false, errors.Trace(err) } return b, nil }
func (sg *ServerGroup) Exists(coordConn zkhelper.Conn) (bool, error) { coordPath := fmt.Sprintf("/zk/reborn/db_%s/servers/group_%d", sg.ProductName, sg.Id) b, err := zkhelper.NodeExists(coordConn, coordPath) if err != nil { return false, errors.Trace(err) } return b, nil }
func ActionGC(zkConn zkhelper.Conn, productName string, gcType int, keep int) error { prefix := GetWatchActionPath(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) if len(actions) <= keep { return nil } for _, action := range actions[:len(actions)-keep] { if err := zkhelper.DeleteRecursive(zkConn, path.Join(prefix, action), -1); err != nil { 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.Info(action, act.Ts) ts, _ := strconv.ParseInt(act.Ts, 10, 64) if currentTs-ts > int64(secs) { if err := zkConn.Delete(path.Join(prefix, action), -1); err != nil { return errors.Trace(err) } } } } return nil }
func CreateActionRootPath(zkConn zkhelper.Conn, path string) error { // if action dir not exists, create it first exists, err := zkhelper.NodeExists(zkConn, path) if err != nil { return errors.Trace(err) } if !exists { _, err := zkhelper.CreateOrUpdate(zkConn, path, "", 0, zkhelper.DefaultDirACLs(), true) if err != nil { return errors.Trace(err) } } return nil }
func (top *Topology) Exist(path string) (bool, error) { return zkhelper.NodeExists(top.coordConn, path) }