Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vtgate advertised mysql server version to 8.0.31 #11989

Merged
merged 11 commits into from
Feb 3, 2023
Merged
2 changes: 1 addition & 1 deletion go/flags/endtoend/mysqlctl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Global flags:
--logtostderr log to standard error instead of files
--max-stack-size int configure the maximum stack size in bytes (default 67108864)
--mysql_port int MySQL port (default 3306)
--mysql_server_version string MySQL server version to advertise.
--mysql_server_version string MySQL server version to advertise. (default "8.0.31-Vitess")
--mysql_socket string Path to the mysqld socket file
--mysqlctl_client_protocol string the protocol to use to talk to the mysqlctl server (default "grpc")
--mysqlctl_mycnf_template string template file to use for generating the my.cnf file during server init
Expand Down
2 changes: 1 addition & 1 deletion go/flags/endtoend/mysqlctld.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Usage of mysqlctld:
--logtostderr log to standard error instead of files
--max-stack-size int configure the maximum stack size in bytes (default 67108864)
--mysql_port int MySQL port (default 3306)
--mysql_server_version string MySQL server version to advertise.
--mysql_server_version string MySQL server version to advertise. (default "8.0.31-Vitess")
--mysql_socket string Path to the mysqld socket file
--mysqlctl_mycnf_template string template file to use for generating the my.cnf file during server init
--mysqlctl_socket string socket file to use for remote mysqlctl actions (empty for local actions)
Expand Down
2 changes: 1 addition & 1 deletion go/flags/endtoend/vtbackup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Usage of vtbackup:
--mycnf_socket_file string mysql socket file
--mycnf_tmp_dir string mysql tmp directory
--mysql_port int mysql port (default 3306)
--mysql_server_version string MySQL server version to advertise.
--mysql_server_version string MySQL server version to advertise. (default "8.0.31-Vitess")
--mysql_socket string path to the mysql socket
--mysql_timeout duration how long to wait for mysqld startup (default 5m0s)
--port int port for the server
Expand Down
2 changes: 1 addition & 1 deletion go/flags/endtoend/vtctldclient.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Flags:
--log_dir string If non-empty, write log files in this directory
--log_rotate_max_size uint size in bytes at which logs are rotated (glog.MaxSize) (default 1887436800)
--logtostderr log to standard error instead of files
--mysql_server_version string MySQL server version to advertise.
--mysql_server_version string MySQL server version to advertise. (default "8.0.31-Vitess")
--purge_logs_interval duration how often try to remove old logs (default 1h0m0s)
--security_policy string the name of a registered security policy to use for controlling access to URLs - empty means allow all for anyone (built-in policies: deny-all, read-only)
--server string server to use for connection (required)
Expand Down
2 changes: 1 addition & 1 deletion go/flags/endtoend/vtexplain.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Usage of vtexplain:
--log_err_stacks log stack traces for errors
--log_rotate_max_size uint size in bytes at which logs are rotated (glog.MaxSize) (default 1887436800)
--logtostderr log to standard error instead of files
--mysql_server_version string MySQL server version to advertise.
--mysql_server_version string MySQL server version to advertise. (default "8.0.31-Vitess")
--normalize Whether to enable vtgate normalization
--output-mode string Output in human-friendly text or json (default "text")
--planner-version string Sets the query planner version to use when generating the explain output. Valid values are V3 and Gen4
Expand Down
2 changes: 1 addition & 1 deletion go/flags/endtoend/vtgate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Usage of vtgate:
--mysql_server_ssl_key string Path to ssl key for mysql server plugin SSL
--mysql_server_ssl_server_ca string path to server CA in PEM format, which will be combine with server cert, return full certificate chain to clients
--mysql_server_tls_min_version string Configures the minimal TLS version negotiated when SSL is enabled. Defaults to TLSv1.2. Options: TLSv1.0, TLSv1.1, TLSv1.2, TLSv1.3.
--mysql_server_version string MySQL server version to advertise.
--mysql_server_version string MySQL server version to advertise. (default "8.0.31-Vitess")
--mysql_server_write_timeout duration connection write timeout
--mysql_slow_connect_warn_threshold duration Warn if it takes more than the given threshold for a mysql connection to establish
--mysql_tcp_version string Select tcp, tcp4, or tcp6 to control the socket type. (default "tcp")
Expand Down
2 changes: 1 addition & 1 deletion go/flags/endtoend/vttablet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ Usage of vttablet:
--mycnf_slow_log_path string mysql slow query log path
--mycnf_socket_file string mysql socket file
--mycnf_tmp_dir string mysql tmp directory
--mysql_server_version string MySQL server version to advertise.
--mysql_server_version string MySQL server version to advertise. (default "8.0.31-Vitess")
--mysqlctl_mycnf_template string template file to use for generating the my.cnf file during server init
--mysqlctl_socket string socket file to use for remote mysqlctl actions (empty for local actions)
--onclose_timeout duration wait no more than this for OnClose handlers before stopping (default 10s)
Expand Down
2 changes: 1 addition & 1 deletion go/flags/endtoend/vttestserver.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Usage of vttestserver:
--min_table_shard_size int The minimum number of initial rows in a table shard. Ignored if--initialize_with_random_data is false. The actual number is chosen randomly. (default 1000)
--mysql_bind_host string which host to bind vtgate mysql listener to (default "localhost")
--mysql_only If this flag is set only mysql is initialized. The rest of the vitess components are not started. Also, the output specifies the mysql unix socket instead of the vtgate port.
--mysql_server_version string MySQL server version to advertise.
--mysql_server_version string MySQL server version to advertise. (default "8.0.31-Vitess")
--mysqlctl_mycnf_template string template file to use for generating the my.cnf file during server init
--mysqlctl_socket string socket file to use for remote mysqlctl actions (empty for local actions)
--null_probability float The probability to initialize a field with 'NULL' if --initialize_with_random_data is true. Only applies to fields that can contain NULL values. (default 0.1)
Expand Down
9 changes: 1 addition & 8 deletions go/mysql/collations/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,7 @@ func Local() *Environment {
if !flag.Parsed() {
panic("collations.Local() called too early")
}
if mySQLVersion := servenv.MySQLServerVersion(); mySQLVersion == "" {
// The default server version used by vtgate is 5.7.9
// NOTE: this should be changed along with the effective default
// for the vtgate mysql_server_version flag.
defaultEnv = fetchCacheEnvironment(collverMySQL57)
} else {
defaultEnv = NewEnvironment(mySQLVersion)
}
defaultEnv = NewEnvironment(servenv.MySQLServerVersion())
})
return defaultEnv
}
Expand Down
5 changes: 1 addition & 4 deletions go/vt/servenv/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ func (v *versionInfo) String() string {
}

func (v *versionInfo) MySQLVersion() string {
if mySQLServerVersion != "" {
return mySQLServerVersion
}
return "5.7.9-vitess-" + v.version
return mySQLServerVersion
}

func init() {
Expand Down
2 changes: 1 addition & 1 deletion go/vt/servenv/buildinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ func TestVersionString(t *testing.T) {

assert.Equal(t, "Version: v1.2.3-SNAPSHOT (Jenkins build 422) (Git revision d54b87ca0be09b678bb4490060e8f23f890ddb92 branch 'gitBranch') built on time is now by user@host using 1.19.3 amiga/amd64", v.String())

assert.Equal(t, "5.7.9-vitess-v1.2.3-SNAPSHOT", v.MySQLVersion())
assert.Equal(t, "8.0.31-Vitess", v.MySQLVersion())
}
2 changes: 1 addition & 1 deletion go/vt/servenv/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
// mySQLServerVersion is what Vitess will present as it's version during the connection handshake,
// and as the value to the @@version system variable. If nothing is provided, Vitess will report itself as
// a specific MySQL version with the vitess version appended to it
var mySQLServerVersion string
var mySQLServerVersion = "8.0.31-Vitess"

// RegisterMySQLServerFlags installs the flags needed to specify or expose a
// particular MySQL server version from Vitess.
Expand Down
6 changes: 3 additions & 3 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5657,9 +5657,9 @@ partition by range (id)

for _, testcase := range testcases {
t.Run(testcase.input+":"+testcase.mysqlVersion, func(t *testing.T) {
oldMySQLVersion := MySQLVersion
defer func() { MySQLVersion = oldMySQLVersion }()
MySQLVersion = testcase.mysqlVersion
oldMySQLVersion := mySQLParserVersion
defer func() { mySQLParserVersion = oldMySQLVersion }()
mySQLParserVersion = testcase.mysqlVersion
tree, err := Parse(testcase.input)
require.NoError(t, err, testcase.input)
out := String(tree)
Expand Down
36 changes: 22 additions & 14 deletions go/vt/sqlparser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ var parserPool = sync.Pool{
// zeroParser is a zero-initialized parser to help reinitialize the parser for pooling.
var zeroParser yyParserImpl

// MySQLVersion is the version of MySQL that the parser would emulate
var MySQLVersion = "50709" // default version if nothing else is stated
// mySQLParserVersion is the version of MySQL that the parser would emulate
var mySQLParserVersion string

// yyParsePooled is a wrapper around yyParse that pools the parser objects. There isn't a
// particularly good reason to use yyParse directly, since it immediately discards its parser.
Expand Down Expand Up @@ -106,18 +106,26 @@ func Parse2(sql string) (Statement, BindVars, error) {
}

func checkParserVersionFlag() {
if flag.Parsed() {
versionFlagSync.Do(func() {
if mySQLVersion := servenv.MySQLServerVersion(); mySQLVersion != "" {
convVersion, err := convertMySQLVersionToCommentVersion(mySQLVersion)
if err != nil {
log.Error(err)
} else {
MySQLVersion = convVersion
}
}
})
if !flag.Parsed() {
panic("checkParserVersionFlag called too soon")
}
versionFlagSync.Do(func() {
convVersion, err := convertMySQLVersionToCommentVersion(servenv.MySQLServerVersion())
if err != nil {
log.Fatalf("unable to parse mysql version: %v", err)
}
mySQLParserVersion = convVersion
})
}

// SetParserVersion sets the mysql parser version
func SetParserVersion(version string) {
mySQLParserVersion = version
}

// GetParserVersion returns the version of the mysql parser
func GetParserVersion() string {
return mySQLParserVersion
}

// convertMySQLVersionToCommentVersion converts the MySQL version into comment version format.
Expand Down Expand Up @@ -307,5 +315,5 @@ loop:
}

func IsMySQL80AndAbove() bool {
return MySQLVersion >= "80000"
return mySQLParserVersion >= "80000"
}
2 changes: 1 addition & 1 deletion go/vt/sqlparser/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ func (tkn *Tokenizer) scanMySQLSpecificComment() (int, string) {

commentVersion, sql := ExtractMysqlComment(tkn.buf[start:tkn.Pos])

if MySQLVersion >= commentVersion {
if mySQLParserVersion >= commentVersion {
// Only add the special comment to the tokenizer if the version of MySQL is higher or equal to the comment version
tkn.specialComment = NewStringTokenizer(sql)
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/sqlparser/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func TestVersion(t *testing.T) {

for _, tcase := range testcases {
t.Run(tcase.version+"_"+tcase.in, func(t *testing.T) {
MySQLVersion = tcase.version
mySQLParserVersion = tcase.version
tok := NewStringTokenizer(tcase.in)
for _, expectedID := range tcase.id {
id, _ := tok.Scan()
Expand Down
4 changes: 4 additions & 0 deletions go/vt/vtexplain/vtexplain_vttablet.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ func newTabletEnvironment(ddls []sqlparser.DDLStatement, opts *Options) (*tablet
Fields: mysql.BaseShowTablesFields,
Rows: showTableRows,
})
tEnv.addResult(mysql.TablesWithSize80, &sqltypes.Result{
Fields: mysql.BaseShowTablesFields,
Rows: showTableRows,
})

indexRows := make([][]sqltypes.Value, 0, 4)
for _, ddl := range ddls {
Expand Down
6 changes: 3 additions & 3 deletions go/vt/vtgate/engine/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,10 @@ func TestSetTable(t *testing.T) {
tc.input = &SingleRow{}
}

oldMySQLVersion := sqlparser.MySQLVersion
defer func() { sqlparser.MySQLVersion = oldMySQLVersion }()
oldMySQLVersion := sqlparser.GetParserVersion()
defer func() { sqlparser.SetParserVersion(oldMySQLVersion) }()
if tc.mysqlVersion != "" {
sqlparser.MySQLVersion = tc.mysqlVersion
sqlparser.SetParserVersion(tc.mysqlVersion)
}

set := &Set{
Expand Down
8 changes: 4 additions & 4 deletions go/vt/vtgate/executor_select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func TestSystemVariablesMySQLBelow80(t *testing.T) {
executor, sbc1, _, _ := createExecutorEnv()
executor.normalize = true

sqlparser.MySQLVersion = "57000"
sqlparser.SetParserVersion("57000")
setVarEnabled = true

session := NewAutocommitSession(&vtgatepb.Session{EnableSystemSettings: true, TargetString: "TestExecutor"})
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestSystemVariablesWithSetVarDisabled(t *testing.T) {
executor, sbc1, _, _ := createExecutorEnv()
executor.normalize = true

sqlparser.MySQLVersion = "80000"
sqlparser.SetParserVersion("80000")
setVarEnabled = false
defer func() {
setVarEnabled = true
Expand Down Expand Up @@ -235,7 +235,7 @@ func TestSetSystemVariablesTx(t *testing.T) {
executor, sbc1, _, _ := createExecutorEnv()
executor.normalize = true

sqlparser.MySQLVersion = "80001"
sqlparser.SetParserVersion("80001")

session := NewAutocommitSession(&vtgatepb.Session{EnableSystemSettings: true, TargetString: "TestExecutor"})

Expand Down Expand Up @@ -283,7 +283,7 @@ func TestSetSystemVariables(t *testing.T) {
executor, _, _, lookup := createExecutorEnv()
executor.normalize = true

sqlparser.MySQLVersion = "80001"
sqlparser.SetParserVersion("80001")

session := NewAutocommitSession(&vtgatepb.Session{EnableSystemSettings: true, TargetString: KsTestUnsharded, SystemVariables: map[string]string{}})

Expand Down
12 changes: 6 additions & 6 deletions go/vt/vtgate/executor_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,10 @@ func TestSetVar(t *testing.T) {
executor, _, _, sbc := createExecutorEnv()
executor.normalize = true

oldVersion := sqlparser.MySQLVersion
sqlparser.MySQLVersion = "80000"
oldVersion := sqlparser.GetParserVersion()
sqlparser.SetParserVersion("80000")
defer func() {
sqlparser.MySQLVersion = oldVersion
sqlparser.SetParserVersion(oldVersion)
}()
session := NewAutocommitSession(&vtgatepb.Session{EnableSystemSettings: true, TargetString: KsTestUnsharded})

Expand Down Expand Up @@ -580,10 +580,10 @@ func TestSetVarShowVariables(t *testing.T) {
executor, _, _, sbc := createExecutorEnv()
executor.normalize = true

oldVersion := sqlparser.MySQLVersion
sqlparser.MySQLVersion = "80000"
oldVersion := sqlparser.GetParserVersion()
sqlparser.SetParserVersion("80000")
defer func() {
sqlparser.MySQLVersion = oldVersion
sqlparser.SetParserVersion(oldVersion)
}()
session := NewAutocommitSession(&vtgatepb.Session{EnableSystemSettings: true, TargetString: KsTestUnsharded})

Expand Down
4 changes: 1 addition & 3 deletions go/vt/vtgate/plugin_mysql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,7 @@ func initMySQLProtocol() {
if err != nil {
log.Exitf("mysql.NewListener failed: %v", err)
}
if mySQLVersion := servenv.MySQLServerVersion(); mySQLVersion != "" {
mysqlListener.ServerVersion = mySQLVersion
}
mysqlListener.ServerVersion = servenv.MySQLServerVersion()
if mysqlSslCert != "" && mysqlSslKey != "" {
tlsVersion, err := vttls.TLSVersionToNumber(mysqlTLSMinVersion)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vttablet/tabletmanager/tm_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import (
)

var (
dbServerVersion = "5.7.0"
dbServerVersion = "8.0.0"
charsetName = "utf8mb4"
dbsvCollID = collations.NewEnvironment(dbServerVersion).DefaultCollationForCharset(charsetName).ID()
)
Expand Down
5 changes: 1 addition & 4 deletions go/vt/vttest/vtprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,7 @@ func VtcomboProcess(environment Environment, args *Config, mysql MySQLManager) (
if args.VSchemaDDLAuthorizedUsers != "" {
vt.ExtraArgs = append(vt.ExtraArgs, []string{"--vschema_ddl_authorized_users", args.VSchemaDDLAuthorizedUsers}...)
}
if mySQLVersion := servenv.MySQLServerVersion(); mySQLVersion != "" {
vt.ExtraArgs = append(vt.ExtraArgs, "--mysql_server_version", mySQLVersion)
}

vt.ExtraArgs = append(vt.ExtraArgs, "--mysql_server_version", servenv.MySQLServerVersion())
if socket != "" {
vt.ExtraArgs = append(vt.ExtraArgs, []string{
"--db_socket", socket,
Expand Down