fix remove node

This commit is contained in:
Xiang Li
2013-08-19 19:07:18 -07:00
parent e4b164c324
commit d8cd744f2f
4 changed files with 23 additions and 11 deletions

View File

@@ -195,7 +195,7 @@ func (c *RemoveCommand) Apply(raftServer *raft.Server) (interface{}, error) {
key := path.Join("_etcd/machines", c.Name)
_, err := etcdStore.Delete(key, raftServer.CommitIndex())
r.peersStats[c.Name] = nil
delete(r.peersStats, c.Name)
if err != nil {
return []byte{0}, err

View File

@@ -269,6 +269,11 @@ func joinByMachine(s *raft.Server, machine string, scheme string) error {
return fmt.Errorf("Unable to join: %v", err)
}
func (r *raftServer) Stats() []byte {
b, _ := json.Marshal(r.peersStats)
return b
}
// Register commands to raft server
func registerCommands() {
raft.RegisterCommand(&JoinCommand{})

View File

@@ -1,7 +1,7 @@
package main
import (
"encoding/json"
"time"
)
type peerStats struct {
@@ -11,7 +11,13 @@ type peerStats struct {
SuccCnt uint64 `json:"successCount"`
}
func (r *raftServer) Stats() []byte {
b, _ := json.Marshal(r.peersStats)
return b
func (ps *peerStats) Fail() {
ps.FailCnt++
}
func (ps *peerStats) Succ(d time.Duration) {
total := float64(ps.SuccCnt) * ps.AvgLatency
ps.SuccCnt++
ps.Latency = float64(d) / (1000000.0)
ps.AvgLatency = (total + ps.Latency) / float64(ps.SuccCnt)
}

View File

@@ -52,7 +52,7 @@ func (t transporter) SendAppendEntriesRequest(server *raft.Server, peer *raft.Pe
u, _ := nameToRaftURL(peer.Name)
debugf("Send LogEntries to %s ", u)
thisPeerStats := r.peersStats[peer.Name]
thisPeerStats, ok := r.peersStats[peer.Name]
start := time.Now()
@@ -62,12 +62,13 @@ func (t transporter) SendAppendEntriesRequest(server *raft.Server, peer *raft.Pe
if err != nil {
debugf("Cannot send AppendEntriesRequest to %s: %s", u, err)
thisPeerStats.FailCnt++
if ok {
thisPeerStats.Fail()
}
} else {
total := float64(thisPeerStats.SuccCnt) * thisPeerStats.AvgLatency
thisPeerStats.SuccCnt++
thisPeerStats.Latency = float64(end.Sub(start)) / (1000000.0)
thisPeerStats.AvgLatency = (total + thisPeerStats.Latency) / float64(thisPeerStats.SuccCnt)
if ok {
thisPeerStats.Succ(end.Sub(start))
}
}
r.peersStats[peer.Name] = thisPeerStats