Skip to content

Commit

Permalink
fix data race of chunk reader stats
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Ye <[email protected]>
  • Loading branch information
yeya24 committed Aug 1, 2023
1 parent 3e727a0 commit 015df28
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions pkg/store/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -3214,9 +3214,14 @@ func (r *bucketChunkReader) load(ctx context.Context, res []seriesEntry, aggrs [
// loadChunks will read range [start, end] from the segment file with sequence number seq.
// This data range covers chunks starting at supplied offsets.
func (r *bucketChunkReader) loadChunks(ctx context.Context, res []seriesEntry, aggrs []storepb.Aggr, seq int, part Part, pIdxs []loadIdx, calculateChunkChecksum bool, bytesLimiter BytesLimiter) error {
var locked bool
fetchBegin := time.Now()
defer func() {
if !locked {
r.mtx.Lock()
}
r.stats.ChunksFetchDurationSum += time.Since(fetchBegin)
r.mtx.Unlock()
}()

// Get a reader for the required range.
Expand All @@ -3227,15 +3232,9 @@ func (r *bucketChunkReader) loadChunks(ctx context.Context, res []seriesEntry, a
defer runutil.CloseWithLogOnErr(r.block.logger, reader, "readChunkRange close range reader")
bufReader := bufio.NewReaderSize(reader, r.block.estimatedMaxChunkSize)

locked := true
locked = true
r.mtx.Lock()

defer func() {
if locked {
r.mtx.Unlock()
}
}()

r.stats.chunksFetchCount++
r.stats.chunksFetched += len(pIdxs)
r.stats.ChunksFetchedSizeSum += units.Base2Bytes(int(part.End - part.Start))
Expand Down

0 comments on commit 015df28

Please sign in to comment.