diff --git a/pkg/dbutil/common.go b/pkg/dbutil/common.go index 392d5113..6a5530c0 100644 --- a/pkg/dbutil/common.go +++ b/pkg/dbutil/common.go @@ -73,7 +73,8 @@ type DBConfig struct { Schema string `toml:"schema" json:"schema"` - Snapshot string `toml:"snapshot" json:"snapshot"` + Snapshot string `toml:"snapshot" json:"snapshot"` + MaxExecutionTime int `toml:"max-execution-time" json:"max-execution-time"` } // String returns native format of database configuration diff --git a/sync_diff_inspector/config/config.go b/sync_diff_inspector/config/config.go index 7fd99cca..2f8c73e2 100644 --- a/sync_diff_inspector/config/config.go +++ b/sync_diff_inspector/config/config.go @@ -108,12 +108,13 @@ type Security struct { // DataSource represents the Source Config. type DataSource struct { - Host string `toml:"host" json:"host"` - Port int `toml:"port" json:"port"` - User string `toml:"user" json:"user"` - Password utils.SecretString `toml:"password" json:"password"` - SqlMode string `toml:"sql-mode" json:"sql-mode"` - Snapshot string `toml:"snapshot" json:"snapshot"` + Host string `toml:"host" json:"host"` + Port int `toml:"port" json:"port"` + User string `toml:"user" json:"user"` + Password utils.SecretString `toml:"password" json:"password"` + SqlMode string `toml:"sql-mode" json:"sql-mode"` + Snapshot string `toml:"snapshot" json:"snapshot"` + MaxExecutionTime int `toml:"max-execution-time" json:"max-execution-time,omitempty"` Security *Security `toml:"security" json:"security"` @@ -138,11 +139,12 @@ func (d *DataSource) SetSnapshot(newSnapshot string) { func (d *DataSource) ToDBConfig() *dbutil.DBConfig { return &dbutil.DBConfig{ - Host: d.Host, - Port: d.Port, - User: d.User, - Password: d.Password.Plain(), - Snapshot: d.Snapshot, + Host: d.Host, + Port: d.Port, + User: d.User, + Password: d.Password.Plain(), + Snapshot: d.Snapshot, + MaxExecutionTime: d.MaxExecutionTime, } } @@ -191,6 +193,11 @@ func (d *DataSource) ToDriverConfig() *mysql.Config { if d.Security != nil && len(d.Security.TLSName) > 0 { cfg.TLSConfig = d.Security.TLSName } + // 0 indicates unset and max_execution_time=0 is unlimited + // in that case we don't set the max_execution_time at session level + if d.MaxExecutionTime > 0 { + cfg.Params["max_execution_time"] = strconv.Itoa(d.MaxExecutionTime) + } return cfg } diff --git a/sync_diff_inspector/config/config.toml b/sync_diff_inspector/config/config.toml index b5557216..8b4e9aa4 100644 --- a/sync_diff_inspector/config/config.toml +++ b/sync_diff_inspector/config/config.toml @@ -27,6 +27,7 @@ check-struct-only = false port = 4000 user = "root" password = "" + max-execution-time = 5 # Support tls connection # security.ca-path = "..." diff --git a/sync_diff_inspector/config/config_test.go b/sync_diff_inspector/config/config_test.go index 7c12c260..150654c4 100644 --- a/sync_diff_inspector/config/config_test.go +++ b/sync_diff_inspector/config/config_test.go @@ -34,6 +34,7 @@ func TestParseConfig(t *testing.T) { require.Nil(t, cfg.Parse([]string{"--config", "config.toml"})) require.Nil(t, cfg.Init()) require.Nil(t, cfg.Task.Init(cfg.DataSources, cfg.TableConfigs)) + require.Equal(t, cfg.Task.TargetInstance.MaxExecutionTime, 5) require.Nil(t, cfg.Parse([]string{"--config", "config_sharding.toml"})) // we change the config from config.toml to config_sharding.toml