2012-06-07 22:55:06 +04:00
|
|
|
// Copyright 2012, Google Inc. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
2012-02-25 11:30:03 +04:00
|
|
|
|
|
|
|
package tabletserver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2013-03-14 23:16:32 +04:00
|
|
|
|
Automatic rewrite of relog import paths and calls to use glog.
Commands run:
find go -name "*.go" | xargs sed --in-place -r 's,"github.com/youtube/vitess/go/relog",log "github.com/golang/glog",g; s,relog.Info,log.Infof,g; s,relog.Warning,log.Warningf,g; s,relog.Error,log.Errorf,g; s,relog.Fatal,log.Fatalf,g; s,relog.Debug,log.V(6).Infof,g'
find . -name '*.go' -exec gofmt -w {} \;
2013-08-07 01:56:00 +04:00
|
|
|
log "github.com/golang/glog"
|
2013-07-19 05:18:20 +04:00
|
|
|
"github.com/youtube/vitess/go/tb"
|
2012-02-25 11:30:03 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
FAIL = iota
|
|
|
|
RETRY
|
|
|
|
FATAL
|
2013-02-21 09:50:47 +04:00
|
|
|
TX_POOL_FULL
|
2012-02-25 11:30:03 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
DUPLICATE_KEY = 1062 // MySQL error number
|
|
|
|
)
|
|
|
|
|
|
|
|
type TabletError struct {
|
|
|
|
ErrorType int
|
|
|
|
Message string
|
|
|
|
SqlError int
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is how go-mysql exports its error number
|
|
|
|
type hasNumber interface {
|
|
|
|
Number() int
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTabletError(errorType int, format string, args ...interface{}) *TabletError {
|
|
|
|
return &TabletError{errorType, fmt.Sprintf(format, args...), 0}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTabletErrorSql(errorType int, err error) *TabletError {
|
2013-04-11 02:43:10 +04:00
|
|
|
te := NewTabletError(errorType, "%s", err)
|
2012-02-25 11:30:03 +04:00
|
|
|
if sqlErr, ok := err.(hasNumber); ok {
|
2013-04-11 02:43:10 +04:00
|
|
|
te.SqlError = sqlErr.Number()
|
2012-02-25 11:30:03 +04:00
|
|
|
}
|
2013-04-11 02:43:10 +04:00
|
|
|
return te
|
2012-02-25 11:30:03 +04:00
|
|
|
}
|
|
|
|
|
2013-04-11 02:43:10 +04:00
|
|
|
func (te *TabletError) Error() string {
|
2012-02-25 11:30:03 +04:00
|
|
|
format := "error: %s"
|
2013-04-11 02:43:10 +04:00
|
|
|
switch te.ErrorType {
|
2012-02-25 11:30:03 +04:00
|
|
|
case RETRY:
|
|
|
|
format = "retry: %s"
|
|
|
|
case FATAL:
|
|
|
|
format = "fatal: %s"
|
|
|
|
}
|
2013-04-11 02:43:10 +04:00
|
|
|
return fmt.Sprintf(format, te.Message)
|
2012-02-25 11:30:03 +04:00
|
|
|
}
|
|
|
|
|
2013-04-11 02:43:10 +04:00
|
|
|
func (te *TabletError) RecordStats() {
|
|
|
|
switch te.ErrorType {
|
2012-02-25 11:30:03 +04:00
|
|
|
case RETRY:
|
|
|
|
errorStats.Add("Retry", 1)
|
|
|
|
case FATAL:
|
|
|
|
errorStats.Add("Fatal", 1)
|
2013-02-21 09:50:47 +04:00
|
|
|
case TX_POOL_FULL:
|
|
|
|
errorStats.Add("TxPoolFull", 1)
|
2012-02-25 11:30:03 +04:00
|
|
|
default:
|
2013-04-11 02:43:10 +04:00
|
|
|
if te.SqlError == DUPLICATE_KEY {
|
2012-02-25 11:30:03 +04:00
|
|
|
errorStats.Add("DupKey", 1)
|
|
|
|
} else {
|
|
|
|
errorStats.Add("Fail", 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-20 04:24:03 +04:00
|
|
|
func handleError(err *error, logStats *sqlQueryStats) {
|
|
|
|
if logStats != nil {
|
|
|
|
logStats.Send()
|
|
|
|
}
|
2012-02-25 11:30:03 +04:00
|
|
|
if x := recover(); x != nil {
|
2012-12-20 05:48:02 +04:00
|
|
|
terr, ok := x.(*TabletError)
|
|
|
|
if !ok {
|
Automatic rewrite of relog import paths and calls to use glog.
Commands run:
find go -name "*.go" | xargs sed --in-place -r 's,"github.com/youtube/vitess/go/relog",log "github.com/golang/glog",g; s,relog.Info,log.Infof,g; s,relog.Warning,log.Warningf,g; s,relog.Error,log.Errorf,g; s,relog.Fatal,log.Fatalf,g; s,relog.Debug,log.V(6).Infof,g'
find . -name '*.go' -exec gofmt -w {} \;
2013-08-07 01:56:00 +04:00
|
|
|
log.Errorf("Uncaught panic:\n%v\n%s", x, tb.Stack(4))
|
2012-12-20 05:48:02 +04:00
|
|
|
*err = NewTabletError(FAIL, "%v: uncaught panic", x)
|
|
|
|
errorStats.Add("Panic", 1)
|
|
|
|
return
|
|
|
|
}
|
2012-02-25 11:30:03 +04:00
|
|
|
*err = terr
|
|
|
|
terr.RecordStats()
|
|
|
|
if terr.ErrorType == RETRY { // Retry errors are too spammy
|
|
|
|
return
|
|
|
|
}
|
Automatic rewrite of relog import paths and calls to use glog.
Commands run:
find go -name "*.go" | xargs sed --in-place -r 's,"github.com/youtube/vitess/go/relog",log "github.com/golang/glog",g; s,relog.Info,log.Infof,g; s,relog.Warning,log.Warningf,g; s,relog.Error,log.Errorf,g; s,relog.Fatal,log.Fatalf,g; s,relog.Debug,log.V(6).Infof,g'
find . -name '*.go' -exec gofmt -w {} \;
2013-08-07 01:56:00 +04:00
|
|
|
log.Errorf("%s", terr.Message)
|
2012-02-25 11:30:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func logError() {
|
|
|
|
if x := recover(); x != nil {
|
Automatic rewrite of relog import paths and calls to use glog.
Commands run:
find go -name "*.go" | xargs sed --in-place -r 's,"github.com/youtube/vitess/go/relog",log "github.com/golang/glog",g; s,relog.Info,log.Infof,g; s,relog.Warning,log.Warningf,g; s,relog.Error,log.Errorf,g; s,relog.Fatal,log.Fatalf,g; s,relog.Debug,log.V(6).Infof,g'
find . -name '*.go' -exec gofmt -w {} \;
2013-08-07 01:56:00 +04:00
|
|
|
log.Errorf("%s", x.(*TabletError).Message)
|
2012-02-25 11:30:03 +04:00
|
|
|
}
|
|
|
|
}
|