本文整理汇总了Golang中github.com/wandoulabs/codis/pkg/utils/errors.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: verifyAuth
func (bc *BackendConn) verifyAuth(c *redis.Conn) error {
if bc.passwd == "" {
return nil
}
resp := redis.NewArray([]*redis.Resp{
redis.NewBulkBytes([]byte("AUTH")),
redis.NewBulkBytes([]byte(bc.passwd)),
})
if err := c.Writer.Encode(resp, true); err != nil {
return err
}
resp, err := c.Reader.Decode()
if err != nil {
return err
}
if resp == nil {
return errors.New(fmt.Sprintf("error resp: nil response"))
}
if resp.IsError() {
return errors.New(fmt.Sprintf("error resp: %s", resp.Value))
}
if resp.IsString() {
return nil
} else {
return errors.New(fmt.Sprintf("error resp: should be string, but got %s", resp.Type))
}
}
开发者ID:hongzhang2046,项目名称:codis,代码行数:29,代码来源:backend.go
示例2: slotsmgrt
func (s *Slot) slotsmgrt(r *Request, key []byte) error {
if len(key) == 0 || s.migrate.bc == nil {
return nil
}
m := &Request{
Owner: r.Owner,
Wait: &sync.WaitGroup{},
Resp: redis.NewArray([]*redis.Resp{
redis.NewBulkBytes([]byte("SLOTSMGRTTAGONE")),
redis.NewBulkBytes(s.backend.host),
redis.NewBulkBytes(s.backend.port),
redis.NewBulkBytes([]byte("3000")),
redis.NewBulkBytes(key),
}),
}
m.Wait.Add(1)
s.migrate.bc.PushBack(m)
m.Wait.Wait()
resp, err := m.Response.Resp, m.Response.Err
if err != nil {
return err
}
if resp == nil {
return ErrRespIsRequired
}
if resp.IsError() {
return errors.New(fmt.Sprintf("error resp: %s", resp.Value))
}
if resp.IsInt() {
log.Debugf("slot-%04d migrate from %s to %s: key = %s, resp = %s",
s.Id, s.migrate.from, s.backend.addr, key, resp.Value)
return nil
} else {
return errors.New(fmt.Sprintf("error resp: should be integer, but got %s", resp.Type))
}
}
开发者ID:cookiebus,项目名称:codis,代码行数:39,代码来源:slots.go
示例3: handleRequest
func (s *Session) handleRequest(resp *redis.Resp, d Dispatcher) (*Request, error) {
opstr, err := getOpStr(resp)
if err != nil {
return nil, err
}
if isNotAllowed(opstr) {
return nil, errors.New(fmt.Sprintf("command <%s> is not allowed", opstr))
}
usnow := microseconds()
s.LastOpUnix = usnow / 1e6
s.Ops++
r := &Request{
OpStr: opstr,
Start: usnow,
Resp: resp,
Wait: &sync.WaitGroup{},
Failed: &s.failed,
}
if opstr == "QUIT" {
return s.handleQuit(r)
}
if opstr == "AUTH" {
return s.handleAuth(r)
}
if !s.authorized {
if s.auth != "" {
r.Response.Resp = redis.NewError([]byte("NOAUTH Authentication required."))
return r, nil
}
s.authorized = true
}
switch opstr {
case "SELECT":
return s.handleSelect(r)
case "PING":
return s.handlePing(r)
case "MGET":
return s.handleRequestMGet(r, d)
case "MSET":
return s.handleRequestMSet(r, d)
case "DEL":
return s.handleRequestMDel(r, d)
}
return r, d.Dispatch(r)
}
开发者ID:njucslqq,项目名称:codis,代码行数:50,代码来源:session.go
示例4: handleRequestMSet
func (s *Session) handleRequestMSet(r *Request, d Dispatcher) (*Request, error) {
nblks := len(r.Resp.Array) - 1
if nblks <= 2 {
return r, d.Dispatch(r)
}
if nblks%2 != 0 {
r.Response.Resp = redis.NewError([]byte("ERR wrong number of arguments for MSET"))
return r, nil
}
var sub = make([]*Request, nblks/2)
for i := 0; i < len(sub); i++ {
sub[i] = &Request{
Owner: r.Owner,
OpSeq: -r.OpSeq,
OpStr: r.OpStr,
Start: r.Start,
Wait: r.Wait,
Resp: redis.NewArray([]*redis.Resp{
r.Resp.Array[0],
r.Resp.Array[i*2+1],
r.Resp.Array[i*2+2],
}),
}
if err := d.Dispatch(sub[i]); err != nil {
return nil, err
}
}
r.Coalesce = func() error {
for _, x := range sub {
if err := x.Response.Err; err != nil {
return err
}
resp := x.Response.Resp
if resp == nil {
return ErrRespIsRequired
}
if !resp.IsString() {
return errors.New(fmt.Sprintf("bad mset resp: %s value.len = %d", resp.Type, len(resp.Value)))
}
r.Response.Resp = resp
}
return nil
}
return r, nil
}
开发者ID:cbruce,项目名称:codis,代码行数:45,代码来源:session.go
示例5: loopReader
func (s *Session) loopReader(tasks chan<- *Request, d Dispatcher) error {
if d == nil {
return errors.New("nil dispatcher")
}
for !s.quit {
resp, err := s.Reader.Decode()
if err != nil {
return err
}
r, err := s.handleRequest(resp, d)
if err != nil {
return err
} else {
tasks <- r
}
}
return nil
}
开发者ID:njucslqq,项目名称:codis,代码行数:18,代码来源:session.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: handleRequestMDel
func (s *Session) handleRequestMDel(r *Request, d Dispatcher) (*Request, error) {
nkeys := len(r.Resp.Array) - 1
if nkeys <= 1 {
return r, d.Dispatch(r)
}
var sub = make([]*Request, nkeys)
for i := 0; i < len(sub); i++ {
sub[i] = &Request{
Owner: r.Owner,
OpSeq: -r.OpSeq,
OpStr: r.OpStr,
Start: r.Start,
Wait: r.Wait,
Resp: redis.NewArray([]*redis.Resp{
r.Resp.Array[0],
r.Resp.Array[i+1],
}),
}
if err := d.Dispatch(sub[i]); err != nil {
return nil, err
}
}
r.Coalesce = func() error {
var n int
for _, x := range sub {
if err := x.Response.Err; err != nil {
return err
}
resp := x.Response.Resp
if resp == nil {
return ErrRespIsRequired
}
if !resp.IsInt() || len(resp.Value) != 1 {
return errors.New(fmt.Sprintf("bad mdel resp: %s value.len = %d", resp.Type, len(resp.Value)))
}
if resp.Value[0] != '0' {
n++
}
}
r.Response.Resp = redis.NewInt([]byte(strconv.Itoa(n)))
return nil
}
return r, nil
}
开发者ID:cbruce,项目名称:codis,代码行数:44,代码来源:session.go
示例8: handleRequestMGet
func (s *Session) handleRequestMGet(r *Request, d Dispatcher) (*Request, error) {
nkeys := len(r.Resp.Array) - 1
if nkeys <= 1 {
return r, d.Dispatch(r)
}
var sub = make([]*Request, nkeys)
for i := 0; i < len(sub); i++ {
sub[i] = &Request{
Owner: r.Owner,
OpSeq: -r.OpSeq,
OpStr: r.OpStr,
Start: r.Start,
Wait: r.Wait,
Resp: redis.NewArray([]*redis.Resp{
r.Resp.Array[0],
r.Resp.Array[i+1],
}),
}
if err := d.Dispatch(sub[i]); err != nil {
return nil, err
}
}
r.Coalesce = func() error {
var array = make([]*redis.Resp, len(sub))
for i, x := range sub {
if err := x.Response.Err; err != nil {
return err
}
resp := x.Response.Resp
if resp == nil {
return ErrRespIsRequired
}
if !resp.IsArray() || len(resp.Array) != 1 {
return errors.New(fmt.Sprintf("bad mget resp: %s array.len = %d", resp.Type, len(resp.Array)))
}
array[i] = resp.Array[0]
}
r.Response.Resp = redis.NewArray(array)
return nil
}
return r, nil
}
开发者ID:cbruce,项目名称:codis,代码行数:42,代码来源:session.go
示例9: createDashboardNode
func createDashboardNode() error {
// make sure root dir is exists
rootDir := fmt.Sprintf("/zk/codis/db_%s", globalEnv.ProductName())
zkhelper.CreateRecursive(safeZkConn, rootDir, "", 0, zkhelper.DefaultDirACLs())
zkPath := fmt.Sprintf("%s/dashboard", rootDir)
// make sure we're the only one dashboard
if exists, _, _ := safeZkConn.Exists(zkPath); exists {
data, _, _ := safeZkConn.Get(zkPath)
return errors.New("dashboard already exists: " + string(data))
}
content := fmt.Sprintf(`{"addr": "%v", "pid": %v}`, globalEnv.DashboardAddr(), os.Getpid())
pathCreated, err := safeZkConn.Create(zkPath, []byte(content), 0, zkhelper.DefaultFileACLs())
createdDashboardNode = true
log.Infof("dashboard node created: %v, %s", pathCreated, string(content))
return errors.Trace(err)
}
开发者ID:jcru,项目名称:codis,代码行数:20,代码来源:dashboard.go
示例10: createDashboardNode
func createDashboardNode() error {
// make sure root dir is exists
rootDir := fmt.Sprintf("/zk/codis/db_%s", globalEnv.ProductName())
zkhelper.CreateRecursive(safeZkConn, rootDir, "", 0, zkhelper.DefaultDirACLs())
zkPath := fmt.Sprintf("%s/dashboard", rootDir)
// make sure we're the only one dashboard
if exists, _, _ := safeZkConn.Exists(zkPath); exists {
data, _, _ := safeZkConn.Get(zkPath)
return errors.New("dashboard already exists: " + string(data))
}
content := fmt.Sprintf(`{"addr": "%v", "pid": %v}`, globalEnv.DashboardAddr(), os.Getpid())
pathCreated, err := safeZkConn.Create(zkPath, []byte(content), 0, zkhelper.DefaultFileACLs())
createdDashboardNode = true
log.Infof("dashboard node created: %v, %s", pathCreated, string(content))
log.Warn("********** Attention **********")
log.Warn("You should use `kill {pid}` rather than `kill -9 {pid}` to stop me,")
log.Warn("or the node resisted on zk will not be cleaned when I'm quiting and you must remove it manually")
log.Warn("*******************************")
return errors.Trace(err)
}
开发者ID:cougar731,项目名称:codis,代码行数:23,代码来源:dashboard.go
示例11: handleRequest
func (s *Session) handleRequest(resp *redis.Resp, d Dispatcher) (*Request, error) {
opstr, err := getOpStr(resp)
if err != nil {
return nil, err
}
if isNotAllowed(opstr) {
return nil, errors.New(fmt.Sprintf("command <%s> is not allowed", opstr))
}
usnow := microseconds()
s.LastOpUnix.Set(usnow / 1e6)
r := &Request{
Owner: s,
OpSeq: s.Ops.Incr(),
OpStr: opstr,
Start: usnow,
Wait: &sync.WaitGroup{},
Resp: resp,
}
switch opstr {
case "QUIT":
s.quit = true
fallthrough
case "AUTH", "SELECT":
r.Response.Resp = redis.NewString([]byte("OK"))
return r, nil
case "MGET":
return s.handleRequestMGet(r, d)
case "MSET":
return s.handleRequestMSet(r, d)
case "DEL":
return s.handleRequestMDel(r, d)
}
return r, d.Dispatch(r)
}
开发者ID:cbruce,项目名称:codis,代码行数:37,代码来源:session.go
示例12: run
func (t *MigrateTask) run() error {
log.Infof("migration start: %+v", t.MigrateTaskInfo)
to := t.NewGroupId
t.UpdateStatus(MIGRATE_TASK_MIGRATING)
err := t.migrateSingleSlot(t.SlotId, to)
if err != nil {
log.ErrorErrorf(err, "migrate single slot failed")
t.UpdateStatus(MIGRATE_TASK_ERR)
return err
}
t.UpdateFinish()
log.Infof("migration finished: %+v", t.MigrateTaskInfo)
return nil
}
var ErrGroupMasterNotFound = errors.New("group master not found")
// will block until all keys are migrated
func (task *MigrateTask) Migrate(slot *models.Slot, fromGroup, toGroup int, onProgress func(SlotMigrateProgress)) (err error) {
groupFrom, err := models.GetGroup(task.zkConn, task.productName, fromGroup)
if err != nil {
return err
}
groupTo, err := models.GetGroup(task.zkConn, task.productName, toGroup)
if err != nil {
return err
}
fromMaster, err := groupFrom.Master(task.zkConn)
if err != nil {
return err
开发者ID:jcru,项目名称:codis,代码行数:31,代码来源:migrate_task.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
}
var ErrReceiverTimeout = errors.New("receiver timeout")
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)
开发者ID:cyflhn,项目名称:codis,代码行数:31,代码来源:action.go
示例14: btoi
// Copyright 2014 Wandoujia Inc. All Rights Reserved.
// Licensed under the MIT (MIT-LICENSE.txt) license.
package redis
import (
"bufio"
"bytes"
"io"
"strconv"
"github.com/wandoulabs/codis/pkg/utils/errors"
)
var (
ErrBadRespCRLFEnd = errors.New("bad resp CRLF end")
ErrBadRespBytesLen = errors.New("bad resp bytes len")
ErrBadRespArrayLen = errors.New("bad resp array len")
)
func btoi(b []byte) (int64, error) {
if len(b) != 0 && len(b) < 10 {
var neg, i = false, 0
switch b[0] {
case '-':
neg = true
fallthrough
case '+':
i++
}
if len(b) != i {
开发者ID:cougar731,项目名称:codis,代码行数:31,代码来源:decoder.go
示例15: isNotAllowed
"BLPOP", "BRPOP", "BRPOPLPUSH", "PSUBSCRIBE", "PUBLISH", "PUNSUBSCRIBE", "SUBSCRIBE", "RANDOMKEY",
"UNSUBSCRIBE", "DISCARD", "EXEC", "MULTI", "UNWATCH", "WATCH", "SCRIPT",
"BGREWRITEAOF", "BGSAVE", "CLIENT", "CONFIG", "DBSIZE", "DEBUG", "FLUSHALL", "FLUSHDB",
"LASTSAVE", "MONITOR", "SAVE", "SHUTDOWN", "SLAVEOF", "SLOWLOG", "SYNC", "TIME",
"SLOTSINFO", "SLOTSDEL", "SLOTSMGRTSLOT", "SLOTSMGRTONE", "SLOTSMGRTTAGSLOT", "SLOTSMGRTTAGONE", "SLOTSCHECK",
} {
blacklist[s] = true
}
}
func isNotAllowed(opstr string) bool {
return blacklist[opstr]
}
var (
ErrBadRespType = errors.New("bad resp type for command")
ErrBadOpStrLen = errors.New("bad command length, too short or too long")
)
func getOpStr(resp *redis.Resp) (string, error) {
if !resp.IsArray() || len(resp.Array) == 0 {
return "", ErrBadRespType
}
for _, r := range resp.Array {
if r.IsBulkBytes() {
continue
}
return "", ErrBadRespType
}
var upper [64]byte
开发者ID:cyflhn,项目名称:codis,代码行数:31,代码来源:mapper.go
示例16: loopWriter
Wait: &sync.WaitGroup{},
Resp: redis.NewArray([]*redis.Resp{
redis.NewBulkBytes([]byte("PING")),
}),
}
r.Wait.Add(1)
select {
case bc.input <- r:
return true
default:
return false
}
}
var ErrZombieRequest = errors.New("request from zombie session")
func (bc *BackendConn) loopWriter() error {
r, ok := <-bc.input
if ok {
c, tasks, err := bc.newBackendReader()
if err != nil {
return bc.setResponse(r, nil, err)
}
defer close(tasks)
p := &FlushPolicy{
Encoder: c.Writer,
MaxBuffered: 64,
MaxInterval: 300,
}
开发者ID:cookiebus,项目名称:codis,代码行数:31,代码来源:backend.go
示例17: SetProxyStatus
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
}
var ErrUnknownProxyStatus = errors.New("unknown status, should be (online offline)")
func SetProxyStatus(zkConn zkhelper.Conn, productName string, proxyName string, status string) error {
p, err := GetProxyInfo(zkConn, productName, proxyName)
if err != nil {
return errors.Trace(err)
}
if status != PROXY_STATE_ONLINE && status != PROXY_STATE_MARK_OFFLINE && status != PROXY_STATE_OFFLINE {
return errors.Errorf("%v, %s", ErrUnknownProxyStatus, status)
}
// check slot status before setting proxy online
if status == PROXY_STATE_ONLINE {
slots, err := Slots(zkConn, productName)
if err != nil {
开发者ID:cougar731,项目名称:codis,代码行数:31,代码来源:proxy.go
示例18: Parse
const (
B = 1 << (10 * iota)
KB
MB
GB
TB
PB
)
var (
BytesizeRegexp = regexp.MustCompile(`(?i)^\s*(\-?[\d\.]+)\s*([KMGTP]?B|[BKMGTP]|)\s*$`)
digitsRegexp = regexp.MustCompile(`^\-?\d+$`)
)
var (
ErrBadBytesize = errors.New("invalid byte size")
ErrBadBytesizeUnit = errors.New("invalid byte size unit")
)
func Parse(s string) (int64, error) {
if !BytesizeRegexp.MatchString(s) {
return 0, errors.Trace(ErrBadBytesize)
}
subs := BytesizeRegexp.FindStringSubmatch(s)
if len(subs) != 3 {
return 0, errors.Trace(ErrBadBytesize)
}
size := int64(0)
switch strings.ToUpper(string(subs[2])) {
开发者ID:cougar731,项目名称:codis,代码行数:31,代码来源:bytesize.go
示例19: loopWriter
}
r := &Request{
Resp: redis.NewArray([]*redis.Resp{
redis.NewBulkBytes([]byte("PING")),
}),
}
select {
case bc.input <- r:
return true
default:
return false
}
}
var ErrFailedRequest = errors.New("discard failed request")
func (bc *BackendConn) loopWriter() error {
r, ok := <-bc.input
if ok {
c, tasks, err := bc.newBackendReader()
if err != nil {
return bc.setResponse(r, nil, err)
}
defer close(tasks)
p := &FlushPolicy{
Encoder: c.Writer,
MaxBuffered: 64,
MaxInterval: 300,
}
开发者ID:hongzhang2046,项目名称:codis,代码行数:31,代码来源:backend.go
示例20: Exists
return errors.Trace(err)
}
return nil
}
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
}
var ErrNodeExists = errors.New("node already exists")
func (self *ServerGroup) AddServer(zkConn zkhelper.Conn, s *Server, passwd string) error {
s.GroupId = self.Id
servers, err := self.GetServers(zkConn)
if err != nil {
return errors.Trace(err)
}
var masterAddr string
for _, server := range servers {
if server.Type == SERVER_TYPE_MASTER {
masterAddr = server.Addr
}
}
开发者ID:cougar731,项目名称:codis,代码行数:30,代码来源:server_group.go
注:本文中的github.com/wandoulabs/codis/pkg/utils/errors.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论