mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-17 11:24:44 -07:00
Use atomic.Load to access fields used in /varz and /subsz requests.
* Includes a unit test that checks all endpoints for data races.
This commit is contained in:
@@ -473,11 +473,11 @@ func (s *Server) HandleVarz(w http.ResponseWriter, r *http.Request) {
|
||||
v.TotalConnections = s.totalClients
|
||||
v.Routes = len(s.routes)
|
||||
v.Remotes = len(s.remotes)
|
||||
v.InMsgs = s.inMsgs
|
||||
v.InBytes = s.inBytes
|
||||
v.OutMsgs = s.outMsgs
|
||||
v.OutBytes = s.outBytes
|
||||
v.SlowConsumers = s.slowConsumers
|
||||
v.InMsgs = atomic.LoadInt64(&s.inMsgs)
|
||||
v.InBytes = atomic.LoadInt64(&s.inBytes)
|
||||
v.OutMsgs = atomic.LoadInt64(&s.outMsgs)
|
||||
v.OutBytes = atomic.LoadInt64(&s.outBytes)
|
||||
v.SlowConsumers = atomic.LoadInt64(&s.slowConsumers)
|
||||
v.Subscriptions = s.sl.Count()
|
||||
s.httpReqStats[VarzPath]++
|
||||
// Need a copy here since s.httpReqStas can change while doing
|
||||
|
||||
@@ -503,11 +503,11 @@ func (s *Sublist) Stats() *SublistStats {
|
||||
st := &SublistStats{}
|
||||
st.NumSubs = s.count
|
||||
st.NumCache = uint32(len(s.cache))
|
||||
st.NumInserts = s.inserts
|
||||
st.NumRemoves = s.removes
|
||||
st.NumMatches = s.matches
|
||||
if s.matches > 0 {
|
||||
st.CacheHitRate = float64(s.cacheHits) / float64(s.matches)
|
||||
st.NumInserts = atomic.LoadUint64(&s.inserts)
|
||||
st.NumRemoves = atomic.LoadUint64(&s.removes)
|
||||
st.NumMatches = atomic.LoadUint64(&s.matches)
|
||||
if st.NumMatches > 0 {
|
||||
st.CacheHitRate = float64(atomic.LoadUint64(&s.cacheHits)) / float64(st.NumMatches)
|
||||
}
|
||||
// whip through cache for fanout stats
|
||||
tot, max := 0, 0
|
||||
|
||||
Reference in New Issue
Block a user