@@ -437,7 +437,12 @@ func (q querier) Select(ctx context.Context, sortSeries bool, sp *storage.Select
437
437
// we have all the sets from different sources (chunk from store, chunks from ingesters,
438
438
// time series from store and time series from ingesters).
439
439
// mergeSeriesSets will return sorted set.
440
- return q .mergeSeriesSets (result )
440
+ mergedSeriesSet , err := q .mergeSeriesSets (ctx , result )
441
+ if err != nil {
442
+ return storage .ErrSeriesSet (err )
443
+ } else {
444
+ return mergedSeriesSet
445
+ }
441
446
}
442
447
443
448
// LabelValues implements storage.Querier.
@@ -553,7 +558,7 @@ func (querier) Close() error {
553
558
return nil
554
559
}
555
560
556
- func (q querier ) mergeSeriesSets (sets []storage.SeriesSet ) storage.SeriesSet {
561
+ func (q querier ) mergeSeriesSets (ctx context. Context , sets []storage.SeriesSet ) ( storage.SeriesSet , error ) {
557
562
// Here we deal with sets that are based on chunks and build single set from them.
558
563
// Remaining sets are merged with chunks-based one using storage.NewMergeSeriesSet
559
564
@@ -565,6 +570,9 @@ func (q querier) mergeSeriesSets(sets []storage.SeriesSet) storage.SeriesSet {
565
570
566
571
// SeriesSet may have some series backed up by chunks, and some not.
567
572
for set .Next () {
573
+ if ctx .Err () != nil {
574
+ return nil , ctx .Err ()
575
+ }
568
576
s := set .At ()
569
577
570
578
if sc , ok := s .(SeriesWithChunks ); ok {
@@ -582,18 +590,18 @@ func (q querier) mergeSeriesSets(sets []storage.SeriesSet) storage.SeriesSet {
582
590
}
583
591
584
592
if len (chunks ) == 0 {
585
- return storage .NewMergeSeriesSet (otherSets , storage .ChainedSeriesMerge )
593
+ return storage .NewMergeSeriesSet (otherSets , storage .ChainedSeriesMerge ), nil
586
594
}
587
595
588
596
// partitionChunks returns set with sorted series, so it can be used by NewMergeSeriesSet
589
597
chunksSet := partitionChunks (chunks , q .mint , q .maxt , q .chunkIterFn )
590
598
591
599
if len (otherSets ) == 0 {
592
- return chunksSet
600
+ return chunksSet , nil
593
601
}
594
602
595
603
otherSets = append (otherSets , chunksSet )
596
- return storage .NewMergeSeriesSet (otherSets , storage .ChainedSeriesMerge )
604
+ return storage .NewMergeSeriesSet (otherSets , storage .ChainedSeriesMerge ), nil
597
605
}
598
606
599
607
type sliceSeriesSet struct {
0 commit comments