Closed dbakit closed 2 years ago
diff --git a/v4/export/config.go b/v4/export/config.go
index a5b99f7..49a72ef 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 +243,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.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 +385,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 1ad1ca6..cec86e3 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
}
SetConnMaxIdleTime
is a newly added function in go 1.15. The CI releasing dumpling is still using go 1.13. We are trying to upgrade to go 1.16 recently. We will do this later after the CI is upgraded.
https://golang.org/doc/go1.15#database/sql
/type bug
@dba-kit Dumpling has already upgraded go version to v1.16. Could you please help us file a pull request?
Maybe this can work for you: https://github.com/pingcap/dumpling/pull/265#issuecomment-812340976
--params="net_read_timeout=86400,interactive_timeout=28800,wait_timeout=2147483,net_write_timeout=86400"
Yep, it's fine for me
Bug Report
On production environment, we set wait_timeout=600, so if mysql connection pool has some connections idle longer than 600s, the dumping will fail.
Dumpling & MySQL Version
Error Log