Skip to content

Commit

Permalink
store/cache: add a case for when item > max LRU size
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Giedrius Statkevičius committed Jan 30, 2019
1 parent 5e5e353 commit 621d87d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/store/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 621d87d

Please sign in to comment.