Browse Source

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

Neil Dunbar 12 years ago
parent
commit
0867b33de5
6 changed files with 19 additions and 20 deletions
  1. 1 1
      Dockerfile
  2. 6 4
      server/config.go
  3. 0 1
      server/server.go
  4. 1 7
      server/timeout.go
  5. 6 2
      server/transporter.go
  6. 5 5
      tests/server_utils.go

+ 1 - 1
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"]

+ 6 - 4
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", "", "")
 

+ 0 - 1
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)
 }
 

+ 1 - 7
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

+ 6 - 2
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" {

+ 5 - 5
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.