本文整理汇总了Golang中github.com/YongMan/codis/pkg/utils/errors.Trace函数的典型用法代码示例。如果您正苦于以下问题:Golang Trace函数的具体用法?Golang Trace怎么用?Golang Trace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Trace函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Rebalance
// experimental simple auto rebalance :)
func Rebalance() error {
targetQuota, err := getQuotaMap(safeZkConn)
if err != nil {
return errors.Trace(err)
}
livingNodes, err := getLivingNodeInfos(safeZkConn)
if err != nil {
return errors.Trace(err)
}
log.Infof("start rebalance")
for _, node := range livingNodes {
for len(node.CurSlots) > targetQuota[node.GroupId] {
for _, dest := range livingNodes {
if dest.GroupId != node.GroupId && len(dest.CurSlots) < targetQuota[dest.GroupId] {
slot := node.CurSlots[len(node.CurSlots)-1]
// create a migration task
info := &MigrateTaskInfo{
Delay: 0,
SlotId: slot,
NewGroupId: dest.GroupId,
Status: MIGRATE_TASK_PENDING,
CreateAt: strconv.FormatInt(time.Now().Unix(), 10),
}
globalMigrateManager.PostTask(info)
node.CurSlots = node.CurSlots[0 : len(node.CurSlots)-1]
dest.CurSlots = append(dest.CurSlots, slot)
}
}
}
}
log.Infof("rebalance tasks submit finish")
return nil
}
开发者ID:YongMan,项目名称:codis,代码行数:35,代码来源:rebalancer.go
示例2: decodeResp
func (d *Decoder) decodeResp(depth int) (*Resp, error) {
b, err := d.ReadByte()
if err != nil {
return nil, errors.Trace(err)
}
switch t := RespType(b); t {
case TypeString, TypeError, TypeInt:
r := &Resp{Type: t}
r.Value, err = d.decodeTextBytes()
return r, err
case TypeBulkBytes:
r := &Resp{Type: t}
r.Value, err = d.decodeBulkBytes()
return r, err
case TypeArray:
r := &Resp{Type: t}
r.Array, err = d.decodeArray(depth)
return r, err
default:
if depth != 0 {
return nil, errors.Errorf("bad resp type %s", t)
}
if err := d.UnreadByte(); err != nil {
return nil, errors.Trace(err)
}
r := &Resp{Type: TypeArray}
r.Array, err = d.decodeSingleLineBulkBytesArray()
return r, err
}
}
开发者ID:YongMan,项目名称:codis,代码行数:30,代码来源:decoder.go
示例3: 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:YongMan,项目名称:codis,代码行数:34,代码来源:server_group.go
示例4: Ops
func (p *ProxyInfo) Ops() (int64, error) {
resp, err := http.Get("http://" + p.DebugVarAddr + "/debug/vars")
if err != nil {
return -1, errors.Trace(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return -1, errors.Trace(err)
}
m := make(map[string]interface{})
err = json.Unmarshal(body, &m)
if err != nil {
return -1, errors.Trace(err)
}
if v, ok := m["router"]; ok {
if vv, ok := v.(map[string]interface{})["ops"]; ok {
return int64(vv.(float64)), nil
}
}
return 0, nil
}
开发者ID:YongMan,项目名称:codis,代码行数:26,代码来源:proxy.go
示例5: ForceRemoveDeadFence
func ForceRemoveDeadFence(zkConn zkhelper.Conn, productName string) error {
proxies, err := ProxyList(zkConn, productName, func(p *ProxyInfo) bool {
return p.State == PROXY_STATE_ONLINE
})
if err != nil {
return errors.Trace(err)
}
fenceProxies, err := GetFenceProxyMap(zkConn, productName)
if err != nil {
return errors.Trace(err)
}
// remove online proxies's fence
for _, proxy := range proxies {
delete(fenceProxies, proxy.Addr)
}
// delete dead fence in zookeeper
path := GetProxyFencePath(productName)
for remainFence, _ := range fenceProxies {
fencePath := filepath.Join(path, remainFence)
log.Info("removing fence: ", fencePath)
if err := zkhelper.DeleteRecursive(zkConn, fencePath, -1); err != nil {
return errors.Trace(err)
}
}
return nil
}
开发者ID:YongMan,项目名称:codis,代码行数:27,代码来源:action.go
示例6: 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:YongMan,项目名称:codis,代码行数:25,代码来源:server_group.go
示例7: GetRedisStat
func GetRedisStat(addr, passwd string) (map[string]string, error) {
c, err := DialTo(addr, passwd)
if err != nil {
return nil, err
}
defer c.Close()
ret, err := redis.String(c.Do("INFO"))
if err != nil {
return nil, errors.Trace(err)
}
m := make(map[string]string)
lines := strings.Split(ret, "\n")
for _, line := range lines {
kv := strings.SplitN(line, ":", 2)
if len(kv) == 2 {
k, v := strings.TrimSpace(kv[0]), strings.TrimSpace(kv[1])
m[k] = v
}
}
reply, err := redis.Strings(c.Do("config", "get", "maxmemory"))
if err != nil {
return nil, errors.Trace(err)
}
// we got result
if len(reply) == 2 {
if reply[1] != "0" {
m["maxmemory"] = reply[1]
} else {
m["maxmemory"] = "∞"
}
}
return m, nil
}
开发者ID:YongMan,项目名称:codis,代码行数:35,代码来源:redis.go
示例8: SlotsInfo
func SlotsInfo(addr, passwd string, fromSlot, toSlot int) (map[int]int, error) {
c, err := DialTo(addr, passwd)
if err != nil {
return nil, err
}
defer c.Close()
infos, err := redis.Values(c.Do("SLOTSINFO", fromSlot, toSlot-fromSlot+1))
if err != nil {
return nil, errors.Trace(err)
}
slots := make(map[int]int)
if infos != nil {
for i := 0; i < len(infos); i++ {
info, err := redis.Values(infos[i], nil)
if err != nil {
return nil, errors.Trace(err)
}
var slotid, slotsize int
if _, err := redis.Scan(info, &slotid, &slotsize); err != nil {
return nil, errors.Trace(err)
} else {
slots[slotid] = slotsize
}
}
}
return slots, nil
}
开发者ID:YongMan,项目名称:codis,代码行数:29,代码来源:redis.go
示例9: encodeTextBytes
func (e *Encoder) encodeTextBytes(b []byte) error {
if _, err := e.Write(b); err != nil {
return errors.Trace(err)
}
if _, err := e.WriteString("\r\n"); err != nil {
return errors.Trace(err)
}
return nil
}
开发者ID:YongMan,项目名称:codis,代码行数:9,代码来源:encoder.go
示例10: encodeTextString
func (e *Encoder) encodeTextString(s string) error {
if _, err := e.WriteString(s); err != nil {
return errors.Trace(err)
}
if _, err := e.WriteString("\r\n"); err != nil {
return errors.Trace(err)
}
return nil
}
开发者ID:YongMan,项目名称:codis,代码行数:9,代码来源:encoder.go
示例11: 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:YongMan,项目名称:codis,代码行数:11,代码来源:server_group.go
示例12: decodeTextBytes
func (d *Decoder) decodeTextBytes() ([]byte, error) {
b, err := d.ReadBytes('\n')
if err != nil {
return nil, errors.Trace(err)
}
if n := len(b) - 2; n < 0 || b[n] != '\r' {
return nil, errors.Trace(ErrBadRespCRLFEnd)
} else {
return b[:n], nil
}
}
开发者ID:YongMan,项目名称:codis,代码行数:11,代码来源:decoder.go
示例13: 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:YongMan,项目名称:codis,代码行数:12,代码来源:action.go
示例14: 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:YongMan,项目名称:codis,代码行数:12,代码来源:action.go
示例15: DialToTimeout
func DialToTimeout(addr string, passwd string, readTimeout, writeTimeout time.Duration) (redis.Conn, error) {
c, err := redis.DialTimeout("tcp", addr, time.Second, readTimeout, writeTimeout)
if err != nil {
return nil, errors.Trace(err)
}
if passwd != "" {
if _, err := c.Do("AUTH", passwd); err != nil {
c.Close()
return nil, errors.Trace(err)
}
}
return c, nil
}
开发者ID:YongMan,项目名称:codis,代码行数:13,代码来源:redis.go
示例16: GetSlotByIndex
func (top *Topology) GetSlotByIndex(i int) (*models.Slot, *models.ServerGroup, error) {
slot, err := models.GetSlot(top.zkConn, top.ProductName, i)
if err != nil {
return nil, nil, errors.Trace(err)
}
groupServer, err := models.GetGroup(top.zkConn, top.ProductName, slot.GroupId)
if err != nil {
return nil, nil, errors.Trace(err)
}
return slot, groupServer, nil
}
开发者ID:YongMan,项目名称:codis,代码行数:13,代码来源:topology.go
示例17: 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:YongMan,项目名称:codis,代码行数:13,代码来源:proxy.go
示例18: 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:YongMan,项目名称:codis,代码行数:13,代码来源:slot.go
示例19: CreateActionRootPath
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
}
开发者ID:YongMan,项目名称:codis,代码行数:15,代码来源:action.go
示例20: getLivingNodeInfos
func getLivingNodeInfos(zkConn zkhelper.Conn) ([]*NodeInfo, error) {
groups, err := models.ServerGroups(zkConn, globalEnv.ProductName())
if err != nil {
return nil, errors.Trace(err)
}
slots, err := models.Slots(zkConn, globalEnv.ProductName())
slotMap := make(map[int][]int)
for _, slot := range slots {
if slot.State.Status == models.SLOT_STATUS_ONLINE {
slotMap[slot.GroupId] = append(slotMap[slot.GroupId], slot.Id)
}
}
var ret []*NodeInfo
for _, g := range groups {
master, err := g.Master(zkConn)
if err != nil {
return nil, errors.Trace(err)
}
if master == nil {
return nil, errors.Errorf("group %d has no master", g.Id)
}
out, err := utils.GetRedisConfig(master.Addr, globalEnv.Password(), "maxmemory")
if err != nil {
return nil, errors.Trace(err)
}
maxMem, err := strconv.ParseInt(out, 10, 64)
if err != nil {
return nil, errors.Trace(err)
}
if maxMem <= 0 {
return nil, errors.Errorf("redis %s should set maxmemory", master.Addr)
}
node := &NodeInfo{
GroupId: g.Id,
CurSlots: slotMap[g.Id],
MaxMemory: maxMem,
}
ret = append(ret, node)
}
cnt := 0
for _, info := range ret {
cnt += len(info.CurSlots)
}
if cnt != models.DEFAULT_SLOT_NUM {
return nil, errors.Errorf("not all slots are online")
}
return ret, nil
}
开发者ID:YongMan,项目名称:codis,代码行数:48,代码来源:rebalancer.go
注:本文中的github.com/YongMan/codis/pkg/utils/errors.Trace函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论