зеркало из https://github.com/github/vitess-gh.git
Fix some golint errors; Sql => SQL
This commit is contained in:
Родитель
f5c24fc49c
Коммит
f8fb95ef83
|
@ -66,7 +66,7 @@ const (
|
|||
|
||||
func handleError(err *error) {
|
||||
if x := recover(); x != nil {
|
||||
terr := x.(*sqldb.SqlError)
|
||||
terr := x.(*sqldb.SQLError)
|
||||
*err = terr
|
||||
}
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ func (conn *Connection) IsClosed() bool {
|
|||
// ExecuteFetch executes the query on the connection
|
||||
func (conn *Connection) ExecuteFetch(query string, maxrows int, wantfields bool) (qr *proto.QueryResult, err error) {
|
||||
if conn.IsClosed() {
|
||||
return nil, sqldb.NewSqlError(2006, "Connection is closed")
|
||||
return nil, sqldb.NewSQLError(2006, "Connection is closed")
|
||||
}
|
||||
|
||||
if C.vt_execute(&conn.c, (*C.char)(hack.StringPointer(query)), C.ulong(len(query)), 0) != 0 {
|
||||
|
@ -143,7 +143,7 @@ func (conn *Connection) ExecuteFetch(query string, maxrows int, wantfields bool)
|
|||
}
|
||||
|
||||
if qr.RowsAffected > uint64(maxrows) {
|
||||
return nil, &sqldb.SqlError{
|
||||
return nil, &sqldb.SQLError{
|
||||
Num: 0,
|
||||
Message: fmt.Sprintf("Row count exceeded %d", maxrows),
|
||||
Query: string(query),
|
||||
|
@ -181,7 +181,7 @@ func (conn *Connection) ExecuteFetchMap(query string) (map[string]string, error)
|
|||
// on the Connection until it returns nil or error
|
||||
func (conn *Connection) ExecuteStreamFetch(query string) (err error) {
|
||||
if conn.IsClosed() {
|
||||
return sqldb.NewSqlError(2006, "Connection is closed")
|
||||
return sqldb.NewSQLError(2006, "Connection is closed")
|
||||
}
|
||||
if C.vt_execute(&conn.c, (*C.char)(hack.StringPointer(query)), C.ulong(len(query)), 1) != 0 {
|
||||
return conn.lastError(query)
|
||||
|
@ -273,13 +273,13 @@ func (conn *Connection) ID() int64 {
|
|||
|
||||
func (conn *Connection) lastError(query string) error {
|
||||
if err := C.vt_error(&conn.c); *err != 0 {
|
||||
return &sqldb.SqlError{
|
||||
return &sqldb.SQLError{
|
||||
Num: int(C.vt_errno(&conn.c)),
|
||||
Message: C.GoString(err),
|
||||
Query: query,
|
||||
}
|
||||
}
|
||||
return &sqldb.SqlError{
|
||||
return &sqldb.SQLError{
|
||||
Num: 0,
|
||||
Message: "Dummy",
|
||||
Query: string(query),
|
||||
|
|
|
@ -6,20 +6,20 @@ package sqldb
|
|||
|
||||
import "fmt"
|
||||
|
||||
// SqlError is the error structure returned from calling a db library function
|
||||
type SqlError struct {
|
||||
// SQLError is the error structure returned from calling a db library function
|
||||
type SQLError struct {
|
||||
Num int
|
||||
Message string
|
||||
Query string
|
||||
}
|
||||
|
||||
// NewSqlError returns a new SqlError
|
||||
func NewSqlError(number int, format string, args ...interface{}) *SqlError {
|
||||
return &SqlError{Num: number, Message: fmt.Sprintf(format, args...)}
|
||||
// NewSQLError returns a new SQLError
|
||||
func NewSQLError(number int, format string, args ...interface{}) *SQLError {
|
||||
return &SQLError{Num: number, Message: fmt.Sprintf(format, args...)}
|
||||
}
|
||||
|
||||
// Error implements the error interface
|
||||
func (se *SqlError) Error() string {
|
||||
func (se *SQLError) Error() string {
|
||||
if se.Query == "" {
|
||||
return fmt.Sprintf("%v (errno %v)", se.Message, se.Num)
|
||||
}
|
||||
|
@ -27,6 +27,6 @@ func (se *SqlError) Error() string {
|
|||
}
|
||||
|
||||
// Number returns the internal mysql error code
|
||||
func (se *SqlError) Number() int {
|
||||
func (se *SQLError) Number() int {
|
||||
return se.Num
|
||||
}
|
||||
|
|
|
@ -223,7 +223,7 @@ func (blp *BinlogPlayer) processTransaction(tx *proto.BinlogTransaction) (ok boo
|
|||
if _, err = blp.exec(string(stmt.Sql)); err == nil {
|
||||
continue
|
||||
}
|
||||
if sqlErr, ok := err.(*sqldb.SqlError); ok && sqlErr.Number() == 1213 {
|
||||
if sqlErr, ok := err.(*sqldb.SQLError); ok && sqlErr.Number() == 1213 {
|
||||
// Deadlock: ask for retry
|
||||
log.Infof("Deadlock: %v", err)
|
||||
if err = blp.dbClient.Rollback(); err != nil {
|
||||
|
|
|
@ -28,7 +28,7 @@ func NewDbClient(params *sqldb.ConnParams) *DBClient {
|
|||
|
||||
func (dc *DBClient) handleError(err error) {
|
||||
// log.Errorf("in DBClient handleError %v", err.(error))
|
||||
if sqlErr, ok := err.(*sqldb.SqlError); ok {
|
||||
if sqlErr, ok := err.(*sqldb.SQLError); ok {
|
||||
if sqlErr.Number() >= 2000 && sqlErr.Number() <= 2018 { // mysql connection errors
|
||||
dc.Close()
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ type DBConnection struct {
|
|||
}
|
||||
|
||||
func (dbc *DBConnection) handleError(err error) {
|
||||
if sqlErr, ok := err.(*sqldb.SqlError); ok {
|
||||
if sqlErr, ok := err.(*sqldb.SQLError); ok {
|
||||
if sqlErr.Number() >= 2000 && sqlErr.Number() <= 2018 { // mysql connection errors
|
||||
dbc.Close()
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ func (sc *SlaveConnection) StartBinlogDump(startPos proto.ReplicationPosition) (
|
|||
|
||||
buf, err = sc.Conn.ReadPacket()
|
||||
if err != nil {
|
||||
if sqlErr, ok := err.(*sqldb.SqlError); ok && sqlErr.Number() == mysql.ErrServerLost {
|
||||
if sqlErr, ok := err.(*sqldb.SQLError); ok && sqlErr.Number() == mysql.ErrServerLost {
|
||||
// ErrServerLost = Lost connection to MySQL server during query
|
||||
// This is not necessarily an error. It could just be that we closed
|
||||
// the connection from outside.
|
||||
|
|
|
@ -229,7 +229,7 @@ func (cp *CachePool) Get(ctx context.Context) cacheservice.CacheService {
|
|||
}
|
||||
r, err := pool.Get(ctx)
|
||||
if err != nil {
|
||||
panic(NewTabletErrorSql(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, err))
|
||||
panic(NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, err))
|
||||
}
|
||||
return r.(cacheservice.CacheService)
|
||||
}
|
||||
|
|
|
@ -60,20 +60,20 @@ func (dbc *DBConn) Exec(ctx context.Context, query string, maxrows int, wantfiel
|
|||
return r, nil
|
||||
case !IsConnErr(err):
|
||||
// MySQL error that isn't due to a connection issue
|
||||
return nil, NewTabletErrorSql(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, err)
|
||||
return nil, NewTabletErrorSQL(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, err)
|
||||
case attempt == 2:
|
||||
// If the MySQL connection is bad, we assume that there is nothing wrong with
|
||||
// the query itself, and retrying it might succeed. The MySQL connection might
|
||||
// fix itself, or the query could succeed on a different VtTablet.
|
||||
return nil, NewTabletErrorSql(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, err)
|
||||
return nil, NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, err)
|
||||
}
|
||||
err2 := dbc.reconnect()
|
||||
if err2 != nil {
|
||||
go checkMySQL()
|
||||
return nil, NewTabletErrorSql(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, err)
|
||||
return nil, NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, err)
|
||||
}
|
||||
}
|
||||
return nil, NewTabletErrorSql(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, errors.New("dbconn.Exec: unreachable code"))
|
||||
return nil, NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, errors.New("dbconn.Exec: unreachable code"))
|
||||
}
|
||||
|
||||
func (dbc *DBConn) execOnce(ctx context.Context, query string, maxrows int, wantfields bool) (*mproto.QueryResult, error) {
|
||||
|
|
|
@ -104,7 +104,7 @@ func getOrPanic(ctx context.Context, pool *ConnPool) *DBConn {
|
|||
// If there's a problem with getting a connection out of the pool, that is
|
||||
// probably not due to the query itself. The query might succeed on a different
|
||||
// tablet.
|
||||
panic(NewTabletErrorSql(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, err))
|
||||
panic(NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, err))
|
||||
}
|
||||
|
||||
// NewQueryEngine creates a new QueryEngine.
|
||||
|
|
|
@ -501,7 +501,7 @@ func (qre *QueryExecutor) execUpsertPK(conn poolConn, invalidator CacheInvalidat
|
|||
if !ok {
|
||||
return result, err
|
||||
}
|
||||
if terr.SqlError != mysql.ErrDupEntry {
|
||||
if terr.SQLError != mysql.ErrDupEntry {
|
||||
return nil, err
|
||||
}
|
||||
// If the error didn't match pk, just return the error without updating.
|
||||
|
@ -741,7 +741,7 @@ func (qre *QueryExecutor) getConn(pool *ConnPool) (*DBConn, error) {
|
|||
case ErrConnPoolClosed:
|
||||
return nil, err
|
||||
}
|
||||
return nil, NewTabletErrorSql(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, err)
|
||||
return nil, NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, err)
|
||||
}
|
||||
|
||||
func (qre *QueryExecutor) qFetch(logStats *SQLQueryStats, parsedQuery *sqlparser.ParsedQuery, bindVars map[string]interface{}) (*mproto.QueryResult, error) {
|
||||
|
@ -756,7 +756,7 @@ func (qre *QueryExecutor) qFetch(logStats *SQLQueryStats, parsedQuery *sqlparser
|
|||
conn, err := qre.qe.connPool.Get(qre.ctx)
|
||||
logStats.WaitingForConnection += time.Now().Sub(waitingForConnectionStart)
|
||||
if err != nil {
|
||||
q.Err = NewTabletErrorSql(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, err)
|
||||
q.Err = NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, err)
|
||||
} else {
|
||||
defer conn.Recycle()
|
||||
q.Result, q.Err = qre.execSQL(conn, sql, false)
|
||||
|
@ -823,7 +823,7 @@ func (qre *QueryExecutor) execStreamSQL(conn *DBConn, sql string, callback func(
|
|||
qre.logStats.AddRewrittenSql(sql, start)
|
||||
if err != nil {
|
||||
// MySQL error that isn't due to a connection issue
|
||||
return NewTabletErrorSql(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, err)
|
||||
return NewTabletErrorSQL(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -248,7 +248,7 @@ func TestQueryExecutorPlanUpsertPk(t *testing.T) {
|
|||
|
||||
db.AddRejectedQuery(
|
||||
"insert into test_table values (1) /* _stream test_table (pk ) (1 ); */",
|
||||
sqldb.NewSqlError(mysql.ErrDupEntry, "err"),
|
||||
sqldb.NewSQLError(mysql.ErrDupEntry, "err"),
|
||||
)
|
||||
db.AddQuery("update test_table set val = 1 where pk in (1) /* _stream test_table (pk ) (1 ); */", &mproto.QueryResult{})
|
||||
_, err = qre.Execute()
|
||||
|
@ -259,7 +259,7 @@ func TestQueryExecutorPlanUpsertPk(t *testing.T) {
|
|||
|
||||
db.AddRejectedQuery(
|
||||
"insert into test_table values (1) /* _stream test_table (pk ) (1 ); */",
|
||||
sqldb.NewSqlError(mysql.ErrDupEntry, "ERROR 1062 (23000): Duplicate entry '2' for key 'PRIMARY'"),
|
||||
sqldb.NewSQLError(mysql.ErrDupEntry, "ERROR 1062 (23000): Duplicate entry '2' for key 'PRIMARY'"),
|
||||
)
|
||||
db.AddQuery(
|
||||
"update test_table set val = 1 where pk in (1) /* _stream test_table (pk ) (1 ); */",
|
||||
|
|
|
@ -385,8 +385,8 @@ func (sq *SqlQuery) handleExecErrorNoPanic(query *proto.Query, err interface{},
|
|||
return NewTabletError(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, "%v: uncaught panic for %v", err, query)
|
||||
}
|
||||
var myError error
|
||||
if sq.config.TerseErrors && terr.SqlError != 0 && len(query.BindVariables) != 0 {
|
||||
myError = fmt.Errorf("%s(errno %d) during query: %s", terr.Prefix(), terr.SqlError, query.Sql)
|
||||
if sq.config.TerseErrors && terr.SQLError != 0 && len(query.BindVariables) != 0 {
|
||||
myError = fmt.Errorf("%s(errno %d) during query: %s", terr.Prefix(), terr.SQLError, query.Sql)
|
||||
} else {
|
||||
myError = terr
|
||||
}
|
||||
|
@ -401,7 +401,7 @@ func (sq *SqlQuery) handleExecErrorNoPanic(query *proto.Query, err interface{},
|
|||
logMethod = log.Errorf
|
||||
}
|
||||
// We want to suppress/demote some MySQL error codes (regardless of the ErrorType)
|
||||
switch terr.SqlError {
|
||||
switch terr.SQLError {
|
||||
case mysql.ErrDupEntry:
|
||||
return myError
|
||||
case mysql.ErrLockWaitTimeout, mysql.ErrLockDeadlock, mysql.ErrDataTooLong, mysql.ErrDataOutOfRange:
|
||||
|
|
|
@ -1054,7 +1054,7 @@ func TestTerseErrors2(t *testing.T) {
|
|||
panic(&TabletError{
|
||||
ErrorType: ErrFail,
|
||||
Message: "msg",
|
||||
SqlError: 10,
|
||||
SQLError: 10,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1080,7 +1080,7 @@ func TestTerseErrors3(t *testing.T) {
|
|||
panic(&TabletError{
|
||||
ErrorType: ErrFail,
|
||||
Message: "msg",
|
||||
SqlError: 10,
|
||||
SQLError: 10,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ var logTxPoolFull = logutil.NewThrottledLogger("TxPoolFull", 1*time.Minute)
|
|||
type TabletError struct {
|
||||
ErrorType int
|
||||
Message string
|
||||
SqlError int
|
||||
SQLError int
|
||||
// ErrorCode will be used to transmit the error across RPC boundaries
|
||||
ErrorCode vtrpc.ErrorCode
|
||||
}
|
||||
|
@ -80,8 +80,8 @@ func NewTabletError(errorType int, errCode vtrpc.ErrorCode, format string, args
|
|||
}
|
||||
}
|
||||
|
||||
// NewTabletErrorSql returns a TabletError based on the error
|
||||
func NewTabletErrorSql(errorType int, errCode vtrpc.ErrorCode, err error) *TabletError {
|
||||
// NewTabletErrorSQL returns a TabletError based on the error
|
||||
func NewTabletErrorSQL(errorType int, errCode vtrpc.ErrorCode, err error) *TabletError {
|
||||
var errnum int
|
||||
errstr := err.Error()
|
||||
if sqlErr, ok := err.(hasNumber); ok {
|
||||
|
@ -102,7 +102,7 @@ func NewTabletErrorSql(errorType int, errCode vtrpc.ErrorCode, err error) *Table
|
|||
return &TabletError{
|
||||
ErrorType: errorType,
|
||||
Message: printable(errstr),
|
||||
SqlError: errnum,
|
||||
SQLError: errnum,
|
||||
ErrorCode: errCode,
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ func IsConnErr(err error) bool {
|
|||
var sqlError int
|
||||
switch err := err.(type) {
|
||||
case *TabletError:
|
||||
sqlError = err.SqlError
|
||||
sqlError = err.SQLError
|
||||
case hasNumber:
|
||||
sqlError = err.Number()
|
||||
default:
|
||||
|
@ -191,7 +191,7 @@ func (te *TabletError) Prefix() string {
|
|||
prefix = "not_in_tx: "
|
||||
}
|
||||
// Special case for killed queries.
|
||||
if te.SqlError == mysql.ErrServerLost {
|
||||
if te.SQLError == mysql.ErrServerLost {
|
||||
prefix = prefix + "the query was killed either because it timed out or was canceled: "
|
||||
}
|
||||
return prefix
|
||||
|
@ -209,7 +209,7 @@ func (te *TabletError) RecordStats(queryServiceStats *QueryServiceStats) {
|
|||
case ErrNotInTx:
|
||||
queryServiceStats.ErrorStats.Add("NotInTx", 1)
|
||||
default:
|
||||
switch te.SqlError {
|
||||
switch te.SQLError {
|
||||
case mysql.ErrDupEntry:
|
||||
queryServiceStats.InfoErrors.Add("DupKey", 1)
|
||||
case mysql.ErrLockWaitTimeout, mysql.ErrLockDeadlock:
|
||||
|
@ -237,7 +237,7 @@ func handleError(err *error, logStats *SQLQueryStats, queryServiceStats *QuerySe
|
|||
case ErrTxPoolFull:
|
||||
logTxPoolFull.Errorf("%v", terr)
|
||||
default:
|
||||
switch terr.SqlError {
|
||||
switch terr.SQLError {
|
||||
// MySQL deadlock errors are (usually) due to client behavior, not server
|
||||
// behavior, and therefore logged at the INFO level.
|
||||
case mysql.ErrLockWaitTimeout, mysql.ErrLockDeadlock, mysql.ErrDataTooLong, mysql.ErrDataOutOfRange:
|
||||
|
|
|
@ -15,8 +15,8 @@ import (
|
|||
)
|
||||
|
||||
func TestTabletErrorRetriableErrorTypeOverwrite(t *testing.T) {
|
||||
sqlErr := sqldb.NewSqlError(mysql.ErrOptionPreventsStatement, "read-only")
|
||||
tabletErr := NewTabletErrorSql(ErrFatal, vtrpc.ErrorCode_UNKNOWN_ERROR, sqlErr)
|
||||
sqlErr := sqldb.NewSQLError(mysql.ErrOptionPreventsStatement, "read-only")
|
||||
tabletErr := NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_UNKNOWN_ERROR, sqlErr)
|
||||
if tabletErr.ErrorType != ErrRetry || tabletErr.ErrorCode != vtrpc.ErrorCode_QUERY_NOT_SERVED {
|
||||
t.Fatalf("tablet error should have error type ErrRetry and error code %v", vtrpc.ErrorCode_QUERY_NOT_SERVED)
|
||||
}
|
||||
|
@ -28,8 +28,8 @@ func TestTabletErrorMsgTooLong(t *testing.T) {
|
|||
buf[i] = 'a'
|
||||
}
|
||||
msg := string(buf)
|
||||
sqlErr := sqldb.NewSqlError(mysql.ErrDupEntry, msg)
|
||||
tabletErr := NewTabletErrorSql(ErrFatal, vtrpc.ErrorCode_UNKNOWN_ERROR, sqlErr)
|
||||
sqlErr := sqldb.NewSQLError(mysql.ErrDupEntry, msg)
|
||||
tabletErr := NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_UNKNOWN_ERROR, sqlErr)
|
||||
if tabletErr.ErrorType != ErrFatal || tabletErr.ErrorCode != vtrpc.ErrorCode_INTEGRITY_ERROR {
|
||||
t.Fatalf("tablet error should have error type ErrFatal and error code %v", vtrpc.ErrorCode_INTEGRITY_ERROR)
|
||||
}
|
||||
|
@ -39,15 +39,15 @@ func TestTabletErrorMsgTooLong(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTabletErrorConnError(t *testing.T) {
|
||||
tabletErr := NewTabletErrorSql(ErrFatal, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSqlError(1999, "test"))
|
||||
tabletErr := NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(1999, "test"))
|
||||
if IsConnErr(tabletErr) {
|
||||
t.Fatalf("table error: %v is not a connection error", tabletErr)
|
||||
}
|
||||
tabletErr = NewTabletErrorSql(ErrFatal, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSqlError(2000, "test"))
|
||||
tabletErr = NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(2000, "test"))
|
||||
if !IsConnErr(tabletErr) {
|
||||
t.Fatalf("table error: %v is a connection error", tabletErr)
|
||||
}
|
||||
tabletErr = NewTabletErrorSql(ErrFatal, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSqlError(mysql.ErrServerLost, "test"))
|
||||
tabletErr = NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(mysql.ErrServerLost, "test"))
|
||||
if IsConnErr(tabletErr) {
|
||||
t.Fatalf("table error: %v is not a connection error", tabletErr)
|
||||
}
|
||||
|
@ -55,11 +55,11 @@ func TestTabletErrorConnError(t *testing.T) {
|
|||
if tabletErr.Error() != want {
|
||||
t.Fatalf("tablet error: %v, want %s", tabletErr, want)
|
||||
}
|
||||
sqlErr := sqldb.NewSqlError(1998, "test")
|
||||
sqlErr := sqldb.NewSQLError(1998, "test")
|
||||
if IsConnErr(sqlErr) {
|
||||
t.Fatalf("sql error: %v is not a connection error", sqlErr)
|
||||
}
|
||||
sqlErr = sqldb.NewSqlError(2001, "test")
|
||||
sqlErr = sqldb.NewSQLError(2001, "test")
|
||||
if !IsConnErr(sqlErr) {
|
||||
t.Fatalf("sql error: %v is a connection error", sqlErr)
|
||||
}
|
||||
|
@ -76,26 +76,26 @@ func TestTabletErrorConnError(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTabletErrorPrefix(t *testing.T) {
|
||||
tabletErr := NewTabletErrorSql(ErrRetry, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSqlError(2000, "test"))
|
||||
tabletErr := NewTabletErrorSQL(ErrRetry, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(2000, "test"))
|
||||
if tabletErr.Prefix() != "retry: " {
|
||||
t.Fatalf("tablet error with error type: ErrRetry should has prefix: 'retry: '")
|
||||
}
|
||||
tabletErr = NewTabletErrorSql(ErrFatal, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSqlError(2000, "test"))
|
||||
tabletErr = NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(2000, "test"))
|
||||
if tabletErr.Prefix() != "fatal: " {
|
||||
t.Fatalf("tablet error with error type: ErrFatal should has prefix: 'fatal: '")
|
||||
}
|
||||
tabletErr = NewTabletErrorSql(ErrTxPoolFull, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSqlError(2000, "test"))
|
||||
tabletErr = NewTabletErrorSQL(ErrTxPoolFull, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(2000, "test"))
|
||||
if tabletErr.Prefix() != "tx_pool_full: " {
|
||||
t.Fatalf("tablet error with error type: ErrTxPoolFull should has prefix: 'tx_pool_full: '")
|
||||
}
|
||||
tabletErr = NewTabletErrorSql(ErrNotInTx, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSqlError(2000, "test"))
|
||||
tabletErr = NewTabletErrorSQL(ErrNotInTx, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(2000, "test"))
|
||||
if tabletErr.Prefix() != "not_in_tx: " {
|
||||
t.Fatalf("tablet error with error type: ErrNotInTx should has prefix: 'not_in_tx: '")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTabletErrorRecordStats(t *testing.T) {
|
||||
tabletErr := NewTabletErrorSql(ErrRetry, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSqlError(2000, "test"))
|
||||
tabletErr := NewTabletErrorSQL(ErrRetry, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(2000, "test"))
|
||||
queryServiceStats := NewQueryServiceStats("", false)
|
||||
retryCounterBefore := queryServiceStats.InfoErrors.Counts()["Retry"]
|
||||
tabletErr.RecordStats(queryServiceStats)
|
||||
|
@ -104,7 +104,7 @@ func TestTabletErrorRecordStats(t *testing.T) {
|
|||
t.Fatalf("tablet error with error type ErrRetry should increase Retry error count by 1")
|
||||
}
|
||||
|
||||
tabletErr = NewTabletErrorSql(ErrFatal, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSqlError(2000, "test"))
|
||||
tabletErr = NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(2000, "test"))
|
||||
fatalCounterBefore := queryServiceStats.InfoErrors.Counts()["Fatal"]
|
||||
tabletErr.RecordStats(queryServiceStats)
|
||||
fatalCounterAfter := queryServiceStats.InfoErrors.Counts()["Fatal"]
|
||||
|
@ -112,7 +112,7 @@ func TestTabletErrorRecordStats(t *testing.T) {
|
|||
t.Fatalf("tablet error with error type ErrFatal should increase Fatal error count by 1")
|
||||
}
|
||||
|
||||
tabletErr = NewTabletErrorSql(ErrTxPoolFull, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSqlError(2000, "test"))
|
||||
tabletErr = NewTabletErrorSQL(ErrTxPoolFull, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(2000, "test"))
|
||||
txPoolFullCounterBefore := queryServiceStats.ErrorStats.Counts()["TxPoolFull"]
|
||||
tabletErr.RecordStats(queryServiceStats)
|
||||
txPoolFullCounterAfter := queryServiceStats.ErrorStats.Counts()["TxPoolFull"]
|
||||
|
@ -120,7 +120,7 @@ func TestTabletErrorRecordStats(t *testing.T) {
|
|||
t.Fatalf("tablet error with error type ErrTxPoolFull should increase TxPoolFull error count by 1")
|
||||
}
|
||||
|
||||
tabletErr = NewTabletErrorSql(ErrNotInTx, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSqlError(2000, "test"))
|
||||
tabletErr = NewTabletErrorSQL(ErrNotInTx, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(2000, "test"))
|
||||
notInTxCounterBefore := queryServiceStats.ErrorStats.Counts()["NotInTx"]
|
||||
tabletErr.RecordStats(queryServiceStats)
|
||||
notInTxCounterAfter := queryServiceStats.ErrorStats.Counts()["NotInTx"]
|
||||
|
@ -128,7 +128,7 @@ func TestTabletErrorRecordStats(t *testing.T) {
|
|||
t.Fatalf("tablet error with error type ErrNotInTx should increase NotInTx error count by 1")
|
||||
}
|
||||
|
||||
tabletErr = NewTabletErrorSql(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSqlError(mysql.ErrDupEntry, "test"))
|
||||
tabletErr = NewTabletErrorSQL(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(mysql.ErrDupEntry, "test"))
|
||||
dupKeyCounterBefore := queryServiceStats.InfoErrors.Counts()["DupKey"]
|
||||
tabletErr.RecordStats(queryServiceStats)
|
||||
dupKeyCounterAfter := queryServiceStats.InfoErrors.Counts()["DupKey"]
|
||||
|
@ -136,7 +136,7 @@ func TestTabletErrorRecordStats(t *testing.T) {
|
|||
t.Fatalf("sql error with error type mysql.ErrDupEntry should increase DupKey error count by 1")
|
||||
}
|
||||
|
||||
tabletErr = NewTabletErrorSql(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSqlError(mysql.ErrLockWaitTimeout, "test"))
|
||||
tabletErr = NewTabletErrorSQL(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(mysql.ErrLockWaitTimeout, "test"))
|
||||
lockWaitTimeoutCounterBefore := queryServiceStats.ErrorStats.Counts()["Deadlock"]
|
||||
tabletErr.RecordStats(queryServiceStats)
|
||||
lockWaitTimeoutCounterAfter := queryServiceStats.ErrorStats.Counts()["Deadlock"]
|
||||
|
@ -144,7 +144,7 @@ func TestTabletErrorRecordStats(t *testing.T) {
|
|||
t.Fatalf("sql error with error type mysql.ErrLockWaitTimeout should increase Deadlock error count by 1")
|
||||
}
|
||||
|
||||
tabletErr = NewTabletErrorSql(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSqlError(mysql.ErrLockDeadlock, "test"))
|
||||
tabletErr = NewTabletErrorSQL(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(mysql.ErrLockDeadlock, "test"))
|
||||
deadlockCounterBefore := queryServiceStats.ErrorStats.Counts()["Deadlock"]
|
||||
tabletErr.RecordStats(queryServiceStats)
|
||||
deadlockCounterAfter := queryServiceStats.ErrorStats.Counts()["Deadlock"]
|
||||
|
@ -152,7 +152,7 @@ func TestTabletErrorRecordStats(t *testing.T) {
|
|||
t.Fatalf("sql error with error type mysql.ErrLockDeadlock should increase Deadlock error count by 1")
|
||||
}
|
||||
|
||||
tabletErr = NewTabletErrorSql(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSqlError(mysql.ErrOptionPreventsStatement, "test"))
|
||||
tabletErr = NewTabletErrorSQL(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(mysql.ErrOptionPreventsStatement, "test"))
|
||||
failCounterBefore := queryServiceStats.ErrorStats.Counts()["Fail"]
|
||||
tabletErr.RecordStats(queryServiceStats)
|
||||
failCounterAfter := queryServiceStats.ErrorStats.Counts()["Fail"]
|
||||
|
@ -177,7 +177,7 @@ func TestTabletErrorHandleUncaughtError(t *testing.T) {
|
|||
|
||||
func TestTabletErrorHandleRetryError(t *testing.T) {
|
||||
var err error
|
||||
tabletErr := NewTabletErrorSql(ErrRetry, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSqlError(1000, "test"))
|
||||
tabletErr := NewTabletErrorSQL(ErrRetry, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(1000, "test"))
|
||||
logStats := newSqlQueryStats("TestTabletErrorHandleError", context.Background())
|
||||
queryServiceStats := NewQueryServiceStats("", false)
|
||||
defer func() {
|
||||
|
@ -192,7 +192,7 @@ func TestTabletErrorHandleRetryError(t *testing.T) {
|
|||
|
||||
func TestTabletErrorHandleTxPoolFullError(t *testing.T) {
|
||||
var err error
|
||||
tabletErr := NewTabletErrorSql(ErrTxPoolFull, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSqlError(1000, "test"))
|
||||
tabletErr := NewTabletErrorSQL(ErrTxPoolFull, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(1000, "test"))
|
||||
logStats := newSqlQueryStats("TestTabletErrorHandleError", context.Background())
|
||||
queryServiceStats := NewQueryServiceStats("", false)
|
||||
defer func() {
|
||||
|
@ -219,7 +219,7 @@ func TestTabletErrorLogUncaughtErr(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTabletErrorTxPoolFull(t *testing.T) {
|
||||
tabletErr := NewTabletErrorSql(ErrTxPoolFull, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSqlError(1000, "test"))
|
||||
tabletErr := NewTabletErrorSQL(ErrTxPoolFull, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(1000, "test"))
|
||||
queryServiceStats := NewQueryServiceStats("", false)
|
||||
defer func() {
|
||||
err := recover()
|
||||
|
@ -232,7 +232,7 @@ func TestTabletErrorTxPoolFull(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTabletErrorFatal(t *testing.T) {
|
||||
tabletErr := NewTabletErrorSql(ErrFatal, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSqlError(1000, "test"))
|
||||
tabletErr := NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_UNKNOWN_ERROR, sqldb.NewSQLError(1000, "test"))
|
||||
queryServiceStats := NewQueryServiceStats("", false)
|
||||
defer func() {
|
||||
err := recover()
|
||||
|
|
|
@ -149,11 +149,11 @@ func (axp *TxPool) Begin(ctx context.Context) int64 {
|
|||
axp.LogActive()
|
||||
panic(NewTabletError(ErrTxPoolFull, vtrpc.ErrorCode_RESOURCE_EXHAUSTED, "Transaction pool connection limit exceeded"))
|
||||
}
|
||||
panic(NewTabletErrorSql(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, err))
|
||||
panic(NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, err))
|
||||
}
|
||||
if _, err := conn.Exec(ctx, "begin", 1, false); err != nil {
|
||||
conn.Recycle()
|
||||
panic(NewTabletErrorSql(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, err))
|
||||
panic(NewTabletErrorSQL(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, err))
|
||||
}
|
||||
transactionID := axp.lastID.Add(1)
|
||||
axp.activePool.Register(transactionID, newTxConnection(conn, transactionID, axp))
|
||||
|
@ -173,7 +173,7 @@ func (axp *TxPool) SafeCommit(ctx context.Context, transactionID int64) (invalid
|
|||
axp.txStats.Add("Completed", time.Now().Sub(conn.StartTime))
|
||||
if _, fetchErr := conn.Exec(ctx, "commit", 1, false); fetchErr != nil {
|
||||
conn.Close()
|
||||
err = NewTabletErrorSql(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, fetchErr)
|
||||
err = NewTabletErrorSQL(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, fetchErr)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ func (axp *TxPool) Rollback(ctx context.Context, transactionID int64) {
|
|||
axp.txStats.Add("Aborted", time.Now().Sub(conn.StartTime))
|
||||
if _, err := conn.Exec(ctx, "rollback", 1, false); err != nil {
|
||||
conn.Close()
|
||||
panic(NewTabletErrorSql(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, err))
|
||||
panic(NewTabletErrorSQL(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, err))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -281,9 +281,9 @@ func (txc *TxConnection) Exec(ctx context.Context, query string, maxrows int, wa
|
|||
if err != nil {
|
||||
if IsConnErr(err) {
|
||||
go checkMySQL()
|
||||
return nil, NewTabletErrorSql(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, err)
|
||||
return nil, NewTabletErrorSQL(ErrFatal, vtrpc.ErrorCode_INTERNAL_ERROR, err)
|
||||
}
|
||||
return nil, NewTabletErrorSql(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, err)
|
||||
return nil, NewTabletErrorSQL(ErrFail, vtrpc.ErrorCode_UNKNOWN_ERROR, err)
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
|
|
@ -286,7 +286,7 @@ func Register() *DB {
|
|||
}
|
||||
|
||||
func newConnError() error {
|
||||
return &sqldb.SqlError{
|
||||
return &sqldb.SQLError{
|
||||
Num: 2012,
|
||||
Message: "connection fail",
|
||||
Query: "",
|
||||
|
|
Загрузка…
Ссылка в новой задаче