mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
stats: fix data race when recording send result
This commit is contained in:
parent
da2ee9a90c
commit
eb72bdc3d2
@ -2,6 +2,7 @@ package stats
|
||||
|
||||
import (
|
||||
"math"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -36,10 +37,15 @@ type FollowerStats struct {
|
||||
Fail uint64 `json:"fail"`
|
||||
Success uint64 `json:"success"`
|
||||
} `json:"counts"`
|
||||
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
// Succ updates the FollowerStats with a successful send
|
||||
func (fs *FollowerStats) Succ(d time.Duration) {
|
||||
fs.Lock()
|
||||
defer fs.Unlock()
|
||||
|
||||
total := float64(fs.Counts.Success) * fs.Latency.Average
|
||||
totalSquare := float64(fs.Counts.Success) * fs.Latency.averageSquare
|
||||
|
||||
@ -64,5 +70,7 @@ func (fs *FollowerStats) Succ(d time.Duration) {
|
||||
|
||||
// Fail updates the FollowerStats with an unsuccessful send
|
||||
func (fs *FollowerStats) Fail() {
|
||||
fs.Lock()
|
||||
defer fs.Unlock()
|
||||
fs.Counts.Fail++
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user