Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: enable prevote by default #1103

Merged
merged 4 commits into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"

enable-prevote = 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: 18 additions & 6 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +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"`
// 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.
PreVote bool `toml:"enable-prevote"`

Security SecurityConfig `toml:"security" json:"security"`

Expand Down Expand Up @@ -219,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 @@ -248,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 @@ -275,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 @@ -333,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("enable-prevote") {
c.PreVote = true
}
return nil
}

Expand All @@ -350,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 @@ -629,6 +640,7 @@ func (c *Config) genEmbedEtcdConfig() (*embed.Config, error) {
cfg.InitialCluster = c.InitialCluster
cfg.ClusterState = c.InitialClusterState
cfg.EnablePprof = true
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
4 changes: 2 additions & 2 deletions server/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (s *testConfigSuite) TestTLS(c *C) {
func (s *testConfigSuite) TestBadFormatJoinAddr(c *C) {
cfg := NewTestSingleConfig()
cfg.Join = "127.0.0.1:2379" // Wrong join addr without scheme.
c.Assert(cfg.adjust(), NotNil)
c.Assert(cfg.adjust(nil), NotNil)
}

func (s *testConfigSuite) TestReloadConfig(c *C) {
Expand Down Expand Up @@ -62,7 +62,7 @@ func (s *testConfigSuite) TestReloadConfig(c *C) {

func (s *testConfigSuite) TestValidation(c *C) {
cfg := NewConfig()
c.Assert(cfg.adjust(), IsNil)
c.Assert(cfg.adjust(nil), IsNil)

cfg.Log.File.Filename = path.Join(cfg.DataDir, "test")
c.Assert(cfg.validate(), NotNil)
Expand Down
2 changes: 1 addition & 1 deletion server/coordinator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func newTestOperator(regionID uint64, regionEpoch *metapb.RegionEpoch, kind sche

func newTestScheduleConfig() (*ScheduleConfig, *scheduleOption) {
cfg := NewConfig()
cfg.adjust()
cfg.adjust(nil)
opt := newScheduleOption(cfg)
return &cfg.Schedule, opt
}
Expand Down
2 changes: 1 addition & 1 deletion server/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func startPdWith(cfg *Config) (*Server, error) {
abortCh := make(chan struct{}, 1)

go func() {
err := cfg.adjust()
err := cfg.adjust(nil)
if err != nil {
errCh <- errors.Trace(err)
return
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