mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver: fix data race in leaderStats.Followers
This commit is contained in:
parent
da2ee9a90c
commit
782d91f2d9
@ -149,12 +149,7 @@ func send(c *http.Client, cls ClusterStore, m raftpb.Message, ss *stats.ServerSt
|
|||||||
ss.SendAppendReq(len(data))
|
ss.SendAppendReq(len(data))
|
||||||
}
|
}
|
||||||
to := strconv.FormatUint(m.To, 16)
|
to := strconv.FormatUint(m.To, 16)
|
||||||
fs, ok := ls.Followers[to]
|
fs := ls.Follower(to)
|
||||||
if !ok {
|
|
||||||
fs = &stats.FollowerStats{}
|
|
||||||
fs.Latency.Minimum = 1 << 63
|
|
||||||
ls.Followers[to] = fs
|
|
||||||
}
|
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
sent := httpPost(c, u, data)
|
sent := httpPost(c, u, data)
|
||||||
|
@ -11,6 +11,8 @@ type LeaderStats struct {
|
|||||||
// TODO(jonboulle): clarify that these are IDs, not names
|
// TODO(jonboulle): clarify that these are IDs, not names
|
||||||
Leader string `json:"leader"`
|
Leader string `json:"leader"`
|
||||||
Followers map[string]*FollowerStats `json:"followers"`
|
Followers map[string]*FollowerStats `json:"followers"`
|
||||||
|
|
||||||
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLeaderStats generates a new LeaderStats with the given id as leader
|
// NewLeaderStats generates a new LeaderStats with the given id as leader
|
||||||
@ -21,6 +23,18 @@ func NewLeaderStats(id string) *LeaderStats {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ls *LeaderStats) Follower(name string) *FollowerStats {
|
||||||
|
ls.Lock()
|
||||||
|
defer ls.Unlock()
|
||||||
|
fs, ok := ls.Followers[name]
|
||||||
|
if !ok {
|
||||||
|
fs = &FollowerStats{}
|
||||||
|
fs.Latency.Minimum = 1 << 63
|
||||||
|
ls.Followers[name] = fs
|
||||||
|
}
|
||||||
|
return fs
|
||||||
|
}
|
||||||
|
|
||||||
// FollowerStats encapsulates various statistics about a follower in an etcd cluster
|
// FollowerStats encapsulates various statistics about a follower in an etcd cluster
|
||||||
type FollowerStats struct {
|
type FollowerStats struct {
|
||||||
Latency struct {
|
Latency struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user