@@ -356,7 +356,7 @@ func (q *parquetQuerierWithFallback) LabelNames(ctx context.Context, hints *stor
356
356
return result , rAnnotations , nil
357
357
}
358
358
359
- func (q * parquetQuerierWithFallback ) Select (ctx context.Context , sortSeries bool , hints * storage.SelectHints , matchers ... * labels.Matcher ) storage.SeriesSet {
359
+ func (q * parquetQuerierWithFallback ) Select (ctx context.Context , sortSeries bool , h * storage.SelectHints , matchers ... * labels.Matcher ) storage.SeriesSet {
360
360
userID , err := tenant .TenantID (ctx )
361
361
if err != nil {
362
362
storage .ErrSeriesSet (err )
@@ -366,68 +366,99 @@ func (q *parquetQuerierWithFallback) Select(ctx context.Context, sortSeries bool
366
366
uLogger := util_log .WithUserID (userID , q .logger )
367
367
level .Warn (uLogger ).Log ("msg" , "parquet queryable enabled but vertical sharding > 1. Falling back to the block storage" )
368
368
369
- return q .blocksStoreQuerier .Select (ctx , sortSeries , hints , matchers ... )
369
+ return q .blocksStoreQuerier .Select (ctx , sortSeries , h , matchers ... )
370
370
}
371
371
372
- mint , maxt , limit := q .minT , q .maxT , 0
372
+ hints := storage.SelectHints {
373
+ Start : q .minT ,
374
+ End : q .maxT ,
375
+ }
373
376
374
- if hints != nil {
377
+ mint , maxt , limit := q .minT , q .maxT , 0
378
+ if h != nil {
379
+ // let copy the hints here as we wanna potentially modify it
380
+ hints = * h
375
381
mint , maxt , limit = hints .Start , hints .End , hints .Limit
376
382
}
377
383
384
+ maxt = q .adjustMaxT (maxt )
385
+ hints .End = maxt
386
+
387
+ if maxt < mint {
388
+ return nil
389
+ }
390
+
378
391
remaining , parquet , err := q .getBlocks (ctx , mint , maxt )
379
392
if err != nil {
380
393
return storage .ErrSeriesSet (err )
381
394
}
382
395
383
- serieSets := []storage.SeriesSet {}
384
-
385
396
// Lets sort the series to merge
386
397
if len (parquet ) > 0 && len (remaining ) > 0 {
387
398
sortSeries = true
388
399
}
389
400
401
+ promises := make ([]chan storage.SeriesSet , 0 , 2 )
402
+
390
403
if len (parquet ) > 0 {
391
- serieSets = append (serieSets , q .parquetQuerier .Select (InjectBlocksIntoContext (ctx , parquet ... ), sortSeries , hints , matchers ... ))
404
+ p := make (chan storage.SeriesSet , 1 )
405
+ promises = append (promises , p )
406
+ go func () {
407
+ p <- q .parquetQuerier .Select (InjectBlocksIntoContext (ctx , parquet ... ), sortSeries , & hints , matchers ... )
408
+ }()
392
409
}
393
410
394
411
if len (remaining ) > 0 {
395
- serieSets = append (serieSets , q .blocksStoreQuerier .Select (InjectBlocksIntoContext (ctx , remaining ... ), sortSeries , hints , matchers ... ))
412
+ p := make (chan storage.SeriesSet , 1 )
413
+ promises = append (promises , p )
414
+ go func () {
415
+ p <- q .blocksStoreQuerier .Select (InjectBlocksIntoContext (ctx , remaining ... ), sortSeries , & hints , matchers ... )
416
+ }()
396
417
}
397
418
398
- if len (serieSets ) == 1 {
399
- return serieSets [0 ]
419
+ if len (promises ) == 1 {
420
+ return <- promises [0 ]
400
421
}
401
422
402
- return storage .NewMergeSeriesSet (serieSets , limit , storage .ChainedSeriesMerge )
403
- }
423
+ seriesSets := make ([]storage.SeriesSet , len (promises ))
424
+ for i , promise := range promises {
425
+ seriesSets [i ] = <- promise
426
+ }
404
427
405
- func (q * parquetQuerierWithFallback ) Close () error {
406
- mErr := multierror.MultiError {}
407
- mErr .Add (q .parquetQuerier .Close ())
408
- mErr .Add (q .blocksStoreQuerier .Close ())
409
- return mErr .Err ()
428
+ return storage .NewMergeSeriesSet (seriesSets , limit , storage .ChainedSeriesMerge )
410
429
}
411
430
412
- func (q * parquetQuerierWithFallback ) getBlocks ( ctx context. Context , minT , maxT int64 ) ([] * bucketindex. Block , [] * bucketindex. Block , error ) {
431
+ func (q * parquetQuerierWithFallback ) adjustMaxT ( maxt int64 ) int64 {
413
432
// If queryStoreAfter is enabled, we do manipulate the query maxt to query samples up until
414
433
// now - queryStoreAfter, because the most recent time range is covered by ingesters. This
415
434
// optimization is particularly important for the blocks storage because can be used to skip
416
435
// querying most recent not-compacted-yet blocks from the storage.
417
436
if q .queryStoreAfter > 0 {
418
437
now := time .Now ()
419
- maxT = min (maxT , util .TimeToMillis (now .Add (- q .queryStoreAfter )))
420
-
421
- if maxT < minT {
422
- return nil , nil , nil
423
- }
438
+ maxt = min (maxt , util .TimeToMillis (now .Add (- q .queryStoreAfter )))
424
439
}
440
+ return maxt
441
+ }
425
442
443
+ func (q * parquetQuerierWithFallback ) Close () error {
444
+ mErr := multierror.MultiError {}
445
+ mErr .Add (q .parquetQuerier .Close ())
446
+ mErr .Add (q .blocksStoreQuerier .Close ())
447
+ return mErr .Err ()
448
+ }
449
+
450
+ func (q * parquetQuerierWithFallback ) getBlocks (ctx context.Context , minT , maxT int64 ) ([]* bucketindex.Block , []* bucketindex.Block , error ) {
426
451
userID , err := tenant .TenantID (ctx )
427
452
if err != nil {
428
453
return nil , nil , err
429
454
}
430
455
456
+ maxT = q .adjustMaxT (maxT )
457
+
458
+ if maxT < minT {
459
+ return nil , nil , nil
460
+ }
461
+
431
462
blocks , _ , err := q .finder .GetBlocks (ctx , userID , minT , maxT )
432
463
if err != nil {
433
464
return nil , nil , err
0 commit comments