Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

Commit

Permalink
add --max-idle-time flag
Browse files Browse the repository at this point in the history
See #282
  • Loading branch information
dbakit committed Aug 3, 2021
1 parent d6e5fb4 commit de1f43d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion v4/export/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const (
flagCompleteInsert = "complete-insert"
flagParams = "params"
flagReadTimeout = "read-timeout"
flagMaxIdleTime = "max-idle-time"
flagTransactionalConsistency = "transactional-consistency"
flagCompress = "compress"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions v4/export/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

0 comments on commit de1f43d

Please sign in to comment.