From 0867b33de50c39b4c6dc0ec328f496a9b90c0342 Mon Sep 17 00:00:00 2001 From: Neil Dunbar Date: Thu, 5 Dec 2013 09:23:23 +0000 Subject: [PATCH] fix(Dockerfile): reverted unneeded changes fix(server/config.go): ensured params are changeable from config file and env fix(server/server.go): removed unnecessary debug line fix(server/timeout.go): removed a commented block style(server/transporter.go): put explicit vars to replace timeout expressions style(tests/server_utils.go): ran gofmt to clean up indenting --- Dockerfile | 2 +- server/config.go | 10 ++++++---- server/server.go | 1 - server/timeout.go | 8 +------- server/transporter.go | 8 ++++++-- tests/server_utils.go | 10 +++++----- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index afcf0afcc..8b549a465 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,4 +7,4 @@ RUN apt-get install -y golang ADD . /opt/etcd RUN cd /opt/etcd && ./build EXPOSE 4001 7001 -ENTRYPOINT ["/datastore/start.sh"] +ENTRYPOINT ["/opt/etcd/etcd", "-addr", "0.0.0.0:4001", "-bind-addr", "0.0.0.0"] \ No newline at end of file diff --git a/server/config.go b/server/config.go index 4ec26b876..a8ce8d44b 100644 --- a/server/config.go +++ b/server/config.go @@ -67,8 +67,8 @@ type Config struct { ShowVersion bool Verbose bool `toml:"verbose" env:"ETCD_VERBOSE"` VeryVerbose bool `toml:"very_verbose" env:"ETCD_VERY_VERBOSE"` - HeartbeatTimeout int - ElectionTimeout int + HeartbeatTimeout int `toml:"peer_heartbeat_timeout" env:"ETCD_PEER_HEARTBEAT_TIMEOUT"` + ElectionTimeout int `toml:"peer_election_timeout" env:"ETCD_PEER_ELECTION_TIMEOUT"` Peer struct { Addr string `toml:"addr" env:"ETCD_PEER_ADDR"` BindAddr string `toml:"bind_addr" env:"ETCD_PEER_BIND_ADDR"` @@ -88,6 +88,8 @@ func NewConfig() *Config { c.MaxRetryAttempts = 3 c.Peer.Addr = "127.0.0.1:7001" c.SnapshotCount = 10000 + c.HeartbeatTimeout = HeartbeatTimeout + c.ElectionTimeout = ElectionTimeout return c } @@ -229,8 +231,8 @@ func (c *Config) LoadFlags(arguments []string) error { f.IntVar(&c.MaxResultBuffer, "max-result-buffer", c.MaxResultBuffer, "") f.IntVar(&c.MaxRetryAttempts, "max-retry-attempts", c.MaxRetryAttempts, "") f.IntVar(&c.MaxClusterSize, "max-cluster-size", c.MaxClusterSize, "") - f.IntVar(&c.HeartbeatTimeout, "peer-heartbeat-timeout", HeartbeatTimeout, "") - f.IntVar(&c.ElectionTimeout, "peer-election-timeout", ElectionTimeout, "") + f.IntVar(&c.HeartbeatTimeout, "peer-heartbeat-timeout", c.HeartbeatTimeout, "") + f.IntVar(&c.ElectionTimeout, "peer-election-timeout", c.ElectionTimeout, "") f.StringVar(&cors, "cors", "", "") diff --git a/server/server.go b/server/server.go index 58b0f642d..00c39227a 100644 --- a/server/server.go +++ b/server/server.go @@ -227,7 +227,6 @@ func (s *Server) listenAndServeTLS(certFile, keyFile string) error { tlsListener := tls.NewListener(conn, config) s.listener = tlsListener - log.Debugf("etcd listening using tls key %s, cert %s", keyFile, certFile) return s.Server.Serve(tlsListener) } diff --git a/server/timeout.go b/server/timeout.go index 2838354b0..892168b13 100644 --- a/server/timeout.go +++ b/server/timeout.go @@ -1,16 +1,10 @@ package server -// import ( -// "time" -// ) - const ( - // The amount of time to elapse without a heartbeat before becoming a candidate. - // ElectionTimeout = 200 * time.Millisecond + // The amount of time (ms) to elapse without a heartbeat before becoming a candidate. ElectionTimeout = 200 // The frequency by which heartbeats are sent to followers. - //HeartbeatTimeout = 50 * time.Millisecond HeartbeatTimeout = 50 RetryInterval = 10 diff --git a/server/transporter.go b/server/transporter.go index 6616e08ed..7cf8f9f04 100644 --- a/server/transporter.go +++ b/server/transporter.go @@ -27,13 +27,17 @@ type dialer func(network, addr string) (net.Conn, error) // Create http or https transporter based on // whether the user give the server cert and key func newTransporter(scheme string, tlsConf tls.Config, peerServer *PeerServer) *transporter { + // names for each type of timeout, for the sake of clarity + dialTimeout := time.Duration(3 * peerServer.heartbeatTimeout + peerServer.electionTimeout) * time.Millisecond + responseHeaderTimeout := time.Duration(3 * peerServer.heartbeatTimeout + peerServer.electionTimeout) * time.Millisecond + t := transporter{} t.tranTimeout = time.Duration(peerServer.heartbeatTimeout) * time.Millisecond tr := &http.Transport{ - Dial: dialWithTimeoutFactory( time.Duration(3 * peerServer.heartbeatTimeout + peerServer.electionTimeout) * time.Millisecond), - ResponseHeaderTimeout: time.Duration(3 * peerServer.heartbeatTimeout + peerServer.electionTimeout) * time.Millisecond, + Dial: dialWithTimeoutFactory(dialTimeout), + ResponseHeaderTimeout: responseHeaderTimeout, } if scheme == "https" { diff --git a/tests/server_utils.go b/tests/server_utils.go index 78df037ba..84588efea 100644 --- a/tests/server_utils.go +++ b/tests/server_utils.go @@ -10,12 +10,12 @@ import ( ) const ( - testName = "ETCDTEST" - testClientURL = "localhost:4401" - testRaftURL = "localhost:7701" - testSnapshotCount = 10000 + testName = "ETCDTEST" + testClientURL = "localhost:4401" + testRaftURL = "localhost:7701" + testSnapshotCount = 10000 testHeartbeatTimeout = 50 - testElectionTimeout = 200 + testElectionTimeout = 200 ) // Starts a server in a temporary directory.