Skip to content

Commit

Permalink
Use shared constant for default timeout value
Browse files Browse the repository at this point in the history
Signed-off-by: Dirkjan Bussink <[email protected]>
  • Loading branch information
dbussink committed Mar 26, 2024
1 parent e45438b commit f1a508f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go/cmd/vtbackup/cli/vtbackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ var (
mysqlPort = 3306
mysqlSocket string
mysqlTimeout = 5 * time.Minute

This comment has been minimized.

Copy link
@deepthi

deepthi Mar 26, 2024

Member

Any chance this is also defined in many places and can be factored out?

mysqlShutdownTimeout = 5 * time.Minute
mysqlShutdownTimeout = mysqlctl.DefaultShutdownTimeout
initDBSQLFile string
detachedMode bool
keepAliveTimeout time.Duration
Expand Down
14 changes: 6 additions & 8 deletions go/cmd/vtcombo/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions go/vt/mysqlctl/grpcmysqlctlserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package grpcmysqlctlserver

import (
"context"
"time"

"google.golang.org/grpc"

Expand All @@ -43,16 +42,14 @@ 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)
if err != nil {
return nil, err
}
if !ok {
timeout = mysqlShutdownTimeout
timeout = mysqlctl.DefaultShutdownTimeout
}
return &mysqlctlpb.ShutdownResponse{}, s.mysqld.Shutdown(ctx, s.cnf, request.WaitForMysqld, timeout)
}
Expand Down
2 changes: 2 additions & 0 deletions go/vt/mysqlctl/mycnf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vttablet/tabletmanager/tm_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ var (
initTags flagutil.StringMapValue

initTimeout = 1 * time.Minute
mysqlShutdownTimeout = 5 * time.Minute
mysqlShutdownTimeout = mysqlctl.DefaultShutdownTimeout
)

func registerInitFlags(fs *pflag.FlagSet) {
Expand Down

0 comments on commit f1a508f

Please sign in to comment.