@@ -217,7 +217,7 @@ func (c *Store) getMetricNameChunks(ctx context.Context, from, through model.Tim
217217 level .Warn (logger ).Log ("msg" , "error fetching from cache" , "err" , err )
218218 }
219219
220- fromCache , missing , err := ProcessCacheResponse (chunks , cacheHits , cacheBufs )
220+ fromCache , missing , err := ProcessCacheResponse (filtered , cacheHits , cacheBufs )
221221 if err != nil {
222222 level .Warn (logger ).Log ("msg" , "error fetching from cache" , "err" , err )
223223 }
@@ -253,17 +253,20 @@ outer:
253253 return filteredChunks , nil
254254}
255255
256+ // ProcessCacheResponse decodes the chunks coming back from the cache, separating
257+ // hits and misses.
256258func ProcessCacheResponse (chunks []Chunk , keys []string , bufs [][]byte ) (found []Chunk , missing []Chunk , err error ) {
257259 ctx := NewDecodeContext ()
258260
259- for i , j := 0 , 0 ; i < len (chunks ) && j < len (keys ); {
261+ i , j := 0 , 0
262+ for i < len (chunks ) && j < len (keys ) {
260263 chunkKey := chunks [i ].ExternalKey ()
261264
262265 if chunkKey < keys [j ] {
263266 missing = append (missing , chunks [i ])
264267 i ++
265268 } else if chunkKey > keys [j ] {
266- // Got a chunk response we shouldn 't have
269+ level . Debug ( util . Logger ). Log ( "msg" , "got chunk from cache we didn 't ask for" )
267270 j ++
268271 } else {
269272 chunk := chunks [i ]
@@ -277,6 +280,10 @@ func ProcessCacheResponse(chunks []Chunk, keys []string, bufs [][]byte) (found [
277280 }
278281 }
279282
283+ for ; i < len (chunks ); i ++ {
284+ missing = append (missing , chunks [i ])
285+ }
286+
280287 return
281288}
282289
0 commit comments