当前位置: 首页>>代码示例>>Golang>>正文


Golang log.ErrorErrorf函数代码示例

本文整理汇总了Golang中github.com/wandoulabs/codis/pkg/utils/log.ErrorErrorf函数的典型用法代码示例。如果您正苦于以下问题:Golang ErrorErrorf函数的具体用法?Golang ErrorErrorf怎么用?Golang ErrorErrorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ErrorErrorf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: apiAddServerGroup

// create new server group
func apiAddServerGroup(newGroup models.ServerGroup) (int, string) {
	lock := utils.GetZkLock(safeZkConn, globalEnv.ProductName())
	if err := lock.LockWithTimeout(0, fmt.Sprintf("add group %+v", newGroup)); err != nil {
		return 500, err.Error()
	}

	defer func() {
		err := lock.Unlock()
		if err != nil && err != zk.ErrNoNode {
			log.ErrorErrorf(err, "unlock node failed")
		}
	}()

	newGroup.ProductName = globalEnv.ProductName()

	exists, err := newGroup.Exists(safeZkConn)
	if err != nil {
		log.ErrorErrorf(err, "check group exits failed")
		return 500, err.Error()
	}
	if exists {
		return 500, "group already exists"
	}
	err = newGroup.Create(safeZkConn)
	if err != nil {
		log.ErrorErrorf(err, "create node for new group failed")
		return 500, err.Error()
	}
	return jsonRetSucc()
}
开发者ID:cyflhn,项目名称:codis,代码行数:31,代码来源:dashboard_apis.go

示例2: fillSlot

/*
* return err should be reconnect to zk
*
 */
func (s *Server) fillSlot(i int) error {
	slotInfo, slotGroup, err := s.topo.GetSlotByIndex(i)
	if err != nil {
		log.ErrorErrorf(err, "get slot by index failed", i)
		return err
	}

	var from string
	var addr = groupMaster(*slotGroup)
	if slotInfo.State.Status == models.SLOT_STATUS_MIGRATE {
		fromGroup, err := s.topo.GetGroup(slotInfo.State.MigrateStatus.From)
		if err != nil {
			log.ErrorErrorf(err, "get migrate from failed")
			return err
		}

		from = groupMaster(*fromGroup)
		if from == addr {
			log.Errorf("set slot %04d migrate from %s to %s", i, from, addr)
			return nil
		}

		if "" == addr {
			log.Errorf("set slot %04d addr nil", i)
			return nil
		}
	}

	s.groups[i] = slotInfo.GroupId
	s.router.FillSlot(i, addr, from,
		slotInfo.State.Status == models.SLOT_STATUS_PRE_MIGRATE)
	return err
}
开发者ID:cyflhn,项目名称:codis,代码行数:37,代码来源:proxy.go

示例3: register

func (s *Server) register() {
	var err error
	for {
		if _, err = s.topo.CreateProxyInfo(&s.info); err != nil {
			log.ErrorErrorf(err, "create proxy node failed")
			if s.topo.IsErrSessionExpired(err) {
				s.topo.RefreshZkConn()
			}
			time.Sleep(ZK_RECONNECT_INTERVAL * time.Second)
		} else {
			break
		}
	}

	for {
		if _, err = s.topo.CreateProxyFenceNode(&s.info); err != nil {
			log.ErrorErrorf(err, "create fence node failed")
			if s.topo.IsErrSessionExpired(err) {
				s.topo.RefreshZkConn()
			} else if s.topo.IsErrNodeExist(err) {
				break
			}
			time.Sleep(ZK_RECONNECT_INTERVAL * time.Second)
		} else {
			break
		}
	}
}
开发者ID:cyflhn,项目名称:codis,代码行数:28,代码来源:proxy.go

示例4: apiPromoteServer

func apiPromoteServer(server models.Server, param martini.Params) (int, string) {
	lock := utils.GetZkLock(safeZkConn, globalEnv.ProductName())
	if err := lock.LockWithTimeout(0, fmt.Sprintf("promote server %+v", server)); err != nil {
		return 500, err.Error()
	}
	defer func() {
		err := lock.Unlock()
		if err != nil && err != zk.ErrNoNode {
			log.ErrorErrorf(err, "unlock node failed")
		}
	}()

	group, err := models.GetGroup(safeZkConn, globalEnv.ProductName(), server.GroupId)
	if err != nil {
		log.ErrorErrorf(err, "get group %d failed", server.GroupId)
		return 500, err.Error()
	}
	err = group.Promote(safeZkConn, server.Addr, globalEnv.Password())
	if err != nil {
		log.ErrorErrorf(err, "promote group %d failed", server.GroupId)
		return 500, err.Error()
	}

	return jsonRetSucc()
}
开发者ID:cyflhn,项目名称:codis,代码行数:25,代码来源:dashboard_apis.go

示例5: apiSlotRangeSet

func apiSlotRangeSet(task RangeSetTask) (int, string) {
	lock := utils.GetZkLock(safeZkConn, globalEnv.ProductName())
	if err := lock.LockWithTimeout(0, fmt.Sprintf("set slot range, %+v", task)); err != nil {
		return 500, err.Error()
	}
	defer func() {
		err := lock.Unlock()
		if err != nil && err != zk.ErrNoNode {
			log.ErrorErrorf(err, "unlock node failed")
		}
	}()

	// default set online
	if len(task.Status) == 0 {
		task.Status = string(models.SLOT_STATUS_ONLINE)
	}

	err := models.SetSlotRange(safeZkConn, globalEnv.ProductName(), task.FromSlot, task.ToSlot, task.NewGroupId, models.SlotStatus(task.Status))
	if err != nil {
		log.ErrorErrorf(err, "set slot range [%d,%d] failed", task.FromSlot, task.ToSlot)
		return 500, err.Error()
	}

	return jsonRetSucc()
}
开发者ID:cyflhn,项目名称:codis,代码行数:25,代码来源:dashboard_apis.go

示例6: GetSlotByIndex

func (top *Topology) GetSlotByIndex(i int) (*models.Slot, *models.ServerGroup, error) {
	var slot *models.Slot
	var groupServer *models.ServerGroup
	var err error
	for {
		slot, err = models.GetSlot(top.zkConn, top.ProductName, i)
		if err == nil || top.IsFatalErr(err) {
			break
		} else {
			time.Sleep(ZK_RECONNECT_INTERVAL * time.Second)
		}
		if err != nil {
			log.ErrorErrorf(err, " GetSlot ")
		}
	}
	if err != nil {
		return nil, nil, errors.Trace(err)
	}

	for {
		groupServer, err = models.GetGroup(top.zkConn, top.ProductName, slot.GroupId)
		if err == nil || top.IsFatalErr(err) {
			break
		} else {
			time.Sleep(ZK_RECONNECT_INTERVAL * time.Second)
		}
		if err != nil {
			log.ErrorErrorf(err, " GetGroup ")
		}
	}
	if err != nil {
		return nil, nil, errors.Trace(err)
	}
	return slot, groupServer, nil
}
开发者ID:cyflhn,项目名称:codis,代码行数:35,代码来源:topology.go

示例7: apiAddServerToGroup

// add redis server to exist server group
func apiAddServerToGroup(server models.Server, param martini.Params) (int, string) {
	groupId, _ := strconv.Atoi(param["id"])
	lock := utils.GetZkLock(safeZkConn, globalEnv.ProductName())
	if err := lock.LockWithTimeout(0, fmt.Sprintf("add server to group,  %+v", server)); err != nil {
		return 500, err.Error()
	}
	defer func() {
		err := lock.Unlock()
		if err != nil && err != zk.ErrNoNode {
			log.ErrorErrorf(err, "unlock node failed")
		}
	}()
	// check group exists first
	serverGroup := models.NewServerGroup(globalEnv.ProductName(), groupId)

	exists, err := serverGroup.Exists(safeZkConn)
	if err != nil {
		log.ErrorErrorf(err, "check group exits failed")
		return 500, err.Error()
	}

	// create new group if not exists
	if !exists {
		if err := serverGroup.Create(safeZkConn); err != nil {
			return 500, err.Error()
		}
	}

	if err := serverGroup.AddServer(safeZkConn, &server, globalEnv.Password()); err != nil {
		log.ErrorErrorf(err, "add server to group failed")
		return 500, err.Error()
	}

	return jsonRetSucc()
}
开发者ID:cyflhn,项目名称:codis,代码行数:36,代码来源:dashboard_apis.go

示例8: apiGetServerGroup

func apiGetServerGroup(param martini.Params) (int, string) {
	id := param["id"]
	groupId, err := strconv.Atoi(id)
	if err != nil {
		log.ErrorErrorf(err, "parse groupid failed")
		return 500, err.Error()
	}
	group, err := models.GetGroup(safeZkConn, globalEnv.ProductName(), groupId)
	if err != nil {
		log.ErrorErrorf(err, "get group %d failed", groupId)
		return 500, err.Error()
	}
	b, err := json.MarshalIndent(group, " ", "  ")
	return 200, string(b)
}
开发者ID:cyflhn,项目名称:codis,代码行数:15,代码来源:dashboard_apis.go

示例9: waitOnline

func (s *Server) waitOnline() bool {
	for {
		info, err := s.topo.GetProxyInfo(s.info.Id)
		if err != nil {
			log.ErrorErrorf(err, "get proxy info failed: %s", s.info.Id)
			if s.topo.IsFatalErr(err) {
				s.reRegister(models.PROXY_STATE_MARK_OFFLINE, true)
			}
			continue
		}
		switch info.State {
		case models.PROXY_STATE_MARK_OFFLINE:
			log.Infof("mark offline, proxy got offline event: %s", s.info.Id)
			s.markOffline()
			return false
		case models.PROXY_STATE_ONLINE:
			s.info.State = info.State
			log.Infof("we are online: %s", s.info.Id)
			s.rewatchProxy(false)
			return true
		}
		select {
		case <-s.kill:
			log.Infof("mark offline, proxy is killed: %s", s.info.Id)
			s.markOffline()
			return false
		default:
		}
		log.Infof("wait to be online: %s", s.info.Id)
		time.Sleep(3 * time.Second)
	}
}
开发者ID:cyflhn,项目名称:codis,代码行数:32,代码来源:proxy.go

示例10: loopEvents

func (s *Server) loopEvents() {
	ticker := time.NewTicker(time.Second)
	defer ticker.Stop()

	var tick int = 0
	for s.info.State == models.PROXY_STATE_ONLINE {
		select {
		case <-s.kill:
			log.Infof("mark offline, proxy is killed: %s", s.info.Id)
			s.markOffline()
		case e := <-s.evtbus:
			evtPath := getEventPath(e)
			log.Infof("got event %s, %v, lastActionSeq %d", s.info.Id, e, s.lastActionSeq)
			if strings.Index(evtPath, models.GetActionResponsePath(s.conf.productName)) == 0 {
				seq, err := strconv.Atoi(path.Base(evtPath))
				if err != nil {
					log.ErrorErrorf(err, "parse action seq failed")
				} else {
					if seq < s.lastActionSeq {
						log.Infof("ignore seq = %d", seq)
						continue
					}
				}
			}
			s.processAction(e)
		case <-ticker.C:
			if maxTick := s.conf.pingPeriod; maxTick != 0 {
				if tick++; tick >= maxTick {
					s.router.KeepAlive()
					tick = 0
				}
			}
		}
	}
}
开发者ID:leoYY,项目名称:codis,代码行数:35,代码来源:proxy.go

示例11: cmdProxy

func cmdProxy(argv []string) (err error) {
	usage := `usage:
	codis-config proxy list
	codis-config proxy offline <proxy_name>
	codis-config proxy online <proxy_name>
`
	args, err := docopt.Parse(usage, argv, true, "", false)
	if err != nil {
		log.ErrorErrorf(err, "parse args failed")
		return err
	}
	log.Debugf("parse args = {%+v}", args)

	if args["list"].(bool) {
		return runProxyList()
	}

	proxyName := args["<proxy_name>"].(string)
	if args["online"].(bool) {
		return runSetProxyStatus(proxyName, models.PROXY_STATE_ONLINE)
	}
	if args["offline"].(bool) {
		return runSetProxyStatus(proxyName, models.PROXY_STATE_MARK_OFFLINE)
	}
	return nil
}
开发者ID:cougar731,项目名称:codis,代码行数:26,代码来源:proxy.go

示例12: cmdDashboard

func cmdDashboard(argv []string) (err error) {
	usage := `usage: codis-config dashboard [--addr=<address>] [--http-log=<log_file>]

options:
	--addr	listen ip:port, e.g. localhost:12345, :8086, [default: :8086]
	--http-log	http request log [default: request.log ]
`

	args, err := docopt.Parse(usage, argv, true, "", false)
	if err != nil {
		log.ErrorErrorf(err, "parse args failed")
		return err
	}
	log.Debugf("parse args = {%+v}", args)

	logFileName := "request.log"
	if args["--http-log"] != nil {
		logFileName = args["--http-log"].(string)
	}

	addr := ":8086"
	if args["--addr"] != nil {
		addr = args["--addr"].(string)
	}

	runDashboard(addr, logFileName)
	return nil
}
开发者ID:jcru,项目名称:codis,代码行数:28,代码来源:dashboard.go

示例13: getAllProxySlowop

func getAllProxySlowop() map[string][]*router.SlowOpInfo {
	proxies, err := models.ProxyList(unsafeZkConn, globalEnv.ProductName(), nil)
	if err != nil {
		log.ErrorErrorf(err, "get proxy list failed")
		return nil
	}

	ret := make(map[string][]*router.SlowOpInfo)
	for _, p := range proxies {
		m, err := p.DebugVars()
		if err != nil {
			log.WarnErrorf(err, "get proxy debug varsfailed")
		}
		if m["router"] != nil {
			route := m["router"].(map[string]interface{})
			if route["slowop"] != nil {
				ops := make([]*router.SlowOpInfo, 0, 10)
				for _, elem := range route["slowop"].([]interface{}) {
					op := elem.(map[string]interface{})
					s := &router.SlowOpInfo{
						Time:     op["time"].(string),
						Key:      op["key"].(string),
						Duration: int64(op["duration"].(float64)),
						Reqs:     int64(op["req"].(float64)),
					}
					ops = append(ops, s)
				}
				ret[p.Id] = ops
			}
		}
	}
	return ret
}
开发者ID:cyflhn,项目名称:codis,代码行数:33,代码来源:dashboard.go

示例14: apiActionGC

// actions
func apiActionGC(r *http.Request) (int, string) {
	r.ParseForm()
	keep, _ := strconv.Atoi(r.FormValue("keep"))
	secs, _ := strconv.Atoi(r.FormValue("secs"))
	lock := utils.GetZkLock(safeZkConn, globalEnv.ProductName())
	if err := lock.LockWithTimeout(0, fmt.Sprintf("action gc")); err != nil {
		return 500, err.Error()
	}
	defer func() {
		err := lock.Unlock()
		if err != nil && err != zk.ErrNoNode {
			log.ErrorErrorf(err, "unlock node failed")
		}
	}()

	var err error
	if keep >= 0 {
		err = models.ActionGC(safeZkConn, globalEnv.ProductName(), models.GC_TYPE_N, keep)
	} else if secs > 0 {
		err = models.ActionGC(safeZkConn, globalEnv.ProductName(), models.GC_TYPE_SEC, secs)
	}
	if err != nil {
		return 500, err.Error()
	}
	return jsonRetSucc()
}
开发者ID:cougar731,项目名称:codis,代码行数:27,代码来源:dashboard_apis.go

示例15: cmdServer

func cmdServer(argv []string) (err error) {
	usage := `usage:
	codis-config server list
	codis-config server add <group_id> <redis_addr> <role>
	codis-config server remove <group_id> <redis_addr>
	codis-config server promote <group_id> <redis_addr>
	codis-config server add-group <group_id>
	codis-config server remove-group <group_id>
`
	args, err := docopt.Parse(usage, argv, true, "", false)
	if err != nil {
		log.ErrorErrorf(err, "parse args failed")
		return err
	}
	log.Debugf("parse args = {%+v}", args)

	if args["list"].(bool) {
		return runListServerGroup()
	}

	groupId, err := strconv.Atoi(args["<group_id>"].(string))
	if err != nil {
		log.ErrorErrorf(err, "parse <group_id> failed")
		return err
	}

	if args["remove-group"].(bool) {
		return runRemoveServerGroup(groupId)
	}
	if args["add-group"].(bool) {
		return runAddServerGroup(groupId)
	}

	serverAddr := args["<redis_addr>"].(string)
	if args["add"].(bool) {
		role := args["<role>"].(string)
		return runAddServerToGroup(groupId, serverAddr, role)
	}
	if args["remove"].(bool) {
		return runRemoveServerFromGroup(groupId, serverAddr)
	}
	if args["promote"].(bool) {
		return runPromoteServerToMaster(groupId, serverAddr)
	}

	return nil
}
开发者ID:cougar731,项目名称:codis,代码行数:47,代码来源:server_group.go


注:本文中的github.com/wandoulabs/codis/pkg/utils/log.ErrorErrorf函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。