Skip to content

Commit 10f2c5f

Browse files
akhilanarayananbboreham
authored andcommitted
Series Index Store: fix race in GetSeries
Collect the individual results per-job in a slice of slices, then flatten them out when all jobs are finished.
1 parent 9734c4b commit 10f2c5f

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
@@ -77,6 +77,7 @@
7777
* [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`.
7878
* [9949](https://github.com/grafana/loki/pull/9949) **masslessparticle**: Fix pipelines to clear caches when tailing to avoid resource exhaustion.
7979
* [9936](https://github.com/grafana/loki/pull/9936) **masslessparticle**: Fix the way query stages are reordered when `unpack` is present.
80+
* [10309](https://github.com/grafana/loki/pull/10309) **bboreham**: Fix race condition in series index store.
8081

8182
##### Changes
8283

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)