Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix data race of chunk reader stats #6578

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading