Skip to content

Commit

Permalink
Series Index Store: fix race in GetSeries (#10310)
Browse files Browse the repository at this point in the history
  • Loading branch information
bboreham authored Aug 23, 2023
1 parent 9734c4b commit cf353bb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
* [9773](https://github.com/grafana/loki/pull/9773) **ssncferreira**: Fix instant query summary statistic's `splits` corresponding to the number of subqueries a query is split into based on `split_queries_by_interval`.
* [9949](https://github.com/grafana/loki/pull/9949) **masslessparticle**: Fix pipelines to clear caches when tailing to avoid resource exhaustion.
* [9936](https://github.com/grafana/loki/pull/9936) **masslessparticle**: Fix the way query stages are reordered when `unpack` is present.
* [10309](https://github.com/grafana/loki/pull/10309) **akhilanarayanan**: Fix race condition in series index store.

##### Changes

Expand Down
8 changes: 6 additions & 2 deletions pkg/storage/stores/series/series_index_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func (c *indexReaderWriter) chunksToSeries(ctx context.Context, in []logproto.Ch
}))
}

results := make([]labels.Labels, 0, len(chunksBySeries))
perJobResults := make([][]labels.Labels, len(jobs))

// Picking an arbitrary bound of 20 numConcurrent jobs.
numConcurrent := len(jobs)
Expand All @@ -294,14 +294,18 @@ func (c *indexReaderWriter) chunksToSeries(ctx context.Context, in []logproto.Ch
func(_ context.Context, idx int) error {
res, err := jobs[idx]()
if res != nil {
results = append(results, res...)
perJobResults[idx] = res
}
return err
},
); err != nil {
return nil, err
}

results := make([]labels.Labels, len(chunksBySeries)) // Flatten out the per-job results.
for _, innerSlice := range perJobResults {
results = append(results, innerSlice...)
}
sort.Slice(results, func(i, j int) bool {
return labels.Compare(results[i], results[j]) < 0
})
Expand Down

0 comments on commit cf353bb

Please sign in to comment.