Skip to content

Commit 815aa51

Browse files
bborehamgrafana-delivery-bot[bot]
authored andcommitted
Series Index Store: fix race in GetSeries (#10310)
(cherry picked from commit cf353bb)
1 parent 70bfc98 commit 815aa51

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
* [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`.
7474
* [9949](https://github.com/grafana/loki/pull/9949) **masslessparticle**: Fix pipelines to clear caches when tailing to avoid resource exhaustion.
7575
* [9936](https://github.com/grafana/loki/pull/9936) **masslessparticle**: Fix the way query stages are reordered when `unpack` is present.
76+
* [10309](https://github.com/grafana/loki/pull/10309) **akhilanarayanan**: Fix race condition in series index store.
7677

7778
##### Changes
7879

pkg/storage/stores/series/series_index_store.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func (c *indexReaderWriter) chunksToSeries(ctx context.Context, in []logproto.Ch
279279
}))
280280
}
281281

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

284284
// Picking an arbitrary bound of 20 numConcurrent jobs.
285285
numConcurrent := len(jobs)
@@ -294,14 +294,18 @@ func (c *indexReaderWriter) chunksToSeries(ctx context.Context, in []logproto.Ch
294294
func(_ context.Context, idx int) error {
295295
res, err := jobs[idx]()
296296
if res != nil {
297-
results = append(results, res...)
297+
perJobResults[idx] = res
298298
}
299299
return err
300300
},
301301
); err != nil {
302302
return nil, err
303303
}
304304

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

0 commit comments

Comments
 (0)