Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nolouch committed Jun 8, 2018
1 parent 5d82e7c commit 1478358
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 2 additions & 0 deletions conf/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down
24 changes: 15 additions & 9 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}

Expand All @@ -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))

Expand Down Expand Up @@ -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
}

Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion server/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 1478358

Please sign in to comment.