diff --git a/v4/export/config.go b/v4/export/config.go index a5b99f7e..32e327d3 100644 --- a/v4/export/config.go +++ b/v4/export/config.go @@ -68,6 +68,7 @@ const ( flagCompleteInsert = "complete-insert" flagParams = "params" flagReadTimeout = "read-timeout" + flagMaxIdleTime = "max-idle-time" flagTransactionalConsistency = "transactional-consistency" flagCompress = "compress" @@ -124,6 +125,7 @@ type Config struct { OutputFileTemplate *template.Template `json:"-"` Rows uint64 ReadTimeout time.Duration + MaxIdleTime time.Duration TiDBMemQuotaQuery uint64 FileSize uint64 StatementSize uint64 @@ -242,7 +244,7 @@ func (conf *Config) DefineFlags(flags *pflag.FlagSet) { flags.StringToString(flagParams, nil, `Extra session variables used while dumping, accepted format: --params "character_set_client=latin1,character_set_connection=latin1"`) flags.Bool(FlagHelp, false, "Print help message and quit") flags.Duration(flagReadTimeout, 15*time.Minute, "I/O read timeout for db connection.") - _ = flags.MarkHidden(flagReadTimeout) + flags.Duration(flagMaxIdleTime, 600*time.Second, "max idle time for db connection.") flags.Bool(flagTransactionalConsistency, true, "Only support transactional consistency") _ = flags.MarkHidden(flagTransactionalConsistency) flags.StringP(flagCompress, "c", "", "Compress output file type, support 'gzip', 'no-compression' now") @@ -384,6 +386,10 @@ func (conf *Config) ParseFromFlags(flags *pflag.FlagSet) error { if err != nil { return errors.Trace(err) } + conf.MaxIdleTime, err = flags.GetDuration(flagMaxIdleTime) + if err != nil { + return errors.Trace(err) + } conf.TransactionalConsistency, err = flags.GetBool(flagTransactionalConsistency) if err != nil { return errors.Trace(err) diff --git a/v4/export/dump.go b/v4/export/dump.go index 1ad1ca61..cec86e39 100755 --- a/v4/export/dump.go +++ b/v4/export/dump.go @@ -996,6 +996,7 @@ func openSQLDB(d *Dumper) error { if err != nil { return errors.Trace(err) } + pool.SetConnMaxIdleTime(conf.MaxIdleTime) d.dbHandle = pool return nil } @@ -1155,5 +1156,6 @@ func setSessionParam(d *Dumper) error { if d.dbHandle, err = resetDBWithSessionParams(d.tctx, pool, conf.GetDSN(""), conf.SessionParams); err != nil { return errors.Trace(err) } + d.dbHandle.SetConnMaxIdleTime(conf.MaxIdleTime) return nil }