@@ -380,16 +380,12 @@ func (s *Server) getTarget(ctx context.Context, req models.Req) (points []schema
380380 }
381381}
382382
383- func logLoad (typ , key string , from , to uint32 ) {
383+ func logLoad (typ string , key schema. AMKey , from , to uint32 ) {
384384 if LogLevel < 2 {
385- log .Debug ("DP load from %-6s %- 20s %d - %d (%s - %s) span:%ds" , typ , key , from , to , util .TS (from ), util .TS (to ), to - from - 1 )
385+ log .Debug ("DP load from %-6s %20s %d - %d (%s - %s) span:%ds" , typ , key , from , to , util .TS (from ), util .TS (to ), to - from - 1 )
386386 }
387387}
388388
389- func AggMetricKey (key , archive string , aggSpan uint32 ) string {
390- return fmt .Sprintf ("%s_%s_%d" , key , archive , aggSpan )
391- }
392-
393389func (s * Server ) getSeriesFixed (ctx context.Context , req models.Req , consolidator consolidation.Consolidator ) ([]schema.Point , error ) {
394390 select {
395391 case <- ctx .Done ():
@@ -474,18 +470,17 @@ func (s *Server) itersToPoints(ctx *requestContext, iters []chunk.Iter) []schema
474470func (s * Server ) getSeriesAggMetrics (ctx * requestContext ) (mdata.Result , error ) {
475471 _ , span := tracing .NewSpan (ctx .ctx , s .Tracer , "getSeriesAggMetrics" )
476472 defer span .Finish ()
477- metric , ok := s .MemoryStore .Get (ctx .Key )
473+ metric , ok := s .MemoryStore .Get (ctx .AMKey . MKey )
478474 if ! ok {
479475 return mdata.Result {
480476 Oldest : ctx .Req .To ,
481477 }, nil
482478 }
483479
480+ logLoad ("memory" , ctx .AMKey , ctx .From , ctx .To )
484481 if ctx .Cons != consolidation .None {
485- logLoad ("memory" , ctx .AggKey , ctx .From , ctx .To )
486482 return metric .GetAggregated (ctx .Cons , ctx .Req .ArchInterval , ctx .From , ctx .To )
487483 } else {
488- logLoad ("memory" , ctx .Req .Key , ctx .From , ctx .To )
489484 return metric .Get (ctx .From , ctx .To ), nil
490485 }
491486}
@@ -495,22 +490,17 @@ func (s *Server) getSeriesCachedStore(ctx *requestContext, until uint32) ([]chun
495490 var iters []chunk.Iter
496491 var prevts uint32
497492
498- key := ctx .Key
499- if ctx .Cons != consolidation .None {
500- key = ctx .AggKey
501- }
502-
503493 _ , span := tracing .NewSpan (ctx .ctx , s .Tracer , "getSeriesCachedStore" )
504494 defer span .Finish ()
505- span .SetTag ("key" , key )
495+ span .SetTag ("key" , ctx . AMKey )
506496 span .SetTag ("from" , ctx .From )
507497 span .SetTag ("until" , until )
508498
509499 reqSpanBoth .ValueUint32 (ctx .To - ctx .From )
510- logLoad ("cassan" , ctx .Key , ctx .From , ctx .To )
500+ logLoad ("cassan" , ctx .AMKey , ctx .From , ctx .To )
511501
512- log .Debug ("cache: searching query key %s, from %d, until %d" , key , ctx .From , until )
513- cacheRes := s .Cache .Search (ctx .ctx , key , ctx .From , until )
502+ log .Debug ("cache: searching query key %s, from %d, until %d" , ctx . AMKey , ctx .From , until )
503+ cacheRes := s .Cache .Search (ctx .ctx , ctx . AMKey , ctx .From , until )
514504 log .Debug ("cache: result start %d, end %d" , len (cacheRes .Start ), len (cacheRes .End ))
515505
516506 // check to see if the request has been canceled, if so abort now.
@@ -544,7 +534,7 @@ func (s *Server) getSeriesCachedStore(ctx *requestContext, until uint32) ([]chun
544534 // the request cannot completely be served from cache, it will require cassandra involvement
545535 if ! cacheRes .Complete {
546536 if cacheRes .From != cacheRes .Until {
547- storeIterGens , err := s .BackendStore .Search (ctx .ctx , key , ctx .Req .TTL , cacheRes .From , cacheRes .Until )
537+ storeIterGens , err := s .BackendStore .Search (ctx .ctx , ctx . AMKey , ctx .Req .TTL , cacheRes .From , cacheRes .Until )
548538 if err != nil {
549539 return iters , err
550540 }
@@ -566,7 +556,7 @@ func (s *Server) getSeriesCachedStore(ctx *requestContext, until uint32) ([]chun
566556 }
567557 // it's important that the itgens get added in chronological order,
568558 // currently we rely on cassandra returning results in order
569- s .Cache .Add (key , ctx .Key , prevts , itgen )
559+ s .Cache .Add (ctx .AMKey , prevts , itgen )
570560 prevts = itgen .Ts
571561 iters = append (iters , * it )
572562 }
@@ -632,18 +622,18 @@ func mergeSeries(in []models.Series) []models.Series {
632622 return merged
633623}
634624
625+ // requestContext is a more concrete specification to load data based on a models.Req
635626type requestContext struct {
636627 ctx context.Context
637628
638629 // request by external user.
639630 Req * models.Req
640631
641632 // internal request needed to satisfy user request.
642- Cons consolidation.Consolidator // to satisfy avg request from user, this would be sum or cnt
643- From uint32 // may be different than user request, see below
644- To uint32 // may be different than user request, see below
645- Key string // key to query
646- AggKey string // aggkey to query (if needed)
633+ Cons consolidation.Consolidator // to satisfy avg request from user, this would be sum or cnt
634+ From uint32 // may be different than user request, see below
635+ To uint32 // may be different than user request, see below
636+ AMKey schema.AMKey // set by combining Req's key, consolidator and archive info
647637}
648638
649639func prevBoundary (ts uint32 , span uint32 ) uint32 {
@@ -656,7 +646,6 @@ func newRequestContext(ctx context.Context, req *models.Req, consolidator consol
656646 ctx : ctx ,
657647 Req : req ,
658648 Cons : consolidator ,
659- Key : req .Key ,
660649 }
661650
662651 // while aggregated archives are quantized, raw intervals are not. quantizing happens after fetching the data,
@@ -673,10 +662,11 @@ func newRequestContext(ctx context.Context, req *models.Req, consolidator consol
673662 if consolidator == consolidation .None {
674663 rc .From = prevBoundary (req .From , req .ArchInterval ) + 1
675664 rc .To = prevBoundary (req .To , req .ArchInterval ) + 1
665+ rc .AMKey = schema.AMKey {MKey : req .MKey }
676666 } else {
677667 rc .From = req .From
678668 rc .To = req .To
679- rc .AggKey = AggMetricKey (req .Key , consolidator .Archive (), req .ArchInterval )
669+ rc .AMKey = schema . GetAMKey (req .MKey , consolidator .Archive (), req .ArchInterval )
680670 }
681671
682672 return & rc
0 commit comments