mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
fix remove node
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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{})
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user