MCPcopy Create free account
hub / github.com/cortexproject/cortex / get

Method get

pkg/querier/tripperware/queryrange/results_cache.go:729–759  ·  view source on GitHub ↗
(ctx context.Context, key string)

Source from the content-addressed store, hash-verified

727}
728
729func (s resultsCache) get(ctx context.Context, key string) ([]tripperware.Extent, bool) {
730 found, bufs, _ := s.cache.Fetch(ctx, []string{cache.HashKey(key)})
731 if len(found) != 1 {
732 return nil, false
733 }
734
735 var resp tripperware.CachedResponse
736 log, ctx := spanlogger.New(ctx, "unmarshal-extent") //nolint:ineffassign,staticcheck
737 defer log.Finish()
738
739 log.LogFields(otlog.Int("bytes", len(bufs[0])))
740
741 if err := proto.Unmarshal(bufs[0], &resp); err != nil {
742 level.Error(log).Log("msg", "error unmarshalling cached value", "err", err)
743 log.Error(err)
744 return nil, false
745 }
746
747 if resp.Key != key {
748 return nil, false
749 }
750
751 // Refreshes the cache if it contains an old proto schema.
752 for _, e := range resp.Extents {
753 if e.Response == nil {
754 return nil, false
755 }
756 }
757
758 return resp.Extents, true
759}
760
761func (s resultsCache) put(ctx context.Context, key string, extents []tripperware.Extent) {
762 buf, err := proto.Marshal(&tripperware.CachedResponse{

Callers 2

DoMethod · 0.95

Calls 8

HashKeyFunction · 0.92
NewFunction · 0.92
FinishMethod · 0.80
LogFieldsMethod · 0.80
FetchMethod · 0.65
UnmarshalMethod · 0.45
LogMethod · 0.45
ErrorMethod · 0.45

Tested by 1