Skip to content

Commit

Permalink
store: fix a small house-keeping data race (thanos-io#1951)
Browse files Browse the repository at this point in the history
`stats` is being accessed from the goroutines inside this function so it
needs to be protected here in the same way with `mtx`. Move the house
keeping out of the inner loop into the outer one to reduce the number of
times we will need to lock/unlock the mutex.

Signed-off-by: Giedrius Statkevičius <[email protected]>
  • Loading branch information
GiedriusS authored Jan 7, 2020
1 parent a532ff6 commit 9c84435
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/store/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,12 +824,15 @@ func (s *BucketStore) Series(req *storepb.SeriesRequest, srv storepb.Store_Serie
}
blocks := bs.getFor(req.MinTime, req.MaxTime, req.MaxResolutionWindow)

mtx.Lock()
stats.blocksQueried += len(blocks)
mtx.Unlock()

if s.debugLogging {
debugFoundBlockSetOverview(s.logger, req.MinTime, req.MaxTime, req.MaxResolutionWindow, bs.labels, blocks)
}

for _, b := range blocks {
stats.blocksQueried++

b := b

Expand Down

0 comments on commit 9c84435

Please sign in to comment.