本文整理汇总了Golang中github.com/wandoulabs/zkhelper.Conn类的典型用法代码示例。如果您正苦于以下问题:Golang Conn类的具体用法?Golang Conn怎么用?Golang Conn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Conn类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: RemoveServer
func (self *ServerGroup) RemoveServer(zkConn zkhelper.Conn, addr string) error {
zkPath := fmt.Sprintf("/zk/codis/db_%s/servers/group_%d/%s", self.ProductName, self.Id, addr)
data, _, err := zkConn.Get(zkPath)
if err != nil {
return errors.Trace(err)
}
var s Server
err = json.Unmarshal(data, &s)
if err != nil {
return errors.Trace(err)
}
log.Info(s)
if s.Type == SERVER_TYPE_MASTER {
return errors.Errorf("cannot remove master, use promote first")
}
err = zkConn.Delete(zkPath, -1)
if err != nil {
return errors.Trace(err)
}
// update server list
for i := 0; i < len(self.Servers); i++ {
if self.Servers[i].Addr == s.Addr {
self.Servers = append(self.Servers[:i], self.Servers[i+1:]...)
break
}
}
// remove slave won't need proxy confirm
err = NewAction(zkConn, self.ProductName, ACTION_TYPE_SERVER_GROUP_CHANGED, self, "", false)
return errors.Trace(err)
}
开发者ID:cougar731,项目名称:codis,代码行数:34,代码来源:server_group.go
示例2: GetActionSeqList
func GetActionSeqList(zkConn zkhelper.Conn, productName string) ([]int, error) {
nodes, _, err := zkConn.Children(GetWatchActionPath(productName))
if err != nil {
return nil, errors.Trace(err)
}
return ExtraSeqList(nodes)
}
开发者ID:cyflhn,项目名称:codis,代码行数:7,代码来源:action.go
示例3: ServerGroups
func ServerGroups(zkConn zkhelper.Conn, productName string) ([]*ServerGroup, error) {
var ret []*ServerGroup
root := fmt.Sprintf("/zk/codis/db_%s/servers", productName)
groups, _, err := zkConn.Children(root)
if err != nil {
return nil, errors.Trace(err)
}
// Buggy :X
//zkhelper.ChildrenRecursive(*zkConn, root)
for _, group := range groups {
// parse group_1 => 1
groupId, err := strconv.Atoi(strings.Split(group, "_")[1])
if err != nil {
return nil, errors.Trace(err)
}
g, err := GetGroup(zkConn, productName, groupId)
if err != nil {
return nil, errors.Trace(err)
}
ret = append(ret, g)
}
return ret, nil
}
开发者ID:cougar731,项目名称:codis,代码行数:25,代码来源:server_group.go
示例4: WaitForReceiverWithTimeout
func WaitForReceiverWithTimeout(zkConn zkhelper.Conn, productName string, actionZkPath string, proxies []ProxyInfo, timeoutInMs int) error {
if len(proxies) == 0 {
return nil
}
times := 0
proxyIds := make(map[string]struct{})
var offlineProxyIds []string
for _, p := range proxies {
proxyIds[p.Id] = struct{}{}
}
checkTimes := timeoutInMs / 500
// check every 500ms
for times < checkTimes {
if times >= 6 && (times*500)%1000 == 0 {
log.Warnf("abnormal waiting time for receivers: %s %v", actionZkPath, offlineProxyIds)
}
// get confirm ids
nodes, _, err := zkConn.Children(actionZkPath)
if err != nil {
return errors.Trace(err)
}
confirmIds := make(map[string]struct{})
for _, node := range nodes {
id := path.Base(node)
confirmIds[id] = struct{}{}
}
if len(confirmIds) != 0 {
match := true
// check if all proxy have responsed
var notMatchList []string
for id, _ := range proxyIds {
// if proxy id not in confirm ids, means someone didn't response
if _, ok := confirmIds[id]; !ok {
match = false
notMatchList = append(notMatchList, id)
}
}
if match {
return nil
}
offlineProxyIds = notMatchList
}
times += 1
time.Sleep(500 * time.Millisecond)
}
if len(offlineProxyIds) > 0 {
log.Errorf("proxies didn't responed: %v", offlineProxyIds)
}
// set offline proxies
for _, id := range offlineProxyIds {
log.Errorf("mark proxy %s to PROXY_STATE_MARK_OFFLINE", id)
if err := SetProxyStatus(zkConn, productName, id, PROXY_STATE_MARK_OFFLINE); err != nil {
return errors.Trace(err)
}
}
return errors.Trace(ErrReceiverTimeout)
}
开发者ID:cookiebus,项目名称:codis,代码行数:60,代码来源:action.go
示例5: 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)
}
}
开发者ID:YongMan,项目名称:codis,代码行数:8,代码来源:action_test.go
示例6: GroupExists
func GroupExists(zkConn zkhelper.Conn, productName string, groupId int) (bool, error) {
zkPath := fmt.Sprintf("/zk/codis/db_%s/servers/group_%d", productName, groupId)
exists, _, err := zkConn.Exists(zkPath)
if err != nil {
return false, errors.Trace(err)
}
return exists, nil
}
开发者ID:cougar731,项目名称:codis,代码行数:8,代码来源:server_group.go
示例7: CreateProxyInfo
func CreateProxyInfo(zkConn zkhelper.Conn, productName string, pi *ProxyInfo) (string, error) {
data, err := json.Marshal(pi)
if err != nil {
return "", errors.Trace(err)
}
dir := GetProxyPath(productName)
zkhelper.CreateRecursive(zkConn, dir, "", 0, zkhelper.DefaultDirACLs())
return zkConn.Create(path.Join(dir, pi.Id), data, zk.FlagEphemeral, zkhelper.DefaultFileACLs())
}
开发者ID:cougar731,项目名称:codis,代码行数:9,代码来源:proxy.go
示例8: doResponseForTest
func doResponseForTest(conn zkhelper.Conn, seq string, pi *ProxyInfo) error {
actionPath := GetActionResponsePath(productName) + "/" + seq
data, err := json.Marshal(pi)
if err != nil {
return errors.Trace(err)
}
_, err = conn.Create(path.Join(actionPath, pi.Id), data,
0, zkhelper.DefaultFileACLs())
return err
}
开发者ID:YongMan,项目名称:codis,代码行数:11,代码来源:action_test.go
示例9: GetServer
func GetServer(zkConn zkhelper.Conn, zkPath string) (*Server, error) {
data, _, err := zkConn.Get(zkPath)
if err != nil {
return nil, errors.Trace(err)
}
srv := Server{}
if err := json.Unmarshal(data, &srv); err != nil {
return nil, errors.Trace(err)
}
return &srv, nil
}
开发者ID:cougar731,项目名称:codis,代码行数:11,代码来源:server_group.go
示例10: GetActionObject
func GetActionObject(zkConn zkhelper.Conn, productName string, seq int64, act interface{}, provider string) error {
data, _, err := zkConn.Get(path.Join(GetWatchActionPath(productName), zkConn.Seq2Str(seq)))
if err != nil {
return errors.Trace(err)
}
if err := json.Unmarshal(data, act); err != nil {
return errors.Trace(err)
}
return nil
}
开发者ID:cyflhn,项目名称:codis,代码行数:12,代码来源:action.go
示例11: CreateOrUpdate
func CreateOrUpdate(zconn zkhelper.Conn, zkPath, value string, flags int, aclv []topo.ACL, recursive bool) (pathCreated string, err error) {
if recursive {
pathCreated, err = CreateRecursive(zconn, zkPath, value, flags, aclv)
} else {
pathCreated, err = zconn.Create(zkPath, []byte(value), int32(flags), aclv)
}
if err != nil && zkhelper.ZkErrorEqual(err, topo.ErrNodeExists) {
pathCreated = ""
_, err = zconn.Set(zkPath, []byte(value), -1)
}
return
}
开发者ID:wfxiang08,项目名称:zero_rpc_proxy,代码行数:12,代码来源:topology.go
示例12: GetActionWithSeq
func GetActionWithSeq(zkConn zkhelper.Conn, productName string, seq int64, provider string) (*Action, error) {
var act Action
data, _, err := zkConn.Get(path.Join(GetWatchActionPath(productName), zkConn.Seq2Str(seq)))
if err != nil {
return nil, errors.Trace(err)
}
if err := json.Unmarshal(data, &act); err != nil {
return nil, errors.Trace(err)
}
return &act, nil
}
开发者ID:cyflhn,项目名称:codis,代码行数:12,代码来源:action.go
示例13: GetSlot
func GetSlot(zkConn zkhelper.Conn, productName string, id int) (*Slot, error) {
zkPath := GetSlotPath(productName, id)
data, _, err := zkConn.Get(zkPath)
if err != nil {
return nil, errors.Trace(err)
}
var slot Slot
if err := json.Unmarshal(data, &slot); err != nil {
return nil, errors.Trace(err)
}
return &slot, nil
}
开发者ID:cookiebus,项目名称:codis,代码行数:13,代码来源:slot.go
示例14: GetProxyInfo
func GetProxyInfo(zkConn zkhelper.Conn, productName string, proxyName string) (*ProxyInfo, error) {
var pi ProxyInfo
data, _, err := zkConn.Get(path.Join(GetProxyPath(productName), proxyName))
if err != nil {
return nil, errors.Trace(err)
}
if err := json.Unmarshal(data, &pi); err != nil {
return nil, errors.Trace(err)
}
return &pi, nil
}
开发者ID:cougar731,项目名称:codis,代码行数:13,代码来源:proxy.go
示例15: GetFenceProxyMap
func GetFenceProxyMap(zkConn zkhelper.Conn, productName string) (map[string]bool, error) {
children, _, err := zkConn.Children(GetProxyFencePath(productName))
if err != nil {
if err.Error() == zk.ErrNoNode.Error() {
return make(map[string]bool), nil
} else {
return nil, err
}
}
m := make(map[string]bool, len(children))
for _, fenceNode := range children {
m[fenceNode] = true
}
return m, nil
}
开发者ID:cougar731,项目名称:codis,代码行数:15,代码来源:proxy.go
示例16: GetServers
func (self *ServerGroup) GetServers(zkConn zkhelper.Conn) ([]*Server, error) {
var ret []*Server
root := fmt.Sprintf("/zk/codis/db_%s/servers/group_%d", self.ProductName, self.Id)
nodes, _, err := zkConn.Children(root)
if err != nil {
return nil, errors.Trace(err)
}
for _, node := range nodes {
nodePath := root + "/" + node
s, err := GetServer(zkConn, nodePath)
if err != nil {
return nil, errors.Trace(err)
}
ret = append(ret, s)
}
return ret, nil
}
开发者ID:cougar731,项目名称:codis,代码行数:17,代码来源:server_group.go
示例17: ForceRemoveLock
func ForceRemoveLock(zkConn zkhelper.Conn, productName string) error {
lockPath := fmt.Sprintf("/zk/codis/db_%s/LOCK", productName)
children, _, err := zkConn.Children(lockPath)
if err != nil && !zkhelper.ZkErrorEqual(err, zk.ErrNoNode) {
return errors.Trace(err)
}
for _, c := range children {
fullPath := path.Join(lockPath, c)
log.Info("deleting..", fullPath)
err := zkConn.Delete(fullPath, 0)
if err != nil {
return errors.Trace(err)
}
}
return nil
}
开发者ID:cyflhn,项目名称:codis,代码行数:18,代码来源:action.go
示例18: WaitForReceiverWithTimeout
func WaitForReceiverWithTimeout(zkConn zkhelper.Conn, productName string, actionZkPath string, proxies []ProxyInfo, timeoutInMs int) error {
if len(proxies) == 0 {
return nil
}
times := 0
proxyIds := make(map[string]bool)
for _, p := range proxies {
proxyIds[p.Id] = true
}
// check every 500ms
for times < timeoutInMs/500 {
if times >= 6 && (times*500)%1000 == 0 {
log.Warnf("abnormal waiting time for receivers: %s %v", actionZkPath, proxyIds)
}
// get confirm ids
nodes, _, err := zkConn.Children(actionZkPath)
if err != nil {
return errors.Trace(err)
}
for _, node := range nodes {
id := path.Base(node)
delete(proxyIds, id)
}
if len(proxyIds) == 0 {
return nil
}
times++
time.Sleep(500 * time.Millisecond)
}
log.Warn("proxies didn't responed: ", proxyIds)
// set offline proxies
/*
for id, _ := range proxyIds {
log.Errorf("mark proxy %s to PROXY_STATE_MARK_OFFLINE", id)
if err := SetProxyStatus(zkConn, productName, id, PROXY_STATE_MARK_OFFLINE); err != nil {
return errors.Trace(err)
}
}
*/
return ErrReceiverTimeout
}
开发者ID:cyflhn,项目名称:codis,代码行数:42,代码来源:action.go
示例19: ProxyList
func ProxyList(zkConn zkhelper.Conn, productName string, filter func(*ProxyInfo) bool) ([]ProxyInfo, error) {
ret := make([]ProxyInfo, 0)
root := GetProxyPath(productName)
proxies, _, err := zkConn.Children(root)
if err != nil && !zkhelper.ZkErrorEqual(err, zk.ErrNoNode) {
return nil, errors.Trace(err)
}
for _, proxyName := range proxies {
pi, err := GetProxyInfo(zkConn, productName, proxyName)
if err != nil {
return nil, errors.Trace(err)
}
if filter == nil || filter(pi) == true {
ret = append(ret, *pi)
}
}
return ret, nil
}
开发者ID:cougar731,项目名称:codis,代码行数:20,代码来源:proxy.go
示例20: Slots
func Slots(zkConn zkhelper.Conn, productName string) ([]*Slot, error) {
zkPath := GetSlotBasePath(productName)
children, _, err := zkConn.Children(zkPath)
if err != nil {
return nil, errors.Trace(err)
}
var slots []*Slot
for _, p := range children {
data, _, err := zkConn.Get(path.Join(zkPath, p))
if err != nil {
return nil, errors.Trace(err)
}
slot := &Slot{}
if err := json.Unmarshal(data, &slot); err != nil {
return nil, errors.Trace(err)
}
slots = append(slots, slot)
}
return slots, nil
}
开发者ID:cookiebus,项目名称:codis,代码行数:21,代码来源:slot.go
注:本文中的github.com/wandoulabs/zkhelper.Conn类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论