From de1f43ddf95c5d1ce15b0246e5d20a9716cdd331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=20=E4=BF=8A=E4=BA=AD?= Date: Tue, 3 Aug 2021 09:25:18 +0800 Subject: [PATCH] add --max-idle-time flag See https://github.com/pingcap/dumpling/issues/282 --- v4/export/config.go | 8 +++++++- v4/export/dump.go | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) 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 }