Skip to content

Commit db422ce

Browse files
committed
Fix test failure and lint.
1 parent 2c55d1f commit db422ce

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

pkg/chunk/cache/memcached.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func (c *Memcached) StoreChunk(ctx context.Context, key string, buf []byte) erro
135135
})
136136
}
137137

138+
// Stop does nothing.
138139
func (*Memcached) Stop() error {
139140
return nil
140141
}

pkg/chunk/chunk_store.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
256258
func 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

Comments
 (0)