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