diff --git a/go/mysql/auth_server_clientcert_test.go b/go/mysql/auth_server_clientcert_test.go index ca32bbfc7ee..eff92053d94 100644 --- a/go/mysql/auth_server_clientcert_test.go +++ b/go/mysql/auth_server_clientcert_test.go @@ -39,7 +39,7 @@ func TestValidCert(t *testing.T) { authServer := newAuthServerClientCert(string(MysqlClearPassword)) // Create the listener, so we can get its host. - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err, "NewListener failed: %v", err) defer l.Close() host := l.Addr().(*net.TCPAddr).IP.String() @@ -108,7 +108,7 @@ func TestNoCert(t *testing.T) { authServer := newAuthServerClientCert(string(MysqlClearPassword)) // Create the listener, so we can get its host. - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err, "NewListener failed: %v", err) defer l.Close() host := l.Addr().(*net.TCPAddr).IP.String() diff --git a/go/mysql/client_test.go b/go/mysql/client_test.go index 5e9a634c13f..da577e338b2 100644 --- a/go/mysql/client_test.go +++ b/go/mysql/client_test.go @@ -151,7 +151,7 @@ func TestTLSClientDisabled(t *testing.T) { // Below, we are enabling --ssl-verify-server-cert, which adds // a check that the common name of the certificate matches the // server host name we connect to. - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err) defer l.Close() @@ -223,7 +223,7 @@ func TestTLSClientPreferredDefault(t *testing.T) { // Below, we are enabling --ssl-verify-server-cert, which adds // a check that the common name of the certificate matches the // server host name we connect to. - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err) defer l.Close() @@ -296,7 +296,7 @@ func TestTLSClientRequired(t *testing.T) { // Below, we are enabling --ssl-verify-server-cert, which adds // a check that the common name of the certificate matches the // server host name we connect to. - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err) defer l.Close() @@ -343,7 +343,7 @@ func TestTLSClientVerifyCA(t *testing.T) { // Below, we are enabling --ssl-verify-server-cert, which adds // a check that the common name of the certificate matches the // server host name we connect to. - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err) defer l.Close() @@ -426,7 +426,7 @@ func TestTLSClientVerifyIdentity(t *testing.T) { // Below, we are enabling --ssl-verify-server-cert, which adds // a check that the common name of the certificate matches the // server host name we connect to. - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err) defer l.Close() diff --git a/go/mysql/conn.go b/go/mysql/conn.go index 6f788db33d5..925dfbfa8e4 100644 --- a/go/mysql/conn.go +++ b/go/mysql/conn.go @@ -1236,7 +1236,7 @@ func (c *Conn) handleComPrepare(handler Handler, data []byte) (kontinue bool) { var queries []string if c.Capabilities&CapabilityClientMultiStatements != 0 { var err error - queries, err = handler.SQLParser().SplitStatementToPieces(query) + queries, err = handler.Env().Parser().SplitStatementToPieces(query) if err != nil { log.Errorf("Conn %v: Error splitting query: %v", c, err) return c.writeErrorPacketFromErrorAndLog(err) @@ -1256,7 +1256,7 @@ func (c *Conn) handleComPrepare(handler Handler, data []byte) (kontinue bool) { PrepareStmt: queries[0], } - statement, err := handler.SQLParser().ParseStrictDDL(query) + statement, err := handler.Env().Parser().ParseStrictDDL(query) if err != nil { log.Errorf("Conn %v: Error parsing prepared statement: %v", c, err) if !c.writeErrorPacketFromErrorAndLog(err) { @@ -1364,7 +1364,7 @@ func (c *Conn) handleComQuery(handler Handler, data []byte) (kontinue bool) { var queries []string var err error if c.Capabilities&CapabilityClientMultiStatements != 0 { - queries, err = handler.SQLParser().SplitStatementToPieces(query) + queries, err = handler.Env().Parser().SplitStatementToPieces(query) if err != nil { log.Errorf("Conn %v: Error splitting query: %v", c, err) return c.writeErrorPacketFromErrorAndLog(err) diff --git a/go/mysql/conn_test.go b/go/mysql/conn_test.go index 65fbd659f77..69ba1fa5e0c 100644 --- a/go/mysql/conn_test.go +++ b/go/mysql/conn_test.go @@ -39,7 +39,7 @@ import ( "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/test/utils" querypb "vitess.io/vitess/go/vt/proto/query" - "vitess.io/vitess/go/vt/sqlparser" + "vitess.io/vitess/go/vt/vtenv" ) func createSocketPair(t *testing.T) (net.Listener, *Conn, *Conn) { @@ -1141,8 +1141,8 @@ func (t testRun) WarningCount(c *Conn) uint16 { return 0 } -func (t testRun) SQLParser() *sqlparser.Parser { - return sqlparser.NewTestParser() +func (t testRun) Env() *vtenv.Environment { + return vtenv.NewTestEnv() } var _ Handler = (*testRun)(nil) diff --git a/go/mysql/fakesqldb/server.go b/go/mysql/fakesqldb/server.go index 3eb169b13ab..09f0c42942e 100644 --- a/go/mysql/fakesqldb/server.go +++ b/go/mysql/fakesqldb/server.go @@ -30,12 +30,12 @@ import ( "time" "vitess.io/vitess/go/mysql" - "vitess.io/vitess/go/mysql/config" "vitess.io/vitess/go/mysql/replication" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/log" querypb "vitess.io/vitess/go/vt/proto/query" "vitess.io/vitess/go/vt/sqlparser" + "vitess.io/vitess/go/vt/vtenv" ) const appendEntry = -1 @@ -127,7 +127,7 @@ type DB struct { lastErrorMu sync.Mutex lastError error - parser *sqlparser.Parser + env *vtenv.Environment } // QueryHandler is the interface used by the DB to simulate executed queries @@ -181,7 +181,7 @@ func New(t testing.TB) *DB { queryPatternUserCallback: make(map[*regexp.Regexp]func(string)), patternData: make(map[string]exprResult), lastErrorMu: sync.Mutex{}, - parser: sqlparser.NewTestParser(), + env: vtenv.NewTestEnv(), } db.Handler = db @@ -189,7 +189,7 @@ func New(t testing.TB) *DB { authServer := mysql.NewAuthServerNone() // Start listening. - db.listener, err = mysql.NewListener("unix", socketFile, authServer, db, 0, 0, false, false, 0, 0, fmt.Sprintf("%s-Vitess", config.DefaultMySQLVersion), 0) + db.listener, err = mysql.NewListener("unix", socketFile, authServer, db, 0, 0, false, false, 0, 0) if err != nil { t.Fatalf("NewListener failed: %v", err) } @@ -845,6 +845,6 @@ func (db *DB) GetQueryPatternResult(key string) (func(string), ExpectedResult, b return nil, ExpectedResult{nil, nil}, false, nil } -func (db *DB) SQLParser() *sqlparser.Parser { - return db.parser +func (db *DB) Env() *vtenv.Environment { + return db.env } diff --git a/go/mysql/handshake_test.go b/go/mysql/handshake_test.go index db65012268a..284189c30e8 100644 --- a/go/mysql/handshake_test.go +++ b/go/mysql/handshake_test.go @@ -27,6 +27,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "vitess.io/vitess/go/mysql/collations" "vitess.io/vitess/go/test/utils" "vitess.io/vitess/go/vt/tlstest" @@ -45,7 +46,7 @@ func TestClearTextClientAuth(t *testing.T) { defer authServer.close() // Create the listener. - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err, "NewListener failed: %v", err) defer l.Close() host := l.Addr().(*net.TCPAddr).IP.String() @@ -77,6 +78,7 @@ func TestClearTextClientAuth(t *testing.T) { defer conn.Close() + assert.Equal(t, collations.ID(collations.CollationUtf8mb4ID), conn.CharacterSet) // Run a 'select rows' command with results. result, err := conn.ExecuteFetch("select rows", 10000, true) require.NoError(t, err, "ExecuteFetch failed: %v", err) @@ -99,7 +101,7 @@ func TestSSLConnection(t *testing.T) { defer authServer.close() // Create the listener, so we can get its host. - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err, "NewListener failed: %v", err) defer l.Close() host := l.Addr().(*net.TCPAddr).IP.String() @@ -176,6 +178,7 @@ func testSSLConnectionBasics(t *testing.T, params *ConnParams) { defer conn.Close() assert.Equal(t, "user1", conn.User, "Invalid conn.User, got %v was expecting user1", conn.User) + assert.Equal(t, collations.ID(collations.CollationUtf8mb4ID), conn.CharacterSet) // Run a 'select rows' command with results. result, err := conn.ExecuteFetch("select rows", 10000, true) diff --git a/go/mysql/server.go b/go/mysql/server.go index ddc9fe06ff6..e21281710b7 100644 --- a/go/mysql/server.go +++ b/go/mysql/server.go @@ -38,7 +38,7 @@ import ( "vitess.io/vitess/go/vt/log" querypb "vitess.io/vitess/go/vt/proto/query" "vitess.io/vitess/go/vt/proto/vtrpc" - "vitess.io/vitess/go/vt/sqlparser" + "vitess.io/vitess/go/vt/vtenv" "vitess.io/vitess/go/vt/vterrors" ) @@ -133,7 +133,7 @@ type Handler interface { ComResetConnection(c *Conn) - SQLParser() *sqlparser.Parser + Env() *vtenv.Environment } // UnimplementedHandler implemnts all of the optional callbacks so as to satisy @@ -233,9 +233,6 @@ func NewFromListener( connBufferPooling bool, keepAlivePeriod time.Duration, flushDelay time.Duration, - mysqlServerVersion string, - truncateErrLen int, - ) (*Listener, error) { cfg := ListenerConfig{ Listener: l, @@ -247,8 +244,6 @@ func NewFromListener( ConnBufferPooling: connBufferPooling, ConnKeepAlivePeriod: keepAlivePeriod, FlushDelay: flushDelay, - MySQLServerVersion: mysqlServerVersion, - TruncateErrLen: truncateErrLen, } return NewListenerWithConfig(cfg) } @@ -264,8 +259,6 @@ func NewListener( connBufferPooling bool, keepAlivePeriod time.Duration, flushDelay time.Duration, - mysqlServerVersion string, - truncateErrLen int, ) (*Listener, error) { listener, err := net.Listen(protocol, address) if err != nil { @@ -273,10 +266,10 @@ func NewListener( } if proxyProtocol { proxyListener := &proxyproto.Listener{Listener: listener} - return NewFromListener(proxyListener, authServer, handler, connReadTimeout, connWriteTimeout, connBufferPooling, keepAlivePeriod, flushDelay, mysqlServerVersion, truncateErrLen) + return NewFromListener(proxyListener, authServer, handler, connReadTimeout, connWriteTimeout, connBufferPooling, keepAlivePeriod, flushDelay) } - return NewFromListener(listener, authServer, handler, connReadTimeout, connWriteTimeout, connBufferPooling, keepAlivePeriod, flushDelay, mysqlServerVersion, truncateErrLen) + return NewFromListener(listener, authServer, handler, connReadTimeout, connWriteTimeout, connBufferPooling, keepAlivePeriod, flushDelay) } // ListenerConfig should be used with NewListenerWithConfig to specify listener parameters. @@ -293,8 +286,6 @@ type ListenerConfig struct { ConnBufferPooling bool ConnKeepAlivePeriod time.Duration FlushDelay time.Duration - MySQLServerVersion string - TruncateErrLen int } // NewListenerWithConfig creates new listener using provided config. There are @@ -315,7 +306,7 @@ func NewListenerWithConfig(cfg ListenerConfig) (*Listener, error) { authServer: cfg.AuthServer, handler: cfg.Handler, listener: l, - ServerVersion: cfg.MySQLServerVersion, + ServerVersion: cfg.Handler.Env().MySQLVersion(), connectionID: 1, connReadTimeout: cfg.ConnReadTimeout, connWriteTimeout: cfg.ConnWriteTimeout, @@ -323,7 +314,8 @@ func NewListenerWithConfig(cfg ListenerConfig) (*Listener, error) { connBufferPooling: cfg.ConnBufferPooling, connKeepAlivePeriod: cfg.ConnKeepAlivePeriod, flushDelay: cfg.FlushDelay, - truncateErrLen: cfg.TruncateErrLen, + truncateErrLen: cfg.Handler.Env().TruncateErrLen(), + charset: cfg.Handler.Env().CollationEnv().DefaultConnectionCharset(), }, nil } diff --git a/go/mysql/server_test.go b/go/mysql/server_test.go index 1b6e11b74aa..082a176e3af 100644 --- a/go/mysql/server_test.go +++ b/go/mysql/server_test.go @@ -33,14 +33,13 @@ import ( "github.com/stretchr/testify/require" "vitess.io/vitess/go/mysql/collations" - "vitess.io/vitess/go/mysql/config" "vitess.io/vitess/go/mysql/replication" "vitess.io/vitess/go/mysql/sqlerror" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/test/utils" - vtenv "vitess.io/vitess/go/vt/env" - "vitess.io/vitess/go/vt/sqlparser" + venv "vitess.io/vitess/go/vt/env" "vitess.io/vitess/go/vt/tlstest" + "vitess.io/vitess/go/vt/vtenv" "vitess.io/vitess/go/vt/vterrors" "vitess.io/vitess/go/vt/vttls" @@ -81,7 +80,6 @@ type testHandler struct { result *sqltypes.Result err error warnings uint16 - parser *sqlparser.Parser } func (th *testHandler) LastConn() *Conn { @@ -257,8 +255,8 @@ func (th *testHandler) WarningCount(c *Conn) uint16 { return th.warnings } -func (th *testHandler) SQLParser() *sqlparser.Parser { - return th.parser +func (th *testHandler) Env() *vtenv.Environment { + return vtenv.NewTestEnv() } func getHostPort(t *testing.T, a net.Addr) (string, int) { @@ -268,8 +266,6 @@ func getHostPort(t *testing.T, a net.Addr) (string, int) { return host, port } -var mysqlVersion = fmt.Sprintf("%s-Vitess", config.DefaultMySQLVersion) - func TestConnectionFromListener(t *testing.T) { th := &testHandler{} @@ -284,7 +280,7 @@ func TestConnectionFromListener(t *testing.T) { listener, err := net.Listen("tcp", "127.0.0.1:") require.NoError(t, err, "net.Listener failed") - l, err := NewFromListener(listener, authServer, th, 0, 0, false, 0, 0, mysqlVersion, 0) + l, err := NewFromListener(listener, authServer, th, 0, 0, false, 0, 0) require.NoError(t, err, "NewListener failed") defer l.Close() go l.Accept() @@ -313,7 +309,7 @@ func TestConnectionWithoutSourceHost(t *testing.T) { UserData: "userData1", }} defer authServer.close() - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err, "NewListener failed") defer l.Close() go l.Accept() @@ -346,7 +342,7 @@ func TestConnectionWithSourceHost(t *testing.T) { } defer authServer.close() - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err, "NewListener failed") defer l.Close() go l.Accept() @@ -379,7 +375,7 @@ func TestConnectionUseMysqlNativePasswordWithSourceHost(t *testing.T) { } defer authServer.close() - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err, "NewListener failed") defer l.Close() go l.Accept() @@ -417,7 +413,7 @@ func TestConnectionUnixSocket(t *testing.T) { os.Remove(unixSocket.Name()) - l, err := NewListener("unix", unixSocket.Name(), authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("unix", unixSocket.Name(), authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err, "NewListener failed") defer l.Close() go l.Accept() @@ -443,7 +439,7 @@ func TestClientFoundRows(t *testing.T) { UserData: "userData1", }} defer authServer.close() - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err, "NewListener failed") defer l.Close() go l.Accept() @@ -487,7 +483,7 @@ func TestConnCounts(t *testing.T) { UserData: "userData1", }} defer authServer.close() - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err, "NewListener failed") defer l.Close() go l.Accept() @@ -541,7 +537,7 @@ func TestServer(t *testing.T) { UserData: "userData1", }} defer authServer.close() - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err) l.SlowConnectWarnThreshold.Store(time.Nanosecond.Nanoseconds()) defer l.Close() @@ -641,7 +637,7 @@ func TestServerStats(t *testing.T) { UserData: "userData1", }} defer authServer.close() - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err) l.SlowConnectWarnThreshold.Store(time.Nanosecond.Nanoseconds()) defer l.Close() @@ -715,7 +711,7 @@ func TestClearTextServer(t *testing.T) { UserData: "userData1", }} defer authServer.close() - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err) defer l.Close() go l.Accept() @@ -788,7 +784,7 @@ func TestDialogServer(t *testing.T) { UserData: "userData1", }} defer authServer.close() - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err) l.AllowClearTextWithoutTLS.Store(true) defer l.Close() @@ -831,7 +827,7 @@ func TestTLSServer(t *testing.T) { // Below, we are enabling --ssl-verify-server-cert, which adds // a check that the common name of the certificate matches the // server host name we connect to. - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err) defer l.Close() @@ -929,7 +925,7 @@ func TestTLSRequired(t *testing.T) { // Below, we are enabling --ssl-verify-server-cert, which adds // a check that the common name of the certificate matches the // server host name we connect to. - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err) defer l.Close() @@ -1018,7 +1014,7 @@ func TestCachingSha2PasswordAuthWithTLS(t *testing.T) { defer authServer.close() // Create the listener, so we can get its host. - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err, "NewListener failed: %v", err) defer l.Close() host := l.Addr().(*net.TCPAddr).IP.String() @@ -1112,7 +1108,7 @@ func TestCachingSha2PasswordAuthWithMoreData(t *testing.T) { defer authServer.close() // Create the listener, so we can get its host. - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err, "NewListener failed: %v", err) defer l.Close() host := l.Addr().(*net.TCPAddr).IP.String() @@ -1181,7 +1177,7 @@ func TestCachingSha2PasswordAuthWithoutTLS(t *testing.T) { defer authServer.close() // Create the listener. - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err, "NewListener failed: %v", err) defer l.Close() host := l.Addr().(*net.TCPAddr).IP.String() @@ -1223,7 +1219,7 @@ func TestErrorCodes(t *testing.T) { UserData: "userData1", }} defer authServer.close() - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err) defer l.Close() go l.Accept() @@ -1317,7 +1313,7 @@ func runMysql(t *testing.T, params *ConnParams, command string) (string, bool) { } func runMysqlWithErr(t *testing.T, params *ConnParams, command string) (string, error) { - dir, err := vtenv.VtMysqlRoot() + dir, err := venv.VtMysqlRoot() require.NoError(t, err) name, err := binaryPath(dir, "mysql") require.NoError(t, err) @@ -1401,7 +1397,7 @@ func TestListenerShutdown(t *testing.T) { UserData: "userData1", }} defer authServer.close() - l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", authServer, th, 0, 0, false, false, 0, 0) require.NoError(t, err) defer l.Close() go l.Accept() @@ -1472,7 +1468,7 @@ func TestServerFlush(t *testing.T) { mysqlServerFlushDelay := 10 * time.Millisecond th := &testHandler{} - l, err := NewListener("tcp", "127.0.0.1:", NewAuthServerNone(), th, 0, 0, false, false, 0, mysqlServerFlushDelay, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", NewAuthServerNone(), th, 0, 0, false, false, 0, mysqlServerFlushDelay) require.NoError(t, err) defer l.Close() go l.Accept() @@ -1518,7 +1514,7 @@ func TestServerFlush(t *testing.T) { func TestTcpKeepAlive(t *testing.T) { th := &testHandler{} - l, err := NewListener("tcp", "127.0.0.1:", NewAuthServerNone(), th, 0, 0, false, false, 0, 0, mysqlVersion, 0) + l, err := NewListener("tcp", "127.0.0.1:", NewAuthServerNone(), th, 0, 0, false, false, 0, 0) require.NoError(t, err) defer l.Close() go l.Accept() diff --git a/go/vt/vtenv/vtenv.go b/go/vt/vtenv/vtenv.go index 71bf089cf24..1371affff52 100644 --- a/go/vt/vtenv/vtenv.go +++ b/go/vt/vtenv/vtenv.go @@ -91,3 +91,7 @@ func (e *Environment) TruncateForUI(query string) string { func (e *Environment) TruncateForLog(query string) string { return sqlparser.TruncateQuery(query, e.truncateErrLen) } + +func (e *Environment) TruncateErrLen() int { + return e.truncateErrLen +} diff --git a/go/vt/vtgate/plugin_mysql_server.go b/go/vt/vtgate/plugin_mysql_server.go index 465def6e9a7..c0b2fe38b56 100644 --- a/go/vt/vtgate/plugin_mysql_server.go +++ b/go/vt/vtgate/plugin_mysql_server.go @@ -45,6 +45,7 @@ import ( vtgatepb "vitess.io/vitess/go/vt/proto/vtgate" "vitess.io/vitess/go/vt/servenv" "vitess.io/vitess/go/vt/sqlparser" + "vitess.io/vitess/go/vt/vtenv" "vitess.io/vitess/go/vt/vterrors" "vitess.io/vitess/go/vt/vttls" ) @@ -420,8 +421,8 @@ func (vh *vtgateHandler) KillQuery(connectionID uint32) error { return nil } -func (vh *vtgateHandler) SQLParser() *sqlparser.Parser { - return vh.vtg.executor.env.Parser() +func (vh *vtgateHandler) Env() *vtenv.Environment { + return vh.vtg.executor.env } func (vh *vtgateHandler) session(c *mysql.Conn) *vtgatepb.Session { @@ -534,8 +535,6 @@ func initMySQLProtocol(vtgate *VTGate) *mysqlServer { mysqlConnBufferPooling, mysqlKeepAlivePeriod, mysqlServerFlushDelay, - servenv.MySQLServerVersion(), - servenv.TruncateErrLen, ) if err != nil { log.Exitf("mysql.NewListener failed: %v", err) @@ -581,8 +580,6 @@ func newMysqlUnixSocket(address string, authServer mysql.AuthServer, handler mys mysqlConnBufferPooling, mysqlKeepAlivePeriod, mysqlServerFlushDelay, - servenv.MySQLServerVersion(), - servenv.TruncateErrLen, ) switch err := err.(type) { @@ -616,8 +613,6 @@ func newMysqlUnixSocket(address string, authServer mysql.AuthServer, handler mys mysqlConnBufferPooling, mysqlKeepAlivePeriod, mysqlServerFlushDelay, - servenv.MySQLServerVersion(), - servenv.TruncateErrLen, ) return listener, listenerErr default: diff --git a/go/vt/vtgate/plugin_mysql_server_test.go b/go/vt/vtgate/plugin_mysql_server_test.go index 89786766e2f..5da79b9fe17 100644 --- a/go/vt/vtgate/plugin_mysql_server_test.go +++ b/go/vt/vtgate/plugin_mysql_server_test.go @@ -36,14 +36,13 @@ import ( "vitess.io/vitess/go/test/utils" "vitess.io/vitess/go/trace" querypb "vitess.io/vitess/go/vt/proto/query" - "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/tlstest" + "vitess.io/vitess/go/vt/vtenv" ) type testHandler struct { mysql.UnimplementedHandler lastConn *mysql.Conn - parser *sqlparser.Parser } func (th *testHandler) NewConnection(c *mysql.Conn) { @@ -83,8 +82,8 @@ func (th *testHandler) WarningCount(c *mysql.Conn) uint16 { return 0 } -func (th *testHandler) SQLParser() *sqlparser.Parser { - return th.parser +func (th *testHandler) Env() *vtenv.Environment { + return vtenv.NewTestEnv() } func TestConnectionUnixSocket(t *testing.T) { @@ -352,7 +351,7 @@ func TestGracefulShutdown(t *testing.T) { vh := newVtgateHandler(&VTGate{executor: executor, timings: timings, rowsReturned: rowsReturned, rowsAffected: rowsAffected}) th := &testHandler{} - listener, err := mysql.NewListener("tcp", "127.0.0.1:", mysql.NewAuthServerNone(), th, 0, 0, false, false, 0, 0, "8.0.30-Vitess", 0) + listener, err := mysql.NewListener("tcp", "127.0.0.1:", mysql.NewAuthServerNone(), th, 0, 0, false, false, 0, 0) require.NoError(t, err) defer listener.Close() @@ -382,7 +381,7 @@ func TestGracefulShutdownWithTransaction(t *testing.T) { vh := newVtgateHandler(&VTGate{executor: executor, timings: timings, rowsReturned: rowsReturned, rowsAffected: rowsAffected}) th := &testHandler{} - listener, err := mysql.NewListener("tcp", "127.0.0.1:", mysql.NewAuthServerNone(), th, 0, 0, false, false, 0, 0, "8.0.30-Vitess", 0) + listener, err := mysql.NewListener("tcp", "127.0.0.1:", mysql.NewAuthServerNone(), th, 0, 0, false, false, 0, 0) require.NoError(t, err) defer listener.Close()