Merge pull request #619 from youtube/suguwork

tabletserver: verbose error for killed queries
This commit is contained in:
sougou 2015-04-24 00:44:18 -07:00
Родитель e702c3744a 9a8f8b8a35
Коммит c88513e39a
8 изменённых файлов: 21 добавлений и 8 удалений

Просмотреть файл

@ -50,6 +50,9 @@ const (
// ErrOptionPreventsStatement is C.ER_OPTION_PREVENTS_STATEMENT
ErrOptionPreventsStatement = C.ER_OPTION_PREVENTS_STATEMENT
// ErrServerLost is C.CR_SERVER_LOST (2013)
ErrServerLost = C.CR_SERVER_LOST
// RedactedPassword is the password value used in redacted configs
RedactedPassword = "****"
)

Просмотреть файл

@ -3,6 +3,7 @@
// license that can be found in the LICENSE file.
#include <mysql.h>
#include <errmsg.h>
// This API provides convenient C wrapper functions for mysql client.

Просмотреть файл

@ -10,6 +10,7 @@ import (
"fmt"
log "github.com/golang/glog"
"github.com/youtube/vitess/go/mysql"
"github.com/youtube/vitess/go/pools"
"github.com/youtube/vitess/go/sqldb"
"github.com/youtube/vitess/go/sync2"
@ -105,8 +106,8 @@ func (sc *SlaveConnection) StartBinlogDump(startPos proto.ReplicationPosition) (
buf, err = sc.Conn.ReadPacket()
if err != nil {
if sqlErr, ok := err.(*sqldb.SqlError); ok && sqlErr.Number() == 2013 {
// errno 2013 = Lost connection to MySQL server during query
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.
log.Infof("connection closed during binlog stream (possibly intentional): %v", err)

Просмотреть файл

@ -78,7 +78,7 @@ func TestConnectivity(t *testing.T) {
newctx, cancel = withTimeout(ctx, 2*time.Millisecond)
_, err = conn.Exec(newctx, "select sleep(1) from dual", 1000, true)
cancel()
lostConn := "error: Lost connection to MySQL server during query (errno 2013) during query: select sleep(1) from dual"
lostConn := "error: the query was killed either because it timed out or was canceled: Lost connection to MySQL server during query (errno 2013) during query: select sleep(1) from dual"
if err == nil || err.Error() != lostConn {
t.Errorf("got: %v, want %s", err, lostConn)
}

Просмотреть файл

@ -111,8 +111,8 @@ func IsConnErr(err error) bool {
return false
}
}
// 2013 means that someone sniped the query.
if sqlError == 2013 {
// ErrServerLost means that someone sniped the query.
if sqlError == mysql.ErrServerLost {
return false
}
return sqlError >= 2000 && sqlError <= 2018
@ -135,6 +135,10 @@ func (te *TabletError) Prefix() string {
case ErrNotInTx:
prefix = "not_in_tx: "
}
// Special case for killed queries.
if te.SqlError == mysql.ErrServerLost {
prefix = prefix + "the query was killed either because it timed out or was canceled: "
}
return prefix
}

Просмотреть файл

@ -46,10 +46,14 @@ func TestTabletErrorConnError(t *testing.T) {
if !IsConnErr(tabletErr) {
t.Fatalf("table error: %v is a connection error", tabletErr)
}
tabletErr = NewTabletErrorSql(ErrFatal, sqldb.NewSqlError(2013, "test"))
tabletErr = NewTabletErrorSql(ErrFatal, sqldb.NewSqlError(mysql.ErrServerLost, "test"))
if IsConnErr(tabletErr) {
t.Fatalf("table error: %v is not a connection error", tabletErr)
}
want := "fatal: the query was killed either because it timed out or was canceled: test (errno 2013)"
if tabletErr.Error() != want {
t.Fatalf("tablet error: %v, want %s", tabletErr, want)
}
sqlErr := sqldb.NewSqlError(1998, "test")
if IsConnErr(sqlErr) {
t.Fatalf("sql error: %v is not a connection error", sqlErr)

Просмотреть файл

@ -367,7 +367,7 @@ class TestNocache(framework.TestCase):
conn.begin()
cu.execute("select sleep(0.5) from vtocc_test", {})
except dbexceptions.DatabaseError as e:
if "error: Query" not in str(e) and "error: Lost connection" not in str(e):
if "error: Query" not in str(e) and "error: the query was killed" not in str(e):
self.fail("Query not killed as expected")
else:
self.fail("Did not receive exception")

Просмотреть файл

@ -112,7 +112,7 @@ class TestStream(framework.TestCase):
thd.join()
with self.assertRaises(dbexceptions.DatabaseError) as cm:
cu.fetchall()
errMsg1 = "error: Lost connection to MySQL server during query (errno 2013)"
errMsg1 = "error: the query was killed either because it timed out or was canceled: Lost connectioy to MySQL server during query (errno 2013)"
errMsg2 = "error: Query execution was interrupted (errno 1317)"
self.assertTrue(cm.exception not in (errMsg1, errMsg2), "did not raise interruption error: %s" % str(cm.exception))
cu.close()