Skip to content

Commit

Permalink
Remove servenv usage and config flags from collations (#14781)
Browse files Browse the repository at this point in the history
Signed-off-by: Dirkjan Bussink <[email protected]>
  • Loading branch information
dbussink authored Dec 17, 2023
1 parent 7c9fec7 commit a8ec75e
Show file tree
Hide file tree
Showing 268 changed files with 1,988 additions and 1,363 deletions.
2 changes: 1 addition & 1 deletion go/cmd/mysqlctl/command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var initArgs = struct {

func commandInit(cmd *cobra.Command, args []string) error {
// Generate my.cnf from scratch and use it to find mysqld.
mysqld, cnf, err := mysqlctl.CreateMysqldAndMycnf(tabletUID, mysqlSocket, mysqlPort)
mysqld, cnf, err := mysqlctl.CreateMysqldAndMycnf(tabletUID, mysqlSocket, mysqlPort, collationEnv)
if err != nil {
return fmt.Errorf("failed to initialize mysql config: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go/cmd/mysqlctl/command/init_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var InitConfig = &cobra.Command{

func commandInitConfig(cmd *cobra.Command, args []string) error {
// Generate my.cnf from scratch and use it to find mysqld.
mysqld, cnf, err := mysqlctl.CreateMysqldAndMycnf(tabletUID, mysqlSocket, mysqlPort)
mysqld, cnf, err := mysqlctl.CreateMysqldAndMycnf(tabletUID, mysqlSocket, mysqlPort, collationEnv)
if err != nil {
return fmt.Errorf("failed to initialize mysql config: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go/cmd/mysqlctl/command/reinit_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var ReinitConfig = &cobra.Command{

func commandReinitConfig(cmd *cobra.Command, args []string) error {
// There ought to be an existing my.cnf, so use it to find mysqld.
mysqld, cnf, err := mysqlctl.OpenMysqldAndMycnf(tabletUID)
mysqld, cnf, err := mysqlctl.OpenMysqldAndMycnf(tabletUID, collationEnv)
if err != nil {
return fmt.Errorf("failed to find mysql config: %v", err)
}
Expand Down
11 changes: 7 additions & 4 deletions go/cmd/mysqlctl/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,22 @@ import (

"vitess.io/vitess/go/acl"
vtcmd "vitess.io/vitess/go/cmd"
"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/vt/dbconfigs"
"vitess.io/vitess/go/vt/logutil"
"vitess.io/vitess/go/vt/servenv"
)

var (
mysqlPort = 3306
tabletUID = uint32(41983)
mysqlSocket string
mysqlPort = 3306
tabletUID = uint32(41983)
mysqlSocket string
collationEnv *collations.Environment

Root = &cobra.Command{
Use: "mysqlctl",
Short: "mysqlctl initializes and controls mysqld with Vitess-specific configuration.",
Long: "`mysqlctl` is a command-line client used for managing `mysqld` instances.\n\n" +

"It is responsible for bootstrapping tasks such as generating a configuration file for `mysqld` and initializing the instance and its data directory.\n" +
"The `mysqld_safe` watchdog is utilized when present.\n" +
"This helps ensure that `mysqld` is automatically restarted after failures.",
Expand Down Expand Up @@ -74,4 +75,6 @@ func init() {
Root.PersistentFlags().StringVar(&mysqlSocket, "mysql_socket", mysqlSocket, "Path to the mysqld socket file.")

acl.RegisterFlags(Root.PersistentFlags())

collationEnv = collations.NewEnvironment(servenv.MySQLServerVersion())
}
2 changes: 1 addition & 1 deletion go/cmd/mysqlctl/command/shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var shutdownArgs = struct {

func commandShutdown(cmd *cobra.Command, args []string) error {
// There ought to be an existing my.cnf, so use it to find mysqld.
mysqld, cnf, err := mysqlctl.OpenMysqldAndMycnf(tabletUID)
mysqld, cnf, err := mysqlctl.OpenMysqldAndMycnf(tabletUID, collationEnv)
if err != nil {
return fmt.Errorf("failed to find mysql config: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go/cmd/mysqlctl/command/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var startArgs = struct {

func commandStart(cmd *cobra.Command, args []string) error {
// There ought to be an existing my.cnf, so use it to find mysqld.
mysqld, cnf, err := mysqlctl.OpenMysqldAndMycnf(tabletUID)
mysqld, cnf, err := mysqlctl.OpenMysqldAndMycnf(tabletUID, collationEnv)
if err != nil {
return fmt.Errorf("failed to find mysql config: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go/cmd/mysqlctl/command/teardown.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var teardownArgs = struct {

func commandTeardown(cmd *cobra.Command, args []string) error {
// There ought to be an existing my.cnf, so use it to find mysqld.
mysqld, cnf, err := mysqlctl.OpenMysqldAndMycnf(tabletUID)
mysqld, cnf, err := mysqlctl.OpenMysqldAndMycnf(tabletUID, collationEnv)
if err != nil {
return fmt.Errorf("failed to find mysql config: %v", err)
}
Expand Down
14 changes: 9 additions & 5 deletions go/cmd/mysqlctld/cli/mysqlctld.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/spf13/cobra"

"vitess.io/vitess/go/acl"
"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/vt/dbconfigs"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/logutil"
Expand All @@ -40,9 +41,10 @@ var (
mysqld *mysqlctl.Mysqld
cnf *mysqlctl.Mycnf

mysqlPort = 3306
tabletUID = uint32(41983)
mysqlSocket string
mysqlPort = 3306
tabletUID = uint32(41983)
mysqlSocket string
collationEnv *collations.Environment

// mysqlctl init flags
waitTime = 5 * time.Minute
Expand Down Expand Up @@ -90,6 +92,8 @@ func init() {
Main.Flags().DurationVar(&shutdownWaitTime, "shutdown-wait-time", shutdownWaitTime, "How long to wait for mysqld shutdown")

acl.RegisterFlags(Main.Flags())

collationEnv = collations.NewEnvironment(servenv.MySQLServerVersion())
}

func run(cmd *cobra.Command, args []string) error {
Expand All @@ -110,7 +114,7 @@ func run(cmd *cobra.Command, args []string) error {
log.Infof("mycnf file (%s) doesn't exist, initializing", mycnfFile)

var err error
mysqld, cnf, err = mysqlctl.CreateMysqldAndMycnf(tabletUID, mysqlSocket, mysqlPort)
mysqld, cnf, err = mysqlctl.CreateMysqldAndMycnf(tabletUID, mysqlSocket, mysqlPort, collationEnv)
if err != nil {
cancel()
return fmt.Errorf("failed to initialize mysql config: %w", err)
Expand All @@ -126,7 +130,7 @@ func run(cmd *cobra.Command, args []string) error {
log.Infof("mycnf file (%s) already exists, starting without init", mycnfFile)

var err error
mysqld, cnf, err = mysqlctl.OpenMysqldAndMycnf(tabletUID)
mysqld, cnf, err = mysqlctl.OpenMysqldAndMycnf(tabletUID, collationEnv)
if err != nil {
cancel()
return fmt.Errorf("failed to find mysql config: %w", err)
Expand Down
9 changes: 6 additions & 3 deletions go/cmd/vtadmin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (

"github.com/spf13/cobra"

_flag "vitess.io/vitess/go/internal/flag"
"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/trace"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/logutil"
Expand All @@ -35,8 +37,6 @@ import (
vtadminhttp "vitess.io/vitess/go/vt/vtadmin/http"
"vitess.io/vitess/go/vt/vtadmin/http/debug"
"vitess.io/vitess/go/vt/vtadmin/rbac"

_flag "vitess.io/vitess/go/internal/flag"
)

var (
Expand Down Expand Up @@ -138,13 +138,14 @@ 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())

s := vtadmin.NewAPI(clusters, vtadmin.Options{
GRPCOpts: opts,
HTTPOpts: httpOpts,
RBAC: rbacConfig,
EnableDynamicClusters: enableDynamicClusters,
})
}, collationEnv)
bootSpan.Finish()

if err := s.ListenAndServe(); err != nil {
Expand Down Expand Up @@ -208,6 +209,8 @@ func main() {
rootCmd.Flags().AddGoFlag(flag.Lookup("stderrthreshold"))
rootCmd.Flags().AddGoFlag(flag.Lookup("log_dir"))

servenv.RegisterMySQLServerFlags(rootCmd.Flags())

if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
}
Expand Down
10 changes: 7 additions & 3 deletions go/cmd/vtbackup/cli/vtbackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ import (

"github.com/spf13/cobra"

"vitess.io/vitess/go/mysql/replication"

"vitess.io/vitess/go/acl"
"vitess.io/vitess/go/cmd"
"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/mysql/replication"
"vitess.io/vitess/go/stats"
"vitess.io/vitess/go/vt/dbconfigs"
"vitess.io/vitess/go/vt/log"
Expand Down Expand Up @@ -93,6 +93,8 @@ var (
keepAliveTimeout time.Duration
disableRedoLog bool

collationEnv *collations.Environment

// Deprecated, use "Phase" instead.
deprecatedDurationByPhase = stats.NewGaugesWithSingleLabel(
"DurationByPhaseSeconds",
Expand Down Expand Up @@ -215,6 +217,8 @@ func init() {
Main.Flags().BoolVar(&disableRedoLog, "disable-redo-log", disableRedoLog, "Disable InnoDB redo log during replication-from-primary phase of backup.")

acl.RegisterFlags(Main.Flags())

collationEnv = collations.NewEnvironment(servenv.MySQLServerVersion())
}

func run(_ *cobra.Command, args []string) error {
Expand Down Expand Up @@ -327,7 +331,7 @@ func takeBackup(ctx context.Context, topoServer *topo.Server, backupStorage back
}()

// Start up mysqld as if we are mysqlctld provisioning a fresh tablet.
mysqld, mycnf, err := mysqlctl.CreateMysqldAndMycnf(tabletAlias.Uid, mysqlSocket, mysqlPort)
mysqld, mycnf, err := mysqlctl.CreateMysqldAndMycnf(tabletAlias.Uid, mysqlSocket, mysqlPort, collationEnv)
if err != nil {
return fmt.Errorf("failed to initialize mysql config: %v", err)
}
Expand Down
22 changes: 14 additions & 8 deletions go/cmd/vtcombo/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (

"github.com/spf13/cobra"

"vitess.io/vitess/go/mysql/collations"

"vitess.io/vitess/go/acl"
"vitess.io/vitess/go/mysql/replication"
"vitess.io/vitess/go/vt/dbconfigs"
Expand Down Expand Up @@ -78,6 +80,7 @@ In particular, it contains:

tpb vttestpb.VTTestTopology
ts *topo.Server
collationEnv *collations.Environment
resilientServer *srvtopo.ResilientServer
)

Expand Down Expand Up @@ -114,6 +117,8 @@ func init() {
// We're going to force the value later, so don't even bother letting the
// user know about this flag.
Main.Flags().MarkHidden("tablet_protocol")

collationEnv = collations.NewEnvironment(servenv.MySQLServerVersion())
}

func startMysqld(uid uint32) (mysqld *mysqlctl.Mysqld, cnf *mysqlctl.Mycnf, err error) {
Expand All @@ -123,15 +128,15 @@ func startMysqld(uid uint32) (mysqld *mysqlctl.Mysqld, cnf *mysqlctl.Mycnf, err
mycnfFile := mysqlctl.MycnfFile(uid)

if _, statErr := os.Stat(mycnfFile); os.IsNotExist(statErr) {
mysqld, cnf, err = mysqlctl.CreateMysqldAndMycnf(uid, "", mysqlPort)
mysqld, cnf, err = mysqlctl.CreateMysqldAndMycnf(uid, "", mysqlPort, collationEnv)
if err != nil {
return nil, nil, fmt.Errorf("failed to initialize mysql config :%w", err)
}
if err := mysqld.Init(ctx, cnf, ""); err != nil {
return nil, nil, fmt.Errorf("failed to initialize mysql :%w", err)
}
} else {
mysqld, cnf, err = mysqlctl.OpenMysqldAndMycnf(uid)
mysqld, cnf, err = mysqlctl.OpenMysqldAndMycnf(uid, collationEnv)
if err != nil {
return nil, nil, fmt.Errorf("failed to find mysql config: %w", err)
}
Expand Down Expand Up @@ -205,7 +210,7 @@ func run(cmd *cobra.Command, args []string) (err error) {
mysqld.SetReadOnly(false)

} else {
dbconfigs.GlobalDBConfigs.InitWithSocket("")
dbconfigs.GlobalDBConfigs.InitWithSocket("", collationEnv)
mysqld.Mysqld = mysqlctl.NewMysqld(&dbconfigs.GlobalDBConfigs)
servenv.OnClose(mysqld.Close)
}
Expand All @@ -217,7 +222,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)
uid, err := vtcombo.InitTabletMap(ts, &tpb, mysqld, &dbconfigs.GlobalDBConfigs, schemaDir, startMysql, collationEnv)
if err != nil {
// ensure we start mysql in the event we fail here
if startMysql {
Expand All @@ -242,8 +247,8 @@ func run(cmd *cobra.Command, args []string) (err error) {
}
}

wr := wrangler.New(logutil.NewConsoleLogger(), ts, nil)
newUID, err := vtcombo.CreateKs(ctx, ts, &tpb, mysqld, &dbconfigs.GlobalDBConfigs, schemaDir, ks, true, uid, wr)
wr := wrangler.New(logutil.NewConsoleLogger(), ts, nil, collationEnv)
newUID, err := vtcombo.CreateKs(ctx, ts, &tpb, mysqld, &dbconfigs.GlobalDBConfigs, schemaDir, ks, true, uid, wr, collationEnv)
if err != nil {
return err
}
Expand Down Expand Up @@ -291,11 +296,12 @@ func run(cmd *cobra.Command, args []string) (err error) {
vtgate.QueryLogHandler = "/debug/vtgate/querylog"
vtgate.QueryLogzHandler = "/debug/vtgate/querylogz"
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)
vtg := vtgate.Init(context.Background(), nil, resilientServer, tpb.Cells[0], tabletTypesToWait, plannerVersion, collationEnv)

// vtctld configuration and init
err = vtctld.InitVtctld(ts)
err = vtctld.InitVtctld(ts, collationEnv)
if err != nil {
return err
}
Expand Down
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)
grpcvtctlserver.StartServer(servenv.GRPCServer, ts, collationEnv)
}
})
}
6 changes: 3 additions & 3 deletions go/cmd/vtctl/vtctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"vitess.io/vitess/go/cmd"
"vitess.io/vitess/go/cmd/vtctldclient/command"
"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/trace"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/logutil"
Expand Down Expand Up @@ -126,7 +127,6 @@ func main() {

ts := topo.Open()
defer ts.Close()

ctx, cancel := context.WithTimeout(context.Background(), waitTime)
installSignalHandlers(cancel)

Expand Down Expand Up @@ -170,8 +170,8 @@ 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 := collations.NewEnvironment(servenv.MySQLServerVersion())
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), collationEnv)

if args[0] == "--" {
vtctl.PrintDoubleDashDeprecationNotice(wr)
Expand Down
9 changes: 6 additions & 3 deletions go/cmd/vtctld/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ import (
"github.com/spf13/cobra"

"vitess.io/vitess/go/acl"
"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/vt/servenv"
"vitess.io/vitess/go/vt/topo"
"vitess.io/vitess/go/vt/vtctld"
)

var (
ts *topo.Server
Main = &cobra.Command{
ts *topo.Server
collationEnv *collations.Environment
Main = &cobra.Command{
Use: "vtctld",
Short: "The Vitess cluster management daemon.",
Long: `vtctld provides web and gRPC interfaces to manage a single Vitess cluster.
Expand Down Expand Up @@ -59,8 +61,9 @@ func run(cmd *cobra.Command, args []string) error {
ts = topo.Open()
defer ts.Close()

collationEnv = collations.NewEnvironment(servenv.MySQLServerVersion())
// Init the vtctld core
if err := vtctld.InitVtctld(ts); err != nil {
if err := vtctld.InitVtctld(ts, collationEnv); err != nil {
return err
}

Expand Down
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)
grpcvtctlserver.StartServer(servenv.GRPCServer, ts, collationEnv)
}
})
}
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())
wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient(), collationEnv)
_, err = schemamanager.Run(
ctx,
controller,
Expand Down
Loading

0 comments on commit a8ec75e

Please sign in to comment.