fix(peer): Pass peer server timeouts through factory

The peer's heartbeat and election timeouts are needed to build
the transporter in the factory method.
This commit is contained in:
Brian Waldon
2014-01-14 08:53:02 -08:00
parent 97f1363afa
commit 32df6f92fc
5 changed files with 15 additions and 25 deletions

View File

@@ -89,8 +89,8 @@ func NewConfig() *Config {
c.MaxRetryAttempts = 3
c.SnapshotCount = 10000
c.Peer.Addr = "127.0.0.1:7001"
c.Peer.HeartbeatTimeout = 0
c.Peer.ElectionTimeout = 0
c.Peer.HeartbeatTimeout = defaultHeartbeatTimeout
c.Peer.ElectionTimeout = defaultElectionTimeout
return c
}

View File

@@ -62,7 +62,7 @@ type snapshotConf struct {
snapshotThr uint64
}
func NewPeerServer(name string, path string, url string, bindAddr string, tlsConf *TLSConfig, tlsInfo *TLSInfo, registry *Registry, store store.Store, snapshotCount int) *PeerServer {
func NewPeerServer(name string, path string, url string, bindAddr string, tlsConf *TLSConfig, tlsInfo *TLSInfo, registry *Registry, store store.Store, snapshotCount int, heartbeatTimeout, electionTimeout time.Duration) *PeerServer {
s := &PeerServer{
name: name,
url: url,
@@ -85,8 +85,8 @@ func NewPeerServer(name string, path string, url string, bindAddr string, tlsCon
back: -1,
},
},
HeartbeatTimeout: defaultHeartbeatTimeout,
ElectionTimeout: defaultElectionTimeout,
HeartbeatTimeout: heartbeatTimeout,
ElectionTimeout: electionTimeout,
timeoutThresholdChan: make(chan interface{}, 1),
}

View File

@@ -1,13 +1,9 @@
package server
import (
"time"
)
const (
// The amount of time to elapse without a heartbeat before becoming a candidate
defaultElectionTimeout = 200 * time.Millisecond
// The amount of time (in ms) to elapse without a heartbeat before becoming a candidate
defaultElectionTimeout = 200
// The frequency by which heartbeats are sent to followers.
defaultHeartbeatTimeout = 50 * time.Millisecond
// The frequency (in ms) by which heartbeats are sent to followers.
defaultHeartbeatTimeout = 50
)