From f1a508fc25ea76e219e7563fdd36aa25dc159d4e Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Tue, 26 Mar 2024 20:51:10 +0100 Subject: [PATCH] Use shared constant for default timeout value Signed-off-by: Dirkjan Bussink --- go/cmd/vtbackup/cli/vtbackup.go | 2 +- go/cmd/vtcombo/cli/main.go | 14 ++++++-------- go/vt/mysqlctl/grpcmysqlctlserver/server.go | 5 +---- go/vt/mysqlctl/mycnf.go | 2 ++ go/vt/vttablet/tabletmanager/tm_init.go | 2 +- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/go/cmd/vtbackup/cli/vtbackup.go b/go/cmd/vtbackup/cli/vtbackup.go index 1f6f62f7ad1..3afc21bda7f 100644 --- a/go/cmd/vtbackup/cli/vtbackup.go +++ b/go/cmd/vtbackup/cli/vtbackup.go @@ -87,7 +87,7 @@ var ( mysqlPort = 3306 mysqlSocket string mysqlTimeout = 5 * time.Minute - mysqlShutdownTimeout = 5 * time.Minute + mysqlShutdownTimeout = mysqlctl.DefaultShutdownTimeout initDBSQLFile string detachedMode bool keepAliveTimeout time.Duration diff --git a/go/cmd/vtcombo/cli/main.go b/go/cmd/vtcombo/cli/main.go index 16e625a6ae6..d18c22ddfbb 100644 --- a/go/cmd/vtcombo/cli/main.go +++ b/go/cmd/vtcombo/cli/main.go @@ -168,8 +168,6 @@ func startMysqld(uid uint32) (mysqld *mysqlctl.Mysqld, cnf *mysqlctl.Mycnf, err return mysqld, cnf, nil } -const mysqlShutdownTimeout = 5 * time.Minute - func run(cmd *cobra.Command, args []string) (err error) { // Stash away a copy of the topology that vtcombo was started with. // @@ -218,9 +216,9 @@ func run(cmd *cobra.Command, args []string) (err error) { return err } servenv.OnClose(func() { - ctx, cancel := context.WithTimeout(context.Background(), mysqlShutdownTimeout+10*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), mysqlctl.DefaultShutdownTimeout+10*time.Second) defer cancel() - mysqld.Shutdown(ctx, cnf, true, mysqlShutdownTimeout) + mysqld.Shutdown(ctx, cnf, true, mysqlctl.DefaultShutdownTimeout) }) // We want to ensure we can write to this database mysqld.SetReadOnly(false) @@ -242,9 +240,9 @@ func run(cmd *cobra.Command, args []string) (err error) { if err != nil { // ensure we start mysql in the event we fail here if startMysql { - ctx, cancel := context.WithTimeout(context.Background(), mysqlShutdownTimeout+10*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), mysqlctl.DefaultShutdownTimeout+10*time.Second) defer cancel() - mysqld.Shutdown(ctx, cnf, true, mysqlShutdownTimeout) + mysqld.Shutdown(ctx, cnf, true, mysqlctl.DefaultShutdownTimeout) } return fmt.Errorf("initTabletMapProto failed: %w", err) @@ -291,9 +289,9 @@ func run(cmd *cobra.Command, args []string) (err error) { err := topotools.RebuildKeyspace(context.Background(), logutil.NewConsoleLogger(), ts, ks.GetName(), tpb.Cells, false) if err != nil { if startMysql { - ctx, cancel := context.WithTimeout(context.Background(), mysqlShutdownTimeout+10*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), mysqlctl.DefaultShutdownTimeout+10*time.Second) defer cancel() - mysqld.Shutdown(ctx, cnf, true, mysqlShutdownTimeout) + mysqld.Shutdown(ctx, cnf, true, mysqlctl.DefaultShutdownTimeout) } return fmt.Errorf("Couldn't build srv keyspace for (%v: %v). Got error: %w", ks, tpb.Cells, err) diff --git a/go/vt/mysqlctl/grpcmysqlctlserver/server.go b/go/vt/mysqlctl/grpcmysqlctlserver/server.go index 38ce4b2b2df..2a703a50a84 100644 --- a/go/vt/mysqlctl/grpcmysqlctlserver/server.go +++ b/go/vt/mysqlctl/grpcmysqlctlserver/server.go @@ -22,7 +22,6 @@ package grpcmysqlctlserver import ( "context" - "time" "google.golang.org/grpc" @@ -43,8 +42,6 @@ func (s *server) Start(ctx context.Context, request *mysqlctlpb.StartRequest) (* return &mysqlctlpb.StartResponse{}, s.mysqld.Start(ctx, s.cnf, request.MysqldArgs...) } -const mysqlShutdownTimeout = 5 * time.Minute - // Shutdown implements the server side of the MysqlctlClient interface. func (s *server) Shutdown(ctx context.Context, request *mysqlctlpb.ShutdownRequest) (*mysqlctlpb.ShutdownResponse, error) { timeout, ok, err := protoutil.DurationFromProto(request.MysqlShutdownTimeout) @@ -52,7 +49,7 @@ func (s *server) Shutdown(ctx context.Context, request *mysqlctlpb.ShutdownReque return nil, err } if !ok { - timeout = mysqlShutdownTimeout + timeout = mysqlctl.DefaultShutdownTimeout } return &mysqlctlpb.ShutdownResponse{}, s.mysqld.Shutdown(ctx, s.cnf, request.WaitForMysqld, timeout) } diff --git a/go/vt/mysqlctl/mycnf.go b/go/vt/mysqlctl/mycnf.go index 7ae2d5d0aa9..c4ee062348b 100644 --- a/go/vt/mysqlctl/mycnf.go +++ b/go/vt/mysqlctl/mycnf.go @@ -31,6 +31,8 @@ import ( "time" ) +const DefaultShutdownTimeout = 5 * time.Minute + // Mycnf is a memory structure that contains a bunch of interesting // parameters to start mysqld. It can be used to generate standard // my.cnf files from a server id and mysql port. It can also be diff --git a/go/vt/vttablet/tabletmanager/tm_init.go b/go/vt/vttablet/tabletmanager/tm_init.go index 6a1a4f1b730..efb6c5e878f 100644 --- a/go/vt/vttablet/tabletmanager/tm_init.go +++ b/go/vt/vttablet/tabletmanager/tm_init.go @@ -92,7 +92,7 @@ var ( initTags flagutil.StringMapValue initTimeout = 1 * time.Minute - mysqlShutdownTimeout = 5 * time.Minute + mysqlShutdownTimeout = mysqlctl.DefaultShutdownTimeout ) func registerInitFlags(fs *pflag.FlagSet) {