From 621d87d91310dc745990a40447bc709dcc3cb1d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Date: Wed, 30 Jan 2019 13:33:01 +0200 Subject: [PATCH] store/cache: add a case for when item > max LRU size This could potentially spin forever if the size of that item is bigger than the max size so add this special case to handle it instead of spinning forever. In this case, the oldest one will not be removed in this function but later an item might be evicted when we will add an item to the LRU with c.lru.Add() so it will be OK either way -- just that we will not spin here forever. --- pkg/store/cache.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/store/cache.go b/pkg/store/cache.go index 16cad121f5..c0d914818f 100644 --- a/pkg/store/cache.go +++ b/pkg/store/cache.go @@ -116,6 +116,9 @@ func newIndexCache(reg prometheus.Registerer, maxBytes uint64) (*indexCache, err } func (c *indexCache) ensureFits(b []byte) { + if uint64(len(b)) > c.maxSize { + return + } for c.curSize+uint64(len(b)) > c.maxSize { c.lru.RemoveOldest() }