本文整理汇总了Golang中github.com/wandoulabs/codis/pkg/utils/errors.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Errorf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: NewRollingFile
func NewRollingFile(basePath string, maxFileFrag int, maxFragSize int64) (io.WriteCloser, error) {
if maxFileFrag <= 0 {
return nil, errors.Errorf("invalid max file-frag = %d", maxFileFrag)
}
if maxFragSize <= 0 {
return nil, errors.Errorf("invalid max frag-size = %d", maxFragSize)
}
if _, file := path.Split(basePath); file == "" {
return nil, errors.Errorf("invalid base-path = %s, file name is required", basePath)
}
var fileFrag = 0
for i := 0; i < maxFileFrag; i++ {
_, err := os.Stat(fmt.Sprintf("%s.%d", basePath, i))
if err != nil && os.IsNotExist(err) {
fileFrag = i
break
}
}
return &rollingFile{
maxFileFrag: maxFileFrag,
maxFragSize: maxFragSize,
basePath: basePath,
fileFrag: fileFrag - 1,
}, nil
}
开发者ID:cougar731,项目名称:codis,代码行数:28,代码来源:rolling.go
示例2: 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:cougar731,项目名称:codis,代码行数:48,代码来源:rebalancer.go
示例3: 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:cougar731,项目名称:codis,代码行数:30,代码来源:decoder.go
示例4: 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
示例5: preMigrateCheck
func (t *MigrateTask) preMigrateCheck() error {
slots, err := models.GetMigratingSlots(safeZkConn, t.productName)
if err != nil {
return errors.Trace(err)
}
// check if there is migrating slot
if len(slots) > 1 {
return errors.Errorf("more than one slots are migrating, unknown error")
}
if len(slots) == 1 {
slot := slots[0]
if t.NewGroupId != slot.State.MigrateStatus.To || t.SlotId != slot.Id {
return errors.Errorf("there is a migrating slot %+v, finish it first", slot)
}
}
return nil
}
开发者ID:jcru,项目名称:codis,代码行数:18,代码来源:migrate_task.go
示例6: SetSlotRange
func SetSlotRange(zkConn zkhelper.Conn, productName string, fromSlot, toSlot, groupId int, status SlotStatus) error {
if status != SLOT_STATUS_OFFLINE && status != SLOT_STATUS_ONLINE {
return errors.Errorf("invalid status")
}
ok, err := GroupExists(zkConn, productName, groupId)
if err != nil {
return errors.Trace(err)
}
if !ok {
return errors.Errorf("group %d is not found", groupId)
}
for i := fromSlot; i <= toSlot; i++ {
s, err := GetSlot(zkConn, productName, i)
if err != nil {
return errors.Trace(err)
}
if s.State.Status != SLOT_STATUS_OFFLINE {
return errors.New(fmt.Sprintf("slot %d is not offline, if you want to change the group for a slot, use migrate", s.Id))
}
s.GroupId = groupId
s.State.Status = status
data, err := json.Marshal(s)
if err != nil {
return errors.Trace(err)
}
zkPath := GetSlotPath(productName, i)
_, err = zkhelper.CreateOrUpdate(zkConn, zkPath, string(data), 0, zkhelper.DefaultFileACLs(), true)
if err != nil {
return errors.Trace(err)
}
}
param := SlotMultiSetParam{
From: fromSlot,
To: toSlot,
GroupId: groupId,
Status: status,
}
err = NewAction(zkConn, productName, ACTION_TYPE_MULTI_SLOT_CHANGED, param, "", true)
return errors.Trace(err)
}
开发者ID:cougar731,项目名称:codis,代码行数:44,代码来源:slot.go
示例7: NewZkConn
func (e *CodisEnv) NewZkConn() (zkhelper.Conn, error) {
switch e.provider {
case "zookeeper":
return zkhelper.ConnectToZk(e.zkAddr, 30)
case "etcd":
addr := strings.TrimSpace(e.zkAddr)
if !strings.HasPrefix(addr, "http://") {
addr = "http://" + addr
}
return zkhelper.NewEtcdConn(addr, 30)
}
return nil, errors.Errorf("need coordinator in config file, %s", e)
}
开发者ID:cougar731,项目名称:codis,代码行数:13,代码来源:env.go
示例8: SetSlots
func SetSlots(zkConn zkhelper.Conn, productName string, slots []*Slot, groupId int, status SlotStatus) error {
if status != SLOT_STATUS_OFFLINE && status != SLOT_STATUS_ONLINE {
return errors.Errorf("invalid status")
}
ok, err := GroupExists(zkConn, productName, groupId)
if err != nil {
return errors.Trace(err)
}
if !ok {
return errors.Errorf("group %d is not found", groupId)
}
for _, s := range slots {
s.GroupId = groupId
s.State.Status = status
data, err := json.Marshal(s)
if err != nil {
return errors.Trace(err)
}
zkPath := GetSlotPath(productName, s.Id)
_, err = zkhelper.CreateOrUpdate(zkConn, zkPath, string(data), 0, zkhelper.DefaultFileACLs(), true)
if err != nil {
return errors.Trace(err)
}
}
param := SlotMultiSetParam{
From: -1,
To: -1,
GroupId: groupId,
Status: status,
}
err = NewAction(zkConn, productName, ACTION_TYPE_MULTI_SLOT_CHANGED, param, "", true)
return errors.Trace(err)
}
开发者ID:cookiebus,项目名称:codis,代码行数:39,代码来源:slot.go
示例9: callApi
func callApi(method HttpMethod, apiPath string, params interface{}, retVal interface{}) error {
if apiPath[0] != '/' {
return errors.Errorf("api path must starts with /")
}
url := "http://" + globalEnv.DashboardAddr() + apiPath
client := &http.Client{Transport: http.DefaultTransport}
b, err := json.Marshal(params)
if err != nil {
return errors.Trace(err)
}
req, err := http.NewRequest(string(method), url, strings.NewReader(string(b)))
if err != nil {
return errors.Trace(err)
}
resp, err := client.Do(req)
if err != nil {
log.Errorf("can't connect to dashboard, please check 'dashboard_addr' is corrent in config file")
return errors.Trace(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return errors.Trace(err)
}
if resp.StatusCode == 200 {
err := json.Unmarshal(body, retVal)
if err != nil {
return errors.Trace(err)
}
return nil
}
return errors.Errorf("http status code %d, %s", resp.StatusCode, string(body))
}
开发者ID:cougar731,项目名称:codis,代码行数:38,代码来源:utils.go
示例10: encodeResp
func (e *Encoder) encodeResp(r *Resp) error {
if err := e.WriteByte(byte(r.Type)); err != nil {
return errors.Trace(err)
}
switch r.Type {
default:
return errors.Errorf("bad resp type %s", r.Type)
case TypeString, TypeError, TypeInt:
return e.encodeTextBytes(r.Value)
case TypeBulkBytes:
return e.encodeBulkBytes(r.Value)
case TypeArray:
return e.encodeArray(r.Array)
}
}
开发者ID:cougar731,项目名称:codis,代码行数:15,代码来源:encoder.go
示例11: Remove
func (self *ServerGroup) Remove(zkConn zkhelper.Conn) error {
// check if this group is not used by any slot
slots, err := Slots(zkConn, self.ProductName)
if err != nil {
return errors.Trace(err)
}
for _, slot := range slots {
if slot.GroupId == self.Id {
return errors.Errorf("group %d is using by slot %d", slot.GroupId, slot.Id)
}
if (slot.State.Status == SLOT_STATUS_MIGRATE || slot.State.Status == SLOT_STATUS_PRE_MIGRATE) && slot.State.MigrateStatus.From == self.Id {
return errors.Errorf("slot %d has residual data remain in group %d", slot.Id, self.Id)
}
}
// do delete
zkPath := fmt.Sprintf("/zk/codis/db_%s/servers/group_%d", self.ProductName, self.Id)
err = zkhelper.DeleteRecursive(zkConn, zkPath, -1)
// we know that there's no slots affected, so this action doesn't need proxy confirm
err = NewAction(zkConn, self.ProductName, ACTION_TYPE_SERVER_GROUP_REMOVE, self, "", false)
return errors.Trace(err)
}
开发者ID:cougar731,项目名称:codis,代码行数:24,代码来源:server_group.go
示例12: Create
func (self *ServerGroup) Create(zkConn zkhelper.Conn) error {
if self.Id < 0 {
return errors.Errorf("invalid server group id %d", self.Id)
}
zkPath := fmt.Sprintf("/zk/codis/db_%s/servers/group_%d", self.ProductName, self.Id)
_, err := zkhelper.CreateOrUpdate(zkConn, zkPath, "", 0, zkhelper.DefaultDirACLs(), true)
if err != nil {
return errors.Trace(err)
}
err = NewAction(zkConn, self.ProductName, ACTION_TYPE_SERVER_GROUP_CHANGED, self, "", false)
if err != nil {
return errors.Trace(err)
}
return nil
}
开发者ID:cougar731,项目名称:codis,代码行数:16,代码来源:server_group.go
示例13: SetMigrateStatus
func (s *Slot) SetMigrateStatus(zkConn zkhelper.Conn, fromGroup, toGroup int) error {
if fromGroup < 0 || toGroup < 0 {
return errors.Errorf("invalid group id, from %d, to %d", fromGroup, toGroup)
}
// wait until all proxy confirmed
err := NewAction(zkConn, s.ProductName, ACTION_TYPE_SLOT_PREMIGRATE, s, "", true)
if err != nil {
return errors.Trace(err)
}
s.State.Status = SLOT_STATUS_MIGRATE
s.State.MigrateStatus.From = fromGroup
s.State.MigrateStatus.To = toGroup
s.GroupId = toGroup
return s.Update(zkConn)
}
开发者ID:cookiebus,项目名称:codis,代码行数:18,代码来源:slot.go
示例14: SetMigrateStatus
func (s *Slot) SetMigrateStatus(zkConn zkhelper.Conn, fromGroup, toGroup int) error {
if fromGroup < 0 || toGroup < 0 {
return errors.Errorf("invalid group id, from %d, to %d", fromGroup, toGroup)
}
// skip pre_migrate if slot is already migrating
if s.State.Status != SLOT_STATUS_MIGRATE {
s.State.Status = SLOT_STATUS_PRE_MIGRATE
err := s.Update(zkConn)
if err != nil {
return errors.Trace(err)
}
}
s.State.Status = SLOT_STATUS_MIGRATE
s.State.MigrateStatus.From = fromGroup
s.State.MigrateStatus.To = toGroup
s.GroupId = toGroup
return s.Update(zkConn)
}
开发者ID:cyflhn,项目名称:codis,代码行数:18,代码来源:slot.go
示例15: runCommand
func runCommand(cmd string, args []string) (err error) {
argv := make([]string, 1)
argv[0] = cmd
argv = append(argv, args...)
switch cmd {
case "action":
return errors.Trace(cmdAction(argv))
case "dashboard":
return errors.Trace(cmdDashboard(argv))
case "server":
return errors.Trace(cmdServer(argv))
case "proxy":
return errors.Trace(cmdProxy(argv))
case "slot":
return errors.Trace(cmdSlot(argv))
}
return errors.Errorf("%s is not a valid command. See 'codis-config -h'", cmd)
}
开发者ID:cougar731,项目名称:codis,代码行数:18,代码来源:main.go
示例16: GetGroup
func GetGroup(zkConn zkhelper.Conn, productName string, groupId int) (*ServerGroup, error) {
exists, err := GroupExists(zkConn, productName, groupId)
if err != nil {
return nil, errors.Trace(err)
}
if !exists {
return nil, errors.Errorf("group %d is not found", groupId)
}
group := &ServerGroup{
ProductName: productName,
Id: groupId,
}
group.Servers, err = group.GetServers(zkConn)
if err != nil {
return nil, errors.Trace(err)
}
return group, nil
}
开发者ID:cougar731,项目名称:codis,代码行数:20,代码来源:server_group.go
示例17: SlaveOf
func SlaveOf(slave, passwd string, master string) error {
if master == slave {
return errors.Errorf("can not slave of itself")
}
c, err := DialToTimeout(slave, passwd, time.Minute*15, time.Second*5)
if err != nil {
return err
}
defer c.Close()
host, port, err := net.SplitHostPort(master)
if err != nil {
return errors.Trace(err)
}
if _, err := c.Do("SLAVEOF", host, port); err != nil {
return errors.Trace(err)
}
return nil
}
开发者ID:cougar731,项目名称:codis,代码行数:21,代码来源:redis.go
示例18: SlaveOf
func SlaveOf(slave, master string) error {
if master == slave {
return errors.Errorf("can not slave of itself")
}
c, err := redis.DialTimeout("tcp", slave, defaultTimeout, defaultTimeout, defaultTimeout)
if err != nil {
return errors.Trace(err)
}
defer c.Close()
host, port, err := net.SplitHostPort(master)
if err != nil {
return errors.Trace(err)
}
if _, err := c.Do("SLAVEOF", host, port); err != nil {
return errors.Trace(err)
}
return nil
}
开发者ID:cookiebus,项目名称:codis,代码行数:21,代码来源:redis.go
示例19: Promote
func (self *ServerGroup) Promote(conn zkhelper.Conn, addr, passwd string) error {
var s *Server
exists := false
for i := 0; i < len(self.Servers); i++ {
if self.Servers[i].Addr == addr {
s = self.Servers[i]
exists = true
break
}
}
if !exists {
return errors.Errorf("no such addr %s", addr)
}
err := utils.SlaveNoOne(s.Addr, passwd)
if err != nil {
return errors.Trace(err)
}
// set origin master offline
master, err := self.Master(conn)
if err != nil {
return errors.Trace(err)
}
// old master may be nil
if master != nil {
master.Type = SERVER_TYPE_OFFLINE
err = self.AddServer(conn, master, passwd)
if err != nil {
return errors.Trace(err)
}
}
// promote new server to master
s.Type = SERVER_TYPE_MASTER
err = self.AddServer(conn, s, passwd)
return errors.Trace(err)
}
开发者ID:cougar731,项目名称:codis,代码行数:40,代码来源:server_group.go
示例20: Create
func (self *ServerGroup) Create(zkConn zkhelper.Conn) error {
if self.Id < 0 {
return errors.Errorf("invalid server group id %d", self.Id)
}
zkPath := fmt.Sprintf("/zk/codis/db_%s/servers/group_%d", self.ProductName, self.Id)
_, err := zkhelper.CreateOrUpdate(zkConn, zkPath, "", 0, zkhelper.DefaultDirACLs(), true)
if err != nil {
return errors.Trace(err)
}
err = NewAction(zkConn, self.ProductName, ACTION_TYPE_SERVER_GROUP_CHANGED, self, "", false)
if err != nil {
return errors.Trace(err)
}
// set no server slots' group id to this server group, no need to return error
slots, err := NoGroupSlots(zkConn, self.ProductName)
if err == nil && len(slots) > 0 {
SetSlots(zkConn, self.ProductName, slots, self.Id, SLOT_STATUS_ONLINE)
}
return nil
}
开发者ID:radioinmyhead,项目名称:codis,代码行数:22,代码来源:server_group.go
注:本文中的github.com/wandoulabs/codis/pkg/utils/errors.Errorf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论