Skip to content

Commit

Permalink
Fix vtcombo parsing flags incorrectly (#17743)
Browse files Browse the repository at this point in the history
Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
  • Loading branch information
dbussink authored Feb 12, 2025
1 parent fa54e1d commit b5ede71
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
18 changes: 9 additions & 9 deletions go/cmd/vtcombo/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,6 @@ func init() {
// user know about this flag.
Main.Flags().MarkHidden("tablet_protocol")

var err error
env, err = vtenv.New(vtenv.Options{
MySQLServerVersion: servenv.MySQLServerVersion(),
TruncateUILen: servenv.TruncateUILen,
TruncateErrLen: servenv.TruncateErrLen,
})
if err != nil {
log.Fatalf("unable to initialize env: %v", err)
}
srvTopoCounts = stats.NewCountersWithSingleLabel("ResilientSrvTopoServer", "Resilient srvtopo server operations", "type")
}

Expand Down Expand Up @@ -189,6 +180,15 @@ func run(cmd *cobra.Command, args []string) (err error) {
cmd.Flags().Set("log_dir", "$VTDATAROOT/tmp")
}

env, err = vtenv.New(vtenv.Options{
MySQLServerVersion: servenv.MySQLServerVersion(),
TruncateUILen: servenv.TruncateUILen,
TruncateErrLen: servenv.TruncateErrLen,
})
if err != nil {
log.Fatalf("unable to initialize env: %v", err)
}

ctx, cancel := context.WithCancel(cmd.Context())
defer cancel()
if externalTopoServer {
Expand Down
21 changes: 10 additions & 11 deletions go/cmd/vtctldclient/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/spf13/cobra"

"vitess.io/vitess/go/trace"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/logutil"
"vitess.io/vitess/go/vt/servenv"
"vitess.io/vitess/go/vt/topo"
Expand Down Expand Up @@ -105,6 +104,15 @@ connect directly to the topo server(s).`, useInternalVtctld),
// We use PersistentPreRun to set up the tracer, grpc client, and
// command context for every command.
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
env, err = vtenv.New(vtenv.Options{
MySQLServerVersion: servenv.MySQLServerVersion(),
TruncateUILen: servenv.TruncateUILen,
TruncateErrLen: servenv.TruncateErrLen,
})
if err != nil {
return fmt.Errorf("failed to initialize vtenv: %w", err)
}

logutil.PurgeLogs()
traceCloser = trace.StartTracing("vtctldclient")
client, err = getClientForCommand(cmd)
Expand All @@ -118,6 +126,7 @@ connect directly to the topo server(s).`, useInternalVtctld),
}
vreplcommon.SetClient(client)
vreplcommon.SetCommandCtx(commandCtx)

return err
},
// Similarly, PersistentPostRun cleans up the resources spawned by
Expand Down Expand Up @@ -220,14 +229,4 @@ func init() {
Root.PersistentFlags().StringSliceVar(&topoOptions.globalServerAddresses, "topo-global-server-address", topoOptions.globalServerAddresses, "the address of the global topology server(s)")
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)

var err error
env, err = vtenv.New(vtenv.Options{
MySQLServerVersion: servenv.MySQLServerVersion(),
TruncateUILen: servenv.TruncateUILen,
TruncateErrLen: servenv.TruncateErrLen,
})
if err != nil {
log.Fatalf("failed to initialize vtenv: %v", err)
}
}

0 comments on commit b5ede71

Please sign in to comment.