Skip to content

Commit

Permalink
Refactor out more usage of servenv for mysql version (#14938)
Browse files Browse the repository at this point in the history
Signed-off-by: Dirkjan Bussink <[email protected]>
  • Loading branch information
dbussink authored Jan 15, 2024
1 parent 42afc72 commit ca4246d
Show file tree
Hide file tree
Showing 182 changed files with 1,114 additions and 877 deletions.
7 changes: 4 additions & 3 deletions go/cmd/vtadmin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,11 @@ func run(cmd *cobra.Command, args []string) {
log.Warningf("no cache-refresh-key set; forcing cache refreshes will not be possible")
}
cache.SetCacheRefreshKey(cacheRefreshKey)
collationEnv := collations.NewEnvironment(servenv.MySQLServerVersion())
mysqlServerVersion := servenv.MySQLServerVersion()
collationEnv := collations.NewEnvironment(mysqlServerVersion)

parser, err := sqlparser.New(sqlparser.Options{
MySQLServerVersion: servenv.MySQLServerVersion(),
MySQLServerVersion: mysqlServerVersion,
TruncateUILen: servenv.TruncateUILen,
TruncateErrLen: servenv.TruncateErrLen,
})
Expand All @@ -154,7 +155,7 @@ func run(cmd *cobra.Command, args []string) {
HTTPOpts: httpOpts,
RBAC: rbacConfig,
EnableDynamicClusters: enableDynamicClusters,
}, collationEnv, parser)
}, collationEnv, parser, mysqlServerVersion)
bootSpan.Finish()

if err := s.ListenAndServe(); err != nil {
Expand Down
14 changes: 8 additions & 6 deletions go/cmd/vtcombo/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ In particular, it contains:
collationEnv *collations.Environment
resilientServer *srvtopo.ResilientServer
parser *sqlparser.Parser
mysqlVersion string
)

func init() {
Expand Down Expand Up @@ -192,8 +193,9 @@ func run(cmd *cobra.Command, args []string) (err error) {
servenv.Init()
tabletenv.Init()

mysqlVersion = servenv.MySQLServerVersion()
parser, err = sqlparser.New(sqlparser.Options{
MySQLServerVersion: servenv.MySQLServerVersion(),
MySQLServerVersion: mysqlVersion,
TruncateUILen: servenv.TruncateUILen,
TruncateErrLen: servenv.TruncateErrLen,
})
Expand Down Expand Up @@ -232,7 +234,7 @@ func run(cmd *cobra.Command, args []string) (err error) {
// to be the "internal" protocol that InitTabletMap registers.
cmd.Flags().Set("tablet_manager_protocol", "internal")
cmd.Flags().Set("tablet_protocol", "internal")
uid, err := vtcombo.InitTabletMap(ts, &tpb, mysqld, &dbconfigs.GlobalDBConfigs, schemaDir, startMysql, collationEnv, parser)
uid, err := vtcombo.InitTabletMap(ts, &tpb, mysqld, &dbconfigs.GlobalDBConfigs, schemaDir, startMysql, collationEnv, parser, mysqlVersion)
if err != nil {
// ensure we start mysql in the event we fail here
if startMysql {
Expand All @@ -257,8 +259,8 @@ func run(cmd *cobra.Command, args []string) (err error) {
}
}

wr := wrangler.New(logutil.NewConsoleLogger(), ts, nil, collationEnv, parser)
newUID, err := vtcombo.CreateKs(ctx, ts, &tpb, mysqld, &dbconfigs.GlobalDBConfigs, schemaDir, ks, true, uid, wr, collationEnv, parser)
wr := wrangler.New(logutil.NewConsoleLogger(), ts, nil, collationEnv, parser, mysqlVersion)
newUID, err := vtcombo.CreateKs(ctx, ts, &tpb, mysqld, &dbconfigs.GlobalDBConfigs, schemaDir, ks, true, uid, wr, collationEnv, parser, mysqlVersion)
if err != nil {
return err
}
Expand Down Expand Up @@ -308,10 +310,10 @@ func run(cmd *cobra.Command, args []string) (err error) {
vtgate.QueryzHandler = "/debug/vtgate/queryz"

// pass nil for healthcheck, it will get created
vtg := vtgate.Init(context.Background(), nil, resilientServer, tpb.Cells[0], tabletTypesToWait, plannerVersion, collationEnv)
vtg := vtgate.Init(context.Background(), nil, resilientServer, tpb.Cells[0], tabletTypesToWait, plannerVersion, collationEnv, mysqlVersion)

// vtctld configuration and init
err = vtctld.InitVtctld(ts, collationEnv, parser)
err = vtctld.InitVtctld(ts, collationEnv, parser, mysqlVersion)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion go/cmd/vtcombo/cli/plugin_grpcvtctldserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
func init() {
servenv.OnRun(func() {
if servenv.GRPCCheckServiceMap("vtctld") {
grpcvtctldserver.StartServer(servenv.GRPCServer, ts, collationEnv, parser)
grpcvtctldserver.StartServer(servenv.GRPCServer, ts, collationEnv, parser, mysqlVersion)
}
})
}
2 changes: 1 addition & 1 deletion go/cmd/vtcombo/cli/plugin_grpcvtctlserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
func init() {
servenv.OnRun(func() {
if servenv.GRPCCheckServiceMap("vtctl") {
grpcvtctlserver.StartServer(servenv.GRPCServer, ts, collationEnv, parser)
grpcvtctlserver.StartServer(servenv.GRPCServer, ts, collationEnv, parser, mysqlVersion)
}
})
}
9 changes: 5 additions & 4 deletions go/cmd/vtctl/vtctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ func main() {
ctx, cancel := context.WithTimeout(context.Background(), waitTime)
installSignalHandlers(cancel)

collationEnv := collations.NewEnvironment(servenv.MySQLServerVersion())
mysqlVersion := servenv.MySQLServerVersion()
collationEnv := collations.NewEnvironment(mysqlVersion)

parser, err := sqlparser.New(sqlparser.Options{
MySQLServerVersion: servenv.MySQLServerVersion(),
MySQLServerVersion: mysqlVersion,
TruncateUILen: servenv.TruncateUILen,
TruncateErrLen: servenv.TruncateErrLen,
})
Expand Down Expand Up @@ -166,7 +167,7 @@ func main() {
// New behavior. Strip off the prefix, and set things up to run through
// the vtctldclient command tree, using the localvtctldclient (in-process)
// client.
vtctld := grpcvtctldserver.NewVtctldServer(ts, collationEnv, parser)
vtctld := grpcvtctldserver.NewVtctldServer(ts, collationEnv, parser, mysqlVersion)
localvtctldclient.SetServer(vtctld)
command.VtctldClientProtocol = "local"

Expand All @@ -182,7 +183,7 @@ func main() {
fallthrough
default:
log.Warningf("WARNING: vtctl should only be used for VDiff v1 workflows. Please use VDiff v2 and consider using vtctldclient for all other commands.")
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), collationEnv, parser)
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), collationEnv, parser, mysqlVersion)

if args[0] == "--" {
vtctl.PrintDoubleDashDeprecationNotice(wr)
Expand Down
8 changes: 5 additions & 3 deletions go/cmd/vtctld/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
ts *topo.Server
collationEnv *collations.Environment
parser *sqlparser.Parser
mysqlVersion string
Main = &cobra.Command{
Use: "vtctld",
Short: "The Vitess cluster management daemon.",
Expand Down Expand Up @@ -65,17 +66,18 @@ func run(cmd *cobra.Command, args []string) error {
defer ts.Close()

var err error
collationEnv = collations.NewEnvironment(servenv.MySQLServerVersion())
mysqlVersion = servenv.MySQLServerVersion()
collationEnv = collations.NewEnvironment(mysqlVersion)
parser, err = sqlparser.New(sqlparser.Options{
MySQLServerVersion: servenv.MySQLServerVersion(),
MySQLServerVersion: mysqlVersion,
TruncateUILen: servenv.TruncateUILen,
TruncateErrLen: servenv.TruncateErrLen,
})
if err != nil {
return err
}
// Init the vtctld core
if err := vtctld.InitVtctld(ts, collationEnv, parser); err != nil {
if err := vtctld.InitVtctld(ts, collationEnv, parser, mysqlVersion); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion go/cmd/vtctld/cli/plugin_grpcvtctldserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
func init() {
servenv.OnRun(func() {
if servenv.GRPCCheckServiceMap("vtctld") {
grpcvtctldserver.StartServer(servenv.GRPCServer, ts, collationEnv, parser)
grpcvtctldserver.StartServer(servenv.GRPCServer, ts, collationEnv, parser, mysqlVersion)
}
})
}
2 changes: 1 addition & 1 deletion go/cmd/vtctld/cli/plugin_grpcvtctlserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
func init() {
servenv.OnRun(func() {
if servenv.GRPCCheckServiceMap("vtctl") {
grpcvtctlserver.StartServer(servenv.GRPCServer, ts, collationEnv, parser)
grpcvtctlserver.StartServer(servenv.GRPCServer, ts, collationEnv, parser, mysqlVersion)
}
})
}
2 changes: 1 addition & 1 deletion go/cmd/vtctld/cli/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func initSchema() {
return
}
ctx := context.Background()
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), collationEnv, parser)
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), collationEnv, parser, mysqlVersion)
_, err = schemamanager.Run(
ctx,
controller,
Expand Down
8 changes: 5 additions & 3 deletions go/cmd/vtctldclient/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ var (

collationEnv *collations.Environment
parser *sqlparser.Parser
mysqlVersion string

topoOptions = struct {
implementation string
Expand Down Expand Up @@ -214,7 +215,7 @@ func getClientForCommand(cmd *cobra.Command) (vtctldclient.VtctldClient, error)
return nil
})
})
vtctld := grpcvtctldserver.NewVtctldServer(ts, collationEnv, parser)
vtctld := grpcvtctldserver.NewVtctldServer(ts, collationEnv, parser, mysqlVersion)
localvtctldclient.SetServer(vtctld)
VtctldClientProtocol = "local"
server = ""
Expand All @@ -232,10 +233,11 @@ func init() {
Root.PersistentFlags().StringVar(&topoOptions.globalRoot, "topo-global-root", topoOptions.globalRoot, "the path of the global topology data in the global topology server")
vreplcommon.RegisterCommands(Root)

collationEnv = collations.NewEnvironment(servenv.MySQLServerVersion())
mysqlVersion = servenv.MySQLServerVersion()
collationEnv = collations.NewEnvironment(mysqlVersion)
var err error
parser, err = sqlparser.New(sqlparser.Options{
MySQLServerVersion: servenv.MySQLServerVersion(),
MySQLServerVersion: mysqlVersion,
TruncateUILen: servenv.TruncateUILen,
TruncateErrLen: servenv.TruncateErrLen,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"vitess.io/vitess/go/cmd/vtctldclient/command"
"vitess.io/vitess/go/cmd/vtctldclient/command/vreplication/common"
"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/mysql/config"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/topo"
"vitess.io/vitess/go/vt/topo/memorytopo"
Expand Down Expand Up @@ -146,7 +147,7 @@ func SetupLocalVtctldClient(t *testing.T, ctx context.Context, cells ...string)
tmclient.RegisterTabletManagerClientFactory("grpc", func() tmclient.TabletManagerClient {
return nil
})
vtctld := grpcvtctldserver.NewVtctldServer(ts, collations.MySQL8(), sqlparser.NewTestParser())
vtctld := grpcvtctldserver.NewVtctldServer(ts, collations.MySQL8(), sqlparser.NewTestParser(), config.DefaultMySQLVersion)
localvtctldclient.SetServer(vtctld)
command.VtctldClientProtocol = "local"
client, err := vtctldclient.New(command.VtctldClientProtocol, "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"testing"

"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/mysql/config"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/grpcclient"
"vitess.io/vitess/go/vt/sqlparser"
Expand Down Expand Up @@ -85,7 +86,7 @@ func newTestVDiffEnv(t testing.TB, ctx context.Context, sourceShards, targetShar
tabletType: topodatapb.TabletType_REPLICA,
tmc: newTestVDiffTMClient(),
}
env.ws = workflow.NewServer(env.topoServ, env.tmc, collations.MySQL8(), sqlparser.NewTestParser())
env.ws = workflow.NewServer(env.topoServ, env.tmc, collations.MySQL8(), sqlparser.NewTestParser(), config.DefaultMySQLVersion)
env.tmc.testEnv = env

// Generate a unique dialer name.
Expand Down
7 changes: 4 additions & 3 deletions go/cmd/vtexplain/cli/vtexplain.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,17 @@ func parseAndRun() error {
Target: dbName,
}

collationEnv := collations.NewEnvironment(servenv.MySQLServerVersion())
mysqlServerVersion := servenv.MySQLServerVersion()
collationEnv := collations.NewEnvironment(mysqlServerVersion)
parser, err := sqlparser.New(sqlparser.Options{
MySQLServerVersion: servenv.MySQLServerVersion(),
MySQLServerVersion: mysqlServerVersion,
TruncateUILen: servenv.TruncateUILen,
TruncateErrLen: servenv.TruncateErrLen,
})
if err != nil {
return err
}
vte, err := vtexplain.Init(context.Background(), vschema, schema, ksShardMap, opts, collationEnv, parser)
vte, err := vtexplain.Init(context.Background(), vschema, schema, ksShardMap, opts, collationEnv, parser, mysqlServerVersion)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions go/cmd/vtgate/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,12 @@ func run(cmd *cobra.Command, args []string) error {
return fmt.Errorf("cells_to_watch validation failed: %v", err)
}

mysqlVersion := servenv.MySQLServerVersion()
plannerVersion, _ := plancontext.PlannerNameToVersion(plannerName)
collationEnv := collations.NewEnvironment(servenv.MySQLServerVersion())
collationEnv := collations.NewEnvironment(mysqlVersion)

// pass nil for HealthCheck and it will be created
vtg := vtgate.Init(context.Background(), nil, resilientServer, cell, tabletTypes, plannerVersion, collationEnv)
vtg := vtgate.Init(context.Background(), nil, resilientServer, cell, tabletTypes, plannerVersion, collationEnv, mysqlVersion)

servenv.OnRun(func() {
// Flags are parsed now. Parse the template using the actual flag value and overwrite the current template.
Expand Down
17 changes: 9 additions & 8 deletions go/cmd/vttablet/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,25 @@ func run(cmd *cobra.Command, args []string) error {
return fmt.Errorf("failed to parse --tablet-path: %w", err)
}

mysqlVersion := servenv.MySQLServerVersion()
parser, err := sqlparser.New(sqlparser.Options{
MySQLServerVersion: servenv.MySQLServerVersion(),
MySQLServerVersion: mysqlVersion,
TruncateUILen: servenv.TruncateUILen,
TruncateErrLen: servenv.TruncateErrLen,
})
if err != nil {
return fmt.Errorf("cannot initialize sql parser: %w", err)
}

collationEnv := collations.NewEnvironment(servenv.MySQLServerVersion())
collationEnv := collations.NewEnvironment(mysqlVersion)
// config and mycnf initializations are intertwined.
config, mycnf, err := initConfig(tabletAlias, collationEnv)
if err != nil {
return err
}

ts := topo.Open()
qsc, err := createTabletServer(context.Background(), config, ts, tabletAlias, collationEnv, parser)
qsc, err := createTabletServer(context.Background(), config, ts, tabletAlias, collationEnv, parser, mysqlVersion)
if err != nil {
ts.Close()
return err
Expand All @@ -142,9 +143,8 @@ func run(cmd *cobra.Command, args []string) error {
ts.Close()
return fmt.Errorf("failed to extract online DDL binaries: %w", err)
}

parser, err = sqlparser.New(sqlparser.Options{
MySQLServerVersion: servenv.MySQLServerVersion(),
MySQLServerVersion: mysqlVersion,
TruncateUILen: servenv.TruncateUILen,
TruncateErrLen: servenv.TruncateErrLen,
})
Expand All @@ -168,10 +168,11 @@ func run(cmd *cobra.Command, args []string) error {
DBConfigs: config.DB.Clone(),
QueryServiceControl: qsc,
UpdateStream: binlog.NewUpdateStream(ts, tablet.Keyspace, tabletAlias.Cell, qsc.SchemaEngine(), parser),
VREngine: vreplication.NewEngine(config, ts, tabletAlias.Cell, mysqld, qsc.LagThrottler(), collationEnv, parser),
VREngine: vreplication.NewEngine(config, ts, tabletAlias.Cell, mysqld, qsc.LagThrottler(), collationEnv, parser, mysqlVersion),
VDiffEngine: vdiff.NewEngine(ts, tablet, collationEnv, parser),
CollationEnv: collationEnv,
SQLParser: parser,
MySQLVersion: mysqlVersion,
}
if err := tm.Start(tablet, config); err != nil {
ts.Close()
Expand Down Expand Up @@ -259,7 +260,7 @@ func extractOnlineDDL() error {
return nil
}

func createTabletServer(ctx context.Context, config *tabletenv.TabletConfig, ts *topo.Server, tabletAlias *topodatapb.TabletAlias, collationEnv *collations.Environment, parser *sqlparser.Parser) (*tabletserver.TabletServer, error) {
func createTabletServer(ctx context.Context, config *tabletenv.TabletConfig, ts *topo.Server, tabletAlias *topodatapb.TabletAlias, collationEnv *collations.Environment, parser *sqlparser.Parser, mysqlVersion string) (*tabletserver.TabletServer, error) {
if tableACLConfig != "" {
// To override default simpleacl, other ACL plugins must set themselves to be default ACL factory
tableacl.Register("simpleacl", &simpleacl.Factory{})
Expand All @@ -268,7 +269,7 @@ func createTabletServer(ctx context.Context, config *tabletenv.TabletConfig, ts
}

// creates and registers the query service
qsc := tabletserver.NewTabletServer(ctx, "", config, ts, tabletAlias, collationEnv, parser)
qsc := tabletserver.NewTabletServer(ctx, "", config, ts, tabletAlias, collationEnv, parser, mysqlVersion)
servenv.OnRun(func() {
qsc.Register()
addStatusParts(qsc)
Expand Down
3 changes: 2 additions & 1 deletion go/test/fuzzing/tabletserver_schema_fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/mysql/config"
"vitess.io/vitess/go/mysql/fakesqldb"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/dbconfigs"
Expand Down Expand Up @@ -68,7 +69,7 @@ func newTestLoadTable(tableName, comment string, db *fakesqldb.DB) (*schema.Tabl
IdleTimeout: 10 * time.Second,
}

connPool := connpool.NewPool(tabletenv.NewEnv(nil, "SchemaTest", collations.MySQL8(), sqlparser.NewTestParser()), "", cfg)
connPool := connpool.NewPool(tabletenv.NewEnv(nil, "SchemaTest", collations.MySQL8(), sqlparser.NewTestParser(), config.DefaultMySQLVersion), "", cfg)
connPool.Open(appParams, dbaParams, appParams)
conn, err := connPool.Get(ctx, nil)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion go/test/fuzzing/vtctl_fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"strings"

"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/mysql/config"
"vitess.io/vitess/go/vt/logutil"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/topo"
Expand Down Expand Up @@ -182,7 +183,7 @@ func Fuzz(data []byte) int {
// Add params to the command
commandSlice = append(commandSlice, args...)

_ = vtctl.RunCommand(ctx, wrangler.New(logger, topo, tmc, collations.MySQL8(), sqlparser.NewTestParser()), commandSlice)
_ = vtctl.RunCommand(ctx, wrangler.New(logger, topo, tmc, collations.MySQL8(), sqlparser.NewTestParser(), config.DefaultMySQLVersion), commandSlice)
command++
}

Expand Down
Loading

0 comments on commit ca4246d

Please sign in to comment.