本文整理匯總了Golang中github.com/ngaut/logging.Error函數的典型用法代碼示例。如果您正苦於以下問題:Golang Error函數的具體用法?Golang Error怎麽用?Golang Error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Error函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: cmdProxy
func cmdProxy(argv []string) (err error) {
usage := `usage:
cconfig proxy list
cconfig proxy offline <proxy_name>
cconfig proxy online <proxy_name>
`
args, err := docopt.Parse(usage, argv, true, "", false)
if err != nil {
log.Error(err)
return err
}
log.Debug(args)
zkLock.Lock(fmt.Sprintf("proxy, %+v", argv))
defer func() {
err := zkLock.Unlock()
if err != nil {
log.Error(err)
}
}()
if args["list"].(bool) {
log.Warning(err)
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
}
示例2: updateItemsStats
func (s *MemcacheStats) updateItemsStats() {
if s.items == nil {
return
}
s.readStats("items", func(sKey, sValue string) {
ival, err := strconv.ParseInt(sValue, 10, 64)
if err != nil {
log.Error(err)
internalErrors.Add("MemcacheStats", 1)
return
}
subkey, slabid, err := parseItemKey(sKey)
if err != nil {
log.Error(err)
internalErrors.Add("MemcacheStats", 1)
return
}
m, ok := s.items[subkey]
if !ok {
log.Errorf("Unknown memcache items stats %v %v: %v", subkey, slabid, ival)
internalErrors.Add("MemcacheStats", 1)
return
}
m[slabid] = ival
})
}
示例3: postConnect
func (cp *ConnPool) postConnect(conn net.Conn, err error) (net.Conn, error) {
if err != nil || !cp.sendReadOnly {
return conn, err
}
defer func() {
if err != nil {
conn.Close()
conn = nil
}
}()
if _, err = conn.Write(REDIS_CMD_READ_ONLY); err != nil {
log.Error("write READONLY failed", conn.RemoteAddr().String(), err)
return conn, err
}
var data *resp.Data
reader := bufio.NewReader(conn)
data, err = resp.ReadData(reader)
if err != nil {
log.Error("read READONLY resp failed", conn.RemoteAddr().String(), err)
return conn, err
}
if data.T == resp.T_Error {
log.Error("READONLY resp is not OK", conn.RemoteAddr().String())
err = errors.New("post connect error: READONLY resp is not OK")
}
return conn, err
}
示例4: cmdServer
func cmdServer(argv []string) (err error) {
usage := `usage:
cconfig server list
cconfig server add <group_id> <redis_addr> <role>
cconfig server remove <group_id> <redis_addr>
cconfig server promote <group_id> <redis_addr>
cconfig server add-group <group_id>
cconfig server remove-group <group_id>
`
args, err := docopt.Parse(usage, argv, true, "", false)
if err != nil {
log.Error(err)
return err
}
log.Debug(args)
zkLock.Lock(fmt.Sprintf("server, %+v", argv))
defer func() {
err := zkLock.Unlock()
if err != nil {
log.Error(err)
}
}()
if args["list"].(bool) {
return runListServerGroup()
}
groupId, err := strconv.Atoi(args["<group_id>"].(string))
if err != nil {
log.Warning(err)
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
}
示例5: Init
func (self *SQLite3Storage) Init() error {
var err error
self.db, err = sql.Open("sqlite3", self.Source)
if err != nil {
log.Error(err)
return err
}
_, create_err := self.db.Exec(createTableSQL)
if create_err != nil {
log.Error(create_err)
return create_err
}
return self.db.Ping()
}
示例6: resetSchemaInfo
func (s *Server) resetSchemaInfo() error {
for _, c := range s.clients {
if len(c.txConns) > 0 {
return errors.Errorf("transaction exist")
}
}
cfg, err := config.ParseConfigFile(s.configFile)
if err != nil {
log.Error(err)
return err
}
s.cleanup()
s.autoSchamas = make(map[string]*tabletserver.SchemaInfo)
for _, n := range s.shards {
n.Close()
}
s.shards = nil
s.schemas = nil
log.Warningf("%#v", cfg)
log.SetLevelByString(cfg.LogLevel)
s.cfg = cfg
return s.loadSchemaInfo()
}
示例7: main
func main() {
fmt.Print(banner)
log.SetLevelByString("info")
args, err := docopt.Parse(usage, nil, true, "codis proxy v0.1", true)
if err != nil {
log.Error(err)
}
// set config file
if args["-c"] != nil {
configFile = args["-c"].(string)
}
// set output log file
if args["-L"] != nil {
log.SetOutputByName(args["-L"].(string))
}
// set log level
if args["--log-level"] != nil {
log.SetLevelByString(args["--log-level"].(string))
}
// set cpu
if args["--cpu"] != nil {
cpus, err = strconv.Atoi(args["--cpu"].(string))
if err != nil {
log.Fatal(err)
}
}
// set addr
if args["--addr"] != nil {
addr = args["--addr"].(string)
}
// set http addr
if args["--http-addr"] != nil {
httpAddr = args["--http-addr"].(string)
}
wd, _ := os.Getwd()
log.Info("wd:", wd)
log.CrashLog(wd + ".dump")
router.CheckUlimit(1024)
runtime.GOMAXPROCS(cpus)
http.HandleFunc("/setloglevel", handleSetLogLevel)
go http.ListenAndServe(httpAddr, nil)
log.Info("running on ", addr)
conf, err := router.LoadConf(configFile)
if err != nil {
log.Fatal(err)
}
s := router.NewServer(addr, httpAddr, conf)
s.Run()
log.Warning("exit")
}
示例8: 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.Error(err)
return err
}
log.Debug(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
}
示例9: 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.Error(err)
return err
}
log.Debug(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
}
示例10: addReadyTask
func (self *ResMan) addReadyTask(id string) (string, error) {
if self.ready.Exist(id) {
return "", fmt.Errorf("%s already exist: %+v", id, self.ready.Get(id))
}
job, err := scheduler.GetJobById(id)
if err != nil {
return "", err
}
persistentTask := &scheduler.Task{TaskId: self.genTaskId(), Status: scheduler.STATUS_READY,
StartTs: time.Now().Unix(), JobName: job.Name}
log.Warningf("%+v", persistentTask)
err = persistentTask.Save()
if err != nil {
log.Error(err)
return "", err
}
job.LastTaskId = persistentTask.TaskId
job.Save()
t := &Task{Tid: persistentTask.TaskId, job: job, state: taskReady}
self.ready.Add(t.Tid, t)
log.Debugf("ready task %+v, total count:%d", t, self.ready.Length())
return persistentTask.TaskId, nil
}
示例11: GetJobs
func (self *RedisQ) GetJobs() ([]*Job, error) {
strs, err := self.client.Keys(JobPrefix + "*").Result()
if err != nil {
return nil, err
}
if len(strs) == 0 { //no jobs on redis
return nil, nil
}
vals, err := self.client.MGet(strs...).Result()
if err != nil {
return nil, err
}
jobs := make([]*Job, len(strs), len(strs))
for i, s := range vals {
err := json.Unmarshal([]byte(s.(string)), &jobs[i])
if err != nil {
log.Error(s)
return nil, err
}
}
return jobs, nil
}
示例12: 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.Warning("abnormal waiting time for receivers", 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.Error("proxies didn't responed: ", 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)
}
示例13: generateSelectSql
//todo: test select a == b && c == d
//select c ==d && a == b
func generateSelectSql(ti *tabletserver.TableInfo, plan *planbuilder.ExecPlan) (string, error) {
if len(ti.PKColumns) != len(plan.PKValues) {
log.Error("PKColumns and PKValues not match")
return "", errors.Errorf("PKColumns and PKValues not match, %+v, %+v", ti.PKColumns, plan.PKValues)
}
pks := make([]schema.TableColumn, 0, len(ti.PKColumns))
for i, _ := range ti.PKColumns {
pks = append(pks, ti.Columns[ti.PKColumns[i]])
}
buf := &bytes.Buffer{}
buf.WriteString(fmt.Sprintf("select * from %s where ", ti.Name))
for i, pk := range pks {
buf.WriteString(pk.Name)
buf.WriteString("=")
plan.PKValues[i].(sqltypes.Value).EncodeSql(buf)
if i < len(pks)-1 {
buf.WriteString(" and ")
}
}
buf.WriteString(";")
return buf.String(), nil
}
示例14: responseAction
func (s *Server) responseAction(seq int64) {
log.Info("send response", seq)
err := s.top.DoResponse(int(seq), &s.pi)
if err != nil {
log.Error(errors.ErrorStack(err))
}
}
示例15: Start
func (self *Server) Start(addr string) {
ln, err := net.Listen("tcp", addr)
if err != nil {
log.Fatal(err)
}
go self.EvtLoop()
log.Debug("listening on", addr)
go registerWebHandler(self)
//load background jobs from storage
err = self.store.Init()
if err != nil {
log.Error(err)
self.store = nil
} else {
self.getAllJobs()
}
for {
conn, err := ln.Accept()
if err != nil { // handle error
continue
}
session := &session{}
go session.handleConnection(self, conn)
}
}