diff --git a/config/config.go b/config/config.go index b30774102..58a97e1c1 100644 --- a/config/config.go +++ b/config/config.go @@ -64,6 +64,7 @@ type Config struct { MaxClusterSize int `toml:"max_cluster_size" env:"ETCD_MAX_CLUSTER_SIZE"` MaxResultBuffer int `toml:"max_result_buffer" env:"ETCD_MAX_RESULT_BUFFER"` MaxRetryAttempts int `toml:"max_retry_attempts" env:"ETCD_MAX_RETRY_ATTEMPTS"` + RetryInterval float64 `toml:"retry_interval" env:"ETCD_RETRY_INTERVAL"` Name string `toml:"name" env:"ETCD_NAME"` Snapshot bool `toml:"snapshot" env:"ETCD_SNAPSHOT"` SnapshotCount int `toml:"snapshot_count" env:"ETCD_SNAPSHOTCOUNT"` @@ -93,6 +94,7 @@ func New() *Config { c.MaxClusterSize = 9 c.MaxResultBuffer = 1024 c.MaxRetryAttempts = 3 + c.RetryInterval = 10.0 c.Snapshot = true c.SnapshotCount = 10000 c.Peer.Addr = "127.0.0.1:7001" @@ -282,6 +284,7 @@ func (c *Config) LoadFlags(arguments []string) error { f.StringVar(&c.DataDir, "data-dir", c.DataDir, "") f.IntVar(&c.MaxResultBuffer, "max-result-buffer", c.MaxResultBuffer, "") f.IntVar(&c.MaxRetryAttempts, "max-retry-attempts", c.MaxRetryAttempts, "") + f.Float64Var(&c.RetryInterval, "retry-interval", c.RetryInterval, "") f.IntVar(&c.MaxClusterSize, "max-cluster-size", c.MaxClusterSize, "") f.IntVar(&c.Peer.HeartbeatTimeout, "peer-heartbeat-timeout", c.Peer.HeartbeatTimeout, "") f.IntVar(&c.Peer.ElectionTimeout, "peer-election-timeout", c.Peer.ElectionTimeout, "") diff --git a/etcd.go b/etcd.go index 7055fcabf..c66df13ef 100644 --- a/etcd.go +++ b/etcd.go @@ -122,6 +122,7 @@ func main() { SnapshotCount: config.SnapshotCount, MaxClusterSize: config.MaxClusterSize, RetryTimes: config.MaxRetryAttempts, + RetryInterval: config.RetryInterval, } ps := server.NewPeerServer(psConfig, registry, store, &mb, followersStats, serverStats) diff --git a/server/peer_server.go b/server/peer_server.go index 38b0e1f02..d8481cf87 100644 --- a/server/peer_server.go +++ b/server/peer_server.go @@ -20,17 +20,16 @@ import ( "github.com/coreos/etcd/store" ) -const retryInterval = 10 - const ThresholdMonitorTimeout = 5 * time.Second type PeerServerConfig struct { - Name string - Scheme string - URL string - SnapshotCount int - MaxClusterSize int - RetryTimes int + Name string + Scheme string + URL string + SnapshotCount int + MaxClusterSize int + RetryTimes int + RetryInterval float64 } type PeerServer struct { @@ -209,8 +208,8 @@ func (s *PeerServer) startAsFollower(cluster []string) { if ok { return } - log.Warnf("Unable to join the cluster using any of the peers %v. Retrying in %d seconds", cluster, retryInterval) - time.Sleep(time.Second * retryInterval) + log.Warnf("Unable to join the cluster using any of the peers %v. Retrying in %.1f seconds", cluster, s.Config.RetryInterval) + time.Sleep(time.Second * time.Duration(s.Config.RetryInterval)) } log.Fatalf("Cannot join the cluster via given peers after %x retries", s.Config.RetryTimes) diff --git a/server/usage.go b/server/usage.go index 4e47512c5..bf55dcc67 100644 --- a/server/usage.go +++ b/server/usage.go @@ -52,6 +52,7 @@ Peer Communication Options: Other Options: -max-result-buffer Max size of the result buffer. -max-retry-attempts Number of times a node will try to join a cluster. + -retry-interval Seconds to wait between cluster join retry attempts. -max-cluster-size Maximum number of nodes in the cluster. -snapshot=false Disable log snapshots -snapshot-count Number of transactions before issuing a snapshot.