From 147835840b776de36548a057eaef0af9943f8185 Mon Sep 17 00:00:00 2001 From: nolouch Date: Fri, 8 Jun 2018 15:38:37 +0800 Subject: [PATCH] address comments --- conf/config.toml | 2 ++ server/config.go | 24 +++++++++++++++--------- server/testutil.go | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/conf/config.toml b/conf/config.toml index 85e75edd400f..7154fc2bf8c9 100644 --- a/conf/config.toml +++ b/conf/config.toml @@ -19,6 +19,8 @@ tso-save-interval = "3s" namespace-classifier = "table" +pre-vote = true + [security] # Path of file that contains list of trusted SSL CAs. if set, following four settings shouldn't be empty cacert-path = "" diff --git a/server/config.go b/server/config.go index 5c29b0563187..b37476f098f8 100644 --- a/server/config.go +++ b/server/config.go @@ -93,11 +93,11 @@ type Config struct { TickInterval typeutil.Duration `toml:"tick-interval"` // ElectionInterval is the interval for etcd Raft election. ElectionInterval typeutil.Duration `toml:"election-interval"` - // DisablePrevote is true to disable Raft Pre-Vote. + // Prevote is true to enable Raft Pre-Vote. // If enabled, Raft runs an additional election phase // to check whether it would get enough votes to win // an election, thus minimizing disruptions. - DisablePreVote bool `json:"disable-pre-vote"` + PreVote bool `toml:"pre-vote"` Security SecurityConfig `toml:"security" json:"security"` @@ -224,8 +224,9 @@ func (c *Config) Parse(arguments []string) error { } // Load config file if specified. + var meta *toml.MetaData if c.configFile != "" { - err = c.configFromFile(c.configFile) + meta, err = c.configFromFile(c.configFile) if err != nil { return errors.Trace(err) } @@ -253,7 +254,7 @@ func (c *Config) Parse(arguments []string) error { return errors.Errorf("'%s' is an invalid flag", c.FlagSet.Arg(0)) } - err = c.adjust() + err = c.adjust(meta) return errors.Trace(err) } @@ -280,7 +281,7 @@ func (c *Config) validate() error { return nil } -func (c *Config) adjust() error { +func (c *Config) adjust(meta *toml.MetaData) error { adjustString(&c.Name, defaultName) adjustString(&c.DataDir, fmt.Sprintf("default.%s", c.Name)) @@ -338,6 +339,11 @@ func (c *Config) adjust() error { adjustDuration(&c.heartbeatStreamBindInterval, defaultHeartbeatStreamRebindInterval) adjustDuration(&c.leaderPriorityCheckInterval, defaultLeaderPriorityCheckInterval) + + // enable PreVote by default + if meta == nil || !meta.IsDefined("pre-vote") { + c.PreVote = true + } return nil } @@ -355,9 +361,9 @@ func (c *Config) String() string { } // configFromFile loads config from file. -func (c *Config) configFromFile(path string) error { - _, err := toml.DecodeFile(path, c) - return errors.Trace(err) +func (c *Config) configFromFile(path string) (*toml.MetaData, error) { + meta, err := toml.DecodeFile(path, c) + return &meta, errors.Trace(err) } // ScheduleConfig is the schedule configuration. @@ -634,7 +640,7 @@ func (c *Config) genEmbedEtcdConfig() (*embed.Config, error) { cfg.InitialCluster = c.InitialCluster cfg.ClusterState = c.InitialClusterState cfg.EnablePprof = true - cfg.PreVote = !c.DisablePreVote + cfg.PreVote = c.PreVote cfg.StrictReconfigCheck = !c.disableStrictReconfigCheck cfg.TickMs = uint(c.TickInterval.Duration / time.Millisecond) cfg.ElectionMs = uint(c.ElectionInterval.Duration / time.Millisecond) diff --git a/server/testutil.go b/server/testutil.go index 7301a797b416..213eba77976f 100644 --- a/server/testutil.go +++ b/server/testutil.go @@ -77,7 +77,7 @@ func NewTestSingleConfig() *Config { cfg.ElectionInterval = typeutil.NewDuration(3000 * time.Millisecond) cfg.leaderPriorityCheckInterval = typeutil.NewDuration(100 * time.Millisecond) - cfg.adjust() + cfg.adjust(nil) return cfg }