本文整理汇总了Golang中github.com/juju/errors.ErrorStack函数的典型用法代码示例。如果您正苦于以下问题:Golang ErrorStack函数的具体用法?Golang ErrorStack怎么用?Golang ErrorStack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ErrorStack函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleCrashedServer
func handleCrashedServer(s *models.Server) error {
switch s.Type {
case models.SERVER_TYPE_MASTER:
//get slave and do promote
slave, err := getSlave(s)
if err != nil {
log.Warning(errors.ErrorStack(err))
return err
}
log.Infof("try promote %+v", slave)
err = callHttp(nil, genUrl(*apiServer, "/api/server_group/", slave.GroupId, "/promote"), "POST", slave)
if err != nil {
log.Errorf("do promote %v failed %v", slave, errors.ErrorStack(err))
return err
}
refreshSlave(s) //刷新
case models.SERVER_TYPE_SLAVE:
log.Errorf("slave is down: %+v", s)
case models.SERVER_TYPE_OFFLINE:
//no need to handle it
default:
log.Fatalf("unkonwn type %+v", s)
}
return nil
}
示例2: TestNewAction
func TestNewAction(t *testing.T) {
fakeZkConn := zkhelper.NewConn()
err := NewAction(fakeZkConn, productName, ACTION_TYPE_SLOT_CHANGED, nil, "desc", false)
if err != nil {
t.Error(errors.ErrorStack(err))
}
prefix := GetWatchActionPath(productName)
if exist, _, err := fakeZkConn.Exists(prefix); !exist {
t.Error(errors.ErrorStack(err))
}
//test if response node exists
d, _, err := fakeZkConn.Get(prefix + "/0000000001")
if err != nil {
t.Error(errors.ErrorStack(err))
}
//test get action data
d, _, err = fakeZkConn.Get(GetActionResponsePath(productName) + "/0000000001")
if err != nil {
t.Error(errors.ErrorStack(err))
}
var action Action
json.Unmarshal(d, &action)
if action.Desc != "desc" || action.Type != ACTION_TYPE_SLOT_CHANGED {
t.Error("create action error")
}
}
示例3: main
func main() {
flag.Parse()
conf, err := config.NewConfigFromFile(*configFile)
if err != nil {
log.Fatal(errors.ErrorStack(err))
}
if err = initLogger(conf); err != nil {
log.Fatal(errors.ErrorStack(err))
}
server, err := service.NewServer(conf)
if err != nil {
log.Fatal(errors.ErrorStack(err))
}
err = metrics.Init(conf)
if err != nil {
log.Fatalf("init metrics err: %v", err)
}
err = server.Start()
if err != nil {
log.Fatal(errors.ErrorStack(err))
}
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGTERM, os.Interrupt, os.Kill)
log.Debug("Process start")
<-c
server.Stop()
log.Debug("Process stop")
}
示例4: Run
// Run reads client query and writes query result to client in for loop, if there is a panic during query handling,
// it will be recovered and log the panic error.
// This function returns and the connection is closed if there is an IO error or there is a panic.
func (cc *clientConn) Run() {
defer func() {
r := recover()
if r != nil {
const size = 4096
buf := make([]byte, size)
buf = buf[:runtime.Stack(buf, false)]
log.Errorf("lastCmd %s, %v, %s", cc.lastCmd, r, buf)
}
cc.Close()
}()
for {
cc.alloc.Reset()
data, err := cc.readPacket()
if err != nil {
if terror.ErrorNotEqual(err, io.EOF) {
log.Error(errors.ErrorStack(err))
}
return
}
if err := cc.dispatch(data); err != nil {
if terror.ErrorEqual(err, io.EOF) {
return
}
log.Warnf("dispatch error %s, %s", errors.ErrorStack(err), cc)
log.Warnf("cmd: %s", string(data[1:]))
cc.writeError(err)
}
cc.pkt.sequence = 0
}
}
示例5: waitOnline
func (s *Server) waitOnline() {
s.mu.Lock()
defer s.mu.Unlock()
for {
pi, err := s.top.GetProxyInfo(s.pi.Id)
if err != nil {
log.Fatal(errors.ErrorStack(err))
}
if pi.State == models.PROXY_STATE_MARK_OFFLINE {
s.handleMarkOffline()
}
if pi.State == models.PROXY_STATE_ONLINE {
s.pi.State = pi.State
println("good, we are on line", s.pi.Id)
log.Info("we are online", s.pi.Id)
_, err := s.top.WatchNode(path.Join(models.GetProxyPath(s.top.ProductName), s.pi.Id), s.evtbus)
if err != nil {
log.Fatal(errors.ErrorStack(err))
}
return
}
println("wait to be online ", s.pi.Id)
log.Warning(s.pi.Id, "wait to be online")
time.Sleep(3 * time.Second)
}
}
示例6: groupUpdate
func (s *Server) groupUpdate(group string, queue string,
write string, read string, url string, ips string) string {
config, err := s.queue.GetSingleGroup(group, queue)
if err != nil {
log.Debugf("GetSingleGroup err:%s", errors.ErrorStack(err))
return `{"action":"update","result":false}`
}
if write != "" {
w, err := strconv.ParseBool(write)
if err == nil {
config.Write = w
}
}
if read != "" {
r, err := strconv.ParseBool(read)
if err == nil {
config.Read = r
}
}
if url != "" {
config.Url = url
}
if ips != "" {
config.Ips = strings.Split(ips, ",")
}
err = s.queue.UpdateGroup(group, queue, config.Write, config.Read, config.Url, config.Ips)
if err != nil {
log.Debugf("groupUpdate failed: %s", errors.ErrorStack(err))
return `{"action":"update","result":false}`
}
return `{"action":"update","result":true}`
}
示例7: nextBatch
func (s *Scan) nextBatch() int {
startKey := s.nextStartKey
if startKey == nil {
startKey = s.StartRow
}
// Notice: ignore error here.
// TODO: add error check, now only add a log.
rs, err := s.getData(startKey, 0)
if err != nil {
log.Errorf("scan next batch failed - [startKey=%q], %v", startKey, errors.ErrorStack(err))
}
// Current region get 0 data, try switch to next region.
if len(rs) == 0 && len(s.nextStartKey) > 0 {
// TODO: add error check, now only add a log.
rs, err = s.getData(s.nextStartKey, 0)
if err != nil {
log.Errorf("scan next batch failed - [startKey=%q], %v", s.nextStartKey, errors.ErrorStack(err))
}
}
s.cache = rs
return len(s.cache)
}
示例8: onConn
func (s *Server) onConn(c net.Conn) {
conn, err := s.newConn(c)
if err != nil {
log.Errorf("newConn error %s", errors.ErrorStack(err))
return
}
if err := conn.handshake(); err != nil {
log.Errorf("handshake error %s", errors.ErrorStack(err))
c.Close()
return
}
conn.ctx, err = s.driver.OpenCtx(conn.capability, uint8(conn.collation), conn.dbname)
if err != nil {
log.Errorf("open ctx error %s", errors.ErrorStack(err))
c.Close()
return
}
defer func() {
log.Infof("close %s", conn)
}()
s.rwlock.Lock()
s.clients[conn.connectionID] = conn
s.rwlock.Unlock()
conn.Run()
}
示例9: WritingLoop
func (s *session) WritingLoop() {
s.lastUnsentResponseSeq = 1
for {
select {
case resp, ok := <-s.backQ:
if !ok {
s.Close()
s.closeSignal.Done()
return
}
flush, err := s.handleResponse(resp)
if err != nil {
log.Warning(s.RemoteAddr(), resp.ctx, errors.ErrorStack(err))
s.Close() //notify reader to exit
continue
}
if flush && len(s.backQ) == 0 {
err := s.w.Flush()
if err != nil {
s.Close() //notify reader to exit
log.Warning(s.RemoteAddr(), resp.ctx, errors.ErrorStack(err))
continue
}
}
}
}
}
示例10: WebhookHandler
func (s *ApiServer) WebhookHandler(w http.ResponseWriter, r *http.Request) {
//todo: post a tyrant job and start task
err := r.ParseForm()
if err != nil {
http.Error(w, errors.ErrorStack(err), http.StatusInternalServerError)
return
}
vars := mux.Vars(r)
log.Debug(vars)
repo := r.Form.Get("repo")
log.Debug(r.Form, "repo", repo)
h := &task.JobHelper{Server: s.Server, ExecutorUrls: s.ExecutorUrls}
job := h.BuildRepoJob(repo)
if err := h.CreateJob(job); err != nil {
http.Error(w, errors.ErrorStack(err), http.StatusInternalServerError)
return
}
log.Debugf("%+v", job)
if err := h.RunJob(job); err != nil {
http.Error(w, errors.ErrorStack(err), http.StatusInternalServerError)
return
}
}
示例11: main
func main() {
tidb.RegisterLocalStore("boltdb", boltdb.Driver{})
tidb.RegisterStore("tikv", tikv.Driver{})
metric.RunMetric(3 * time.Second)
printer.PrintTiDBInfo()
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
if *lease < 0 {
log.Fatalf("invalid lease seconds %d", *lease)
}
tidb.SetSchemaLease(time.Duration(*lease) * time.Second)
cfg := &server.Config{
Addr: fmt.Sprintf(":%s", *port),
LogLevel: *logLevel,
StatusAddr: fmt.Sprintf(":%s", *statusPort),
Socket: *socket,
}
log.SetLevelByString(cfg.LogLevel)
store, err := tidb.NewStore(fmt.Sprintf("%s://%s", *store, *storePath))
if err != nil {
log.Fatal(errors.ErrorStack(err))
}
// Create a session to load information schema.
se, err := tidb.CreateSession(store)
if err != nil {
log.Fatal(errors.ErrorStack(err))
}
se.Close()
var driver server.IDriver
driver = server.NewTiDBDriver(store)
var svr *server.Server
svr, err = server.NewServer(cfg, driver)
if err != nil {
log.Fatal(errors.ErrorStack(err))
}
sc := make(chan os.Signal, 1)
signal.Notify(sc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
sig := <-sc
log.Infof("Got signal [%d] to exit.", sig)
svr.Close()
os.Exit(0)
}()
log.Error(svr.Run())
}
示例12: monitorHandler
func (s *Server) monitorHandler(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
monitorType := r.FormValue("type")
queue := r.FormValue("queue")
group := r.FormValue("group")
end := time.Now().Unix()
start := end - 5*60 //5min
interval := int64(1)
startTime := r.FormValue("start")
if startTime != "" {
start, _ = strconv.ParseInt(startTime, 10, 0)
}
endTime := r.FormValue("end")
if endTime != "" {
end, _ = strconv.ParseInt(endTime, 10, 0)
}
intervalTime := r.FormValue("interval")
if intervalTime != "" {
interval, _ = strconv.ParseInt(intervalTime, 10, 0)
}
var result string
switch monitorType {
case "send":
m, err := s.queue.GetSendMetrics(queue, group, start, end, interval)
if err != nil {
log.Debug("GetSendMetrics err: %s", errors.ErrorStack(err))
return
}
sm, err := json.Marshal(m)
if err != nil {
log.Debugf("GetSendMetrics Marshal err: %s", err)
return
}
result = string(sm)
case "receive":
m, err := s.queue.GetReceiveMetrics(queue, group, start, end, interval)
if err != nil {
log.Debug("GetReceiveMetrics err: %s", errors.ErrorStack(err))
return
}
rm, err := json.Marshal(m)
if err != nil {
log.Debugf("GetReceiveMetrics Marshal err: %s", err)
return
}
result = string(rm)
default:
result = "error, param type=" + monitorType + " not support!"
}
fmt.Fprintf(w, result)
}
示例13: runDDLJob
// runDDLJob runs a DDL job.
func (d *ddl) runDDLJob(t *meta.Meta, job *model.Job) {
log.Infof("[ddl] run DDL job %s", job)
if job.IsFinished() {
return
}
if job.State != model.JobRollback {
job.State = model.JobRunning
}
var err error
switch job.Type {
case model.ActionCreateSchema:
err = d.onCreateSchema(t, job)
case model.ActionDropSchema:
err = d.onDropSchema(t, job)
case model.ActionCreateTable:
err = d.onCreateTable(t, job)
case model.ActionDropTable:
err = d.onDropTable(t, job)
case model.ActionAddColumn:
err = d.onAddColumn(t, job)
case model.ActionDropColumn:
err = d.onDropColumn(t, job)
case model.ActionModifyColumn:
err = d.onModifyColumn(t, job)
case model.ActionAddIndex:
err = d.onCreateIndex(t, job)
case model.ActionDropIndex:
err = d.onDropIndex(t, job)
case model.ActionAddForeignKey:
err = d.onCreateForeignKey(t, job)
case model.ActionDropForeignKey:
err = d.onDropForeignKey(t, job)
case model.ActionTruncateTable:
err = d.onTruncateTable(t, job)
default:
// Invalid job, cancel it.
job.State = model.JobCancelled
err = errInvalidDDLJob.Gen("invalid ddl job %v", job)
}
// Save errors in job, so that others can know errors happened.
if err != nil {
// If job is not cancelled, we should log this error.
if job.State != model.JobCancelled {
log.Errorf("[ddl] run ddl job err %v", errors.ErrorStack(err))
} else {
log.Infof("[ddl] the job is normal to cancel because %v", errors.ErrorStack(err))
}
job.Error = toTError(err)
job.ErrorCount++
}
}
示例14: processAction
func (s *Server) processAction(e interface{}) {
if strings.Index(GetEventPath(e), models.GetProxyPath(s.top.ProductName)) == 0 {
//proxy event, should be order for me to suicide
s.handleProxyCommand()
return
}
//re-watch
nodes, err := s.top.WatchChildren(models.GetWatchActionPath(s.top.ProductName), s.evtbus)
if err != nil {
log.Fatal(errors.ErrorStack(err))
}
seqs, err := models.ExtraSeqList(nodes)
if err != nil {
log.Fatal(errors.ErrorStack(err))
}
if len(seqs) == 0 || !s.top.IsChildrenChangedEvent(e) {
return
}
//get last pos
index := -1
for i, seq := range seqs {
if s.lastActionSeq < seq {
index = i
break
}
}
if index < 0 {
return
}
actions := seqs[index:]
for _, seq := range actions {
exist, err := s.top.Exist(path.Join(s.top.GetActionResponsePath(seq), s.pi.Id))
if err != nil {
log.Fatal(errors.ErrorStack(err))
}
if exist {
continue
}
if s.checkAndDoTopoChange(seq) {
s.responseAction(int64(seq))
}
}
s.lastActionSeq = seqs[len(seqs)-1]
}
示例15: RegisterAndWait
func (s *Server) RegisterAndWait() {
_, err := s.top.CreateProxyInfo(&s.pi)
if err != nil {
log.Fatal(errors.ErrorStack(err))
}
_, err = s.top.CreateProxyFenceNode(&s.pi)
if err != nil {
log.Warning(errors.ErrorStack(err))
}
s.registerSignal()
s.waitOnline()
}