Switching to new mysqlconn by default for all.

This is just to make sure all tests pass.
This is based on the other branch.
This commit is contained in:
Alain Jobart 2017-01-30 13:25:01 -08:00
Родитель 82e3a37fe1
Коммит fb628e54db
6 изменённых файлов: 16 добавлений и 17 удалений

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

@ -45,10 +45,6 @@ func init() {
// This needs to be called before threads begin to spawn.
C.vt_library_init()
sqldb.Register("libmysqlclient", Connect)
// Comment this out and uncomment call to sqldb.RegisterDefault in
// go/mysqlconn/sqldb_conn.go to make it the default.
sqldb.RegisterDefault(Connect)
}
func handleError(err *error) {
@ -65,6 +61,11 @@ type Connection struct {
// Connect uses the connection parameters to connect and returns the connection
func Connect(params sqldb.ConnParams) (sqldb.Conn, error) {
// FIXME(alainjobart) adding a panic to make sure this library is
// unused. Before the defer on purpose, so it actually panics.
if true {
panic("Added to make sure this library is unused.")
}
var err error
defer handleError(&err)

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

@ -179,12 +179,8 @@ func init() {
ctx := context.Background()
return Connect(ctx, &params)
})
// Uncomment this and comment out the call to sqldb.RegisterDefault in
// go/mysql/mysql.go to make this the default.
// sqldb.RegisterDefault(func(params sqldb.ConnParams) (sqldb.Conn, error) {
// ctx := context.Background()
// return Connect(ctx, &params)
// })
sqldb.RegisterDefault(func(params sqldb.ConnParams) (sqldb.Conn, error) {
ctx := context.Background()
return Connect(ctx, &params)
})
}

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

@ -58,7 +58,7 @@ const redactedPassword = "****"
// The flags will change the global singleton
func registerConnFlags(connParams *sqldb.ConnParams, name string) {
flag.StringVar(&connParams.Engine, "db-config-"+name+"-engine", "libmysqlclient", "db "+name+" engine to use (empty for default, libmysqlclient or mysqlconn)")
flag.StringVar(&connParams.Engine, "db-config-"+name+"-engine", "mysqlconn", "db "+name+" engine to use (empty for default, libmysqlclient or mysqlconn)")
flag.StringVar(&connParams.Host, "db-config-"+name+"-host", "", "db "+name+" connection host")
flag.IntVar(&connParams.Port, "db-config-"+name+"-port", 0, "db "+name+" connection port")
flag.StringVar(&connParams.Uname, "db-config-"+name+"-uname", "", "db "+name+" connection uname")

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

@ -92,7 +92,7 @@ func TestDBConnKill(t *testing.T) {
// Kill failed because we are not able to connect to the database
db.EnableConnFail()
err = dbConn.Kill("test kill")
want := "Lost connection"
want := "errno 2013"
if err == nil || !strings.Contains(err.Error(), want) {
t.Errorf("Exec: %v, want %s", err, want)
}

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

@ -240,7 +240,7 @@ func TestTxPoolBeginWithPoolConnectionError_Errno2006_Permanent(t *testing.T) {
// DBConn.Exec() will return the reconnect error as final error and not the
// initial connection error.
_, err = txPool.LocalBegin(context.Background(), false)
if err == nil || !strings.Contains(err.Error(), "Lost connection to MySQL server") || !strings.Contains(err.Error(), "(errno 2013)") {
if err == nil || !strings.Contains(err.Error(), "(errno 2013)") {
t.Fatalf("Begin did not return the reconnect error: %v", err)
}
sqlErr, ok := err.(*sqldb.SQLError)
@ -433,6 +433,8 @@ func TestTxPoolExecFailDueToConnFail_Errno2013(t *testing.T) {
}
func TestTxPoolCloseKillsStrayTransactions(t *testing.T) {
before := tabletenv.InternalErrors.Counts()["StrayTransactions"]
db := fakesqldb.New(t)
defer db.Close()
db.AddQuery("begin", &sqltypes.Result{})
@ -448,7 +450,7 @@ func TestTxPoolCloseKillsStrayTransactions(t *testing.T) {
// Close kills stray transaction.
txPool.Close()
if got, want := tabletenv.InternalErrors.Counts()["StrayTransactions"], int64(1); got != want {
if got, want := tabletenv.InternalErrors.Counts()["StrayTransactions"]-before, int64(1); got != want {
t.Fatalf("internal error count for stray transactions not increased: got = %v, want = %v", got, want)
}
if got, want := txPool.conns.Capacity(), int64(0); got != want {

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

@ -30,7 +30,7 @@ import (
// FIXME(alainjobart) remove this when it's the only option.
// Registers our implementation.
_ "github.com/youtube/vitess/go/mysql"
_ "github.com/youtube/vitess/go/mysqlconn"
topodatapb "github.com/youtube/vitess/go/vt/proto/topodata"
vschemapb "github.com/youtube/vitess/go/vt/proto/vschema"