From 1fd64f984b422923f6b5ce06ebe82bb0f855c4dc Mon Sep 17 00:00:00 2001 From: John Shahid Date: Mon, 24 Mar 2014 14:41:32 -0400 Subject: [PATCH] make the raft election timeout configurable --- config.toml.sample | 2 ++ src/configuration/config.toml | 2 ++ src/configuration/configuration.go | 11 +++++++++-- src/configuration/configuration_test.go | 1 + src/coordinator/raft_server.go | 2 +- 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/config.toml.sample b/config.toml.sample index a2ae77610e..d479ccea20 100644 --- a/config.toml.sample +++ b/config.toml.sample @@ -41,6 +41,8 @@ port = 8090 # Where the raft logs are stored. The user running InfluxDB will need read/write access. dir = "/tmp/influxdb/development/raft" +# election-timeout = "1s" + [storage] dir = "/tmp/influxdb/development/db" # How many requests to potentially buffer in memory. If the buffer gets filled then writes diff --git a/src/configuration/config.toml b/src/configuration/config.toml index 9126d51497..2ac47586f6 100644 --- a/src/configuration/config.toml +++ b/src/configuration/config.toml @@ -38,6 +38,8 @@ port = 8090 # Where the raft logs are stored. The user running InfluxDB will need read/write access. dir = "/tmp/influxdb/development/raft" +# election-timeout = "2s" + [storage] dir = "/tmp/influxdb/development/db" # How many requests to potentially buffer in memory. If the buffer gets filled then writes diff --git a/src/configuration/configuration.go b/src/configuration/configuration.go index a2bb52e30a..376f0ceaf0 100644 --- a/src/configuration/configuration.go +++ b/src/configuration/configuration.go @@ -69,8 +69,9 @@ type GraphiteConfig struct { } type RaftConfig struct { - Port int - Dir string + Port int + Dir string + Timeout duration `toml:"election-timeout"` } type StorageConfig struct { @@ -189,6 +190,7 @@ type Configuration struct { GraphitePort int GraphiteDatabase string RaftServerPort int + RaftTimeout duration SeedServers []string DataDir string RaftDir string @@ -257,6 +259,10 @@ func parseTomlConfiguration(filename string) (*Configuration, error) { defaultQueryShardBufferSize = tomlConfiguration.Cluster.QueryShardBufferSize } + if tomlConfiguration.Raft.Timeout.Duration == 0 { + tomlConfiguration.Raft.Timeout = duration{time.Second} + } + config := &Configuration{ AdminHttpPort: tomlConfiguration.Admin.Port, AdminAssetsDir: tomlConfiguration.Admin.Assets, @@ -267,6 +273,7 @@ func parseTomlConfiguration(filename string) (*Configuration, error) { GraphitePort: tomlConfiguration.InputPlugins.Graphite.Port, GraphiteDatabase: tomlConfiguration.InputPlugins.Graphite.Database, RaftServerPort: tomlConfiguration.Raft.Port, + RaftTimeout: tomlConfiguration.Raft.Timeout, RaftDir: tomlConfiguration.Raft.Dir, ProtobufPort: tomlConfiguration.Cluster.ProtobufPort, ProtobufTimeout: tomlConfiguration.Cluster.ProtobufTimeout, diff --git a/src/configuration/configuration_test.go b/src/configuration/configuration_test.go index 2adcbece0c..28a4827dbf 100644 --- a/src/configuration/configuration_test.go +++ b/src/configuration/configuration_test.go @@ -40,6 +40,7 @@ func (self *LoadConfigurationSuite) TestConfig(c *C) { c.Assert(config.RaftDir, Equals, "/tmp/influxdb/development/raft") c.Assert(config.RaftServerPort, Equals, 8090) + c.Assert(config.RaftTimeout.Duration, Equals, time.Second) c.Assert(config.DataDir, Equals, "/tmp/influxdb/development/db") diff --git a/src/coordinator/raft_server.go b/src/coordinator/raft_server.go index fa7db2e6a8..a64784e6fe 100644 --- a/src/coordinator/raft_server.go +++ b/src/coordinator/raft_server.go @@ -327,7 +327,7 @@ func (s *RaftServer) startRaft() error { return err } - s.raftServer.SetElectionTimeout(time.Second) + s.raftServer.SetElectionTimeout(s.config.RaftTimeout.Duration) s.raftServer.LoadSnapshot() // ignore errors s.raftServer.AddEventListener(raft.StateChangeEventType, s.raftEventHandler)