config: check the validity of the DDL lease (#14641)

This commit is contained in:
Lynn
2020-02-13 11:53:51 +08:00
committed by GitHub
parent 4755a9b9ef
commit 5778b50d0e
3 changed files with 26 additions and 9 deletions

View File

@ -741,6 +741,14 @@ func (c *Config) Load(confFile string) error {
return err
}
// MinDDLLease returns the minimum valid value of the DDL lease.
func (c *Config) MinDDLLease() time.Duration {
if c.Store == "tikv" {
return time.Second
}
return time.Duration(0)
}
// Valid checks if this config is valid.
func (c *Config) Valid() error {
if c.Log.EnableErrorStack == c.Log.DisableErrorStack && c.Log.EnableErrorStack != nbUnset {

View File

@ -19,6 +19,7 @@ import (
"path/filepath"
"runtime"
"testing"
"time"
"github.com/BurntSushi/toml"
. "github.com/pingcap/check"
@ -326,6 +327,11 @@ xkNuJ2BlEGkwWLiRbKy1lNBBFUXKuhh3L/EIY10WTnr3TQzeL6H1
c.Assert(tlsConfig, NotNil)
c.Assert(os.Remove(certFile), IsNil)
c.Assert(os.Remove(keyFile), IsNil)
// for MinDDLLease
c.Assert(conf.MinDDLLease(), Equals, time.Duration(0))
conf.Store = "tikv"
c.Assert(conf.MinDDLLease(), Equals, time.Second)
}
func (s *testConfigSuite) TestConfigDiff(c *C) {

View File

@ -268,9 +268,9 @@ func setupBinlogClient() {
}
if len(cfg.Binlog.BinlogSocket) == 0 {
client, err = pumpcli.NewPumpsClient(cfg.Path, cfg.Binlog.Strategy, parseDuration(cfg.Binlog.WriteTimeout), securityOption)
client, err = pumpcli.NewPumpsClient(cfg.Path, cfg.Binlog.Strategy, parseDuration(cfg.Binlog.WriteTimeout, 0), securityOption)
} else {
client, err = pumpcli.NewLocalPumpsClient(cfg.Path, cfg.Binlog.BinlogSocket, parseDuration(cfg.Binlog.WriteTimeout), securityOption)
client, err = pumpcli.NewLocalPumpsClient(cfg.Path, cfg.Binlog.BinlogSocket, parseDuration(cfg.Binlog.WriteTimeout, 0), securityOption)
}
terror.MustNil(err)
@ -320,13 +320,16 @@ func instanceName() string {
}
// parseDuration parses lease argument string.
func parseDuration(lease string) time.Duration {
func parseDuration(lease string, minVal time.Duration) time.Duration {
dur, err := time.ParseDuration(lease)
if err != nil {
dur, err = time.ParseDuration(lease + "s")
}
if err != nil || dur < 0 {
log.Fatal("invalid lease duration", zap.String("lease", lease))
if minVal < 0 {
minVal = 0
}
if err != nil || dur < minVal {
log.Fatal("invalid lease duration", zap.Duration("min value", minVal), zap.String("lease", lease))
}
return dur
}
@ -526,12 +529,12 @@ func overrideConfig() {
}
func setGlobalVars() {
ddlLeaseDuration := parseDuration(cfg.Lease)
ddlLeaseDuration := parseDuration(cfg.Lease, cfg.MinDDLLease())
session.SetSchemaLease(ddlLeaseDuration)
runtime.GOMAXPROCS(int(cfg.Performance.MaxProcs))
statsLeaseDuration := parseDuration(cfg.Performance.StatsLease)
statsLeaseDuration := parseDuration(cfg.Performance.StatsLease, 0)
session.SetStatsLease(statsLeaseDuration)
bindinfo.Lease = parseDuration(cfg.Performance.BindInfoLease)
bindinfo.Lease = parseDuration(cfg.Performance.BindInfoLease, 0)
domain.RunAutoAnalyze = cfg.Performance.RunAutoAnalyze
statistics.FeedbackProbability.Store(cfg.Performance.FeedbackProbability)
handle.MaxQueryFeedbackCount.Store(int64(cfg.Performance.QueryFeedbackLimit))
@ -573,7 +576,7 @@ func setGlobalVars() {
}
}
tikv.CommitMaxBackoff = int(parseDuration(cfg.TiKVClient.CommitTimeout).Seconds() * 1000)
tikv.CommitMaxBackoff = int(parseDuration(cfg.TiKVClient.CommitTimeout, 0).Seconds() * 1000)
tikv.RegionCacheTTLSec = int64(cfg.TiKVClient.RegionCacheTTL)
domainutil.RepairInfo.SetRepairMode(cfg.RepairMode)
domainutil.RepairInfo.SetRepairTableList(cfg.RepairTableList)