init peerStats in transportation.go; avoid nil pointer due to restart from snapshot(we do not keep stats in persistentlayer yet)

This commit is contained in:
Xiang Li 2013-09-22 11:20:08 -04:00
parent 24b34d0a1e
commit a8ff1b27d4
2 changed files with 6 additions and 7 deletions

View File

@ -170,10 +170,6 @@ func (c *JoinCommand) Apply(raftServer *raft.Server) (interface{}, error) {
value := fmt.Sprintf("raft=%s&etcd=%s&raftVersion=%s", c.RaftURL, c.EtcdURL, c.RaftVersion)
etcdStore.Set(key, value, time.Unix(0, 0), raftServer.CommitIndex())
if c.Name != r.Name() {
r.peersStats[c.Name] = &raftPeerStats{MinLatency: 1 << 63}
}
return b, err
}

View File

@ -68,6 +68,11 @@ func (t *transporter) SendAppendEntriesRequest(server *raft.Server, peer *raft.P
thisPeerStats, ok := r.peersStats[peer.Name]
if !ok { // we first see this peer
thisPeerStats = &raftPeerStats{MinLatency: 1 << 63}
r.peersStats[peer.Name] = thisPeerStats
}
start := time.Now()
resp, err := t.Post(fmt.Sprintf("%s/log/append", u), &b)
@ -85,8 +90,6 @@ func (t *transporter) SendAppendEntriesRequest(server *raft.Server, peer *raft.P
}
}
r.peersStats[peer.Name] = thisPeerStats
if resp != nil {
defer resp.Body.Close()
aersp = &raft.AppendEntriesResponse{}
@ -211,7 +214,7 @@ func (t *transporter) Get(path string) (*http.Response, error) {
func (t *transporter) waitResponse(responseChan chan *transporterResponse) (*http.Response, error) {
timeoutChan := time.After(t.timeout)
timeoutChan := time.After(t.timeout * 10)
select {
case <-timeoutChan: