Skip to content

Commit

Permalink
store/cache: properly adjust c.curSize
Browse files Browse the repository at this point in the history
  • Loading branch information
Giedrius Statkevičius committed Feb 28, 2019
1 parent 8d54a99 commit fbaae7c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/store/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ func (c *indexCache) ensureFits(b []byte) bool {
return false
}
for c.curSize+uint64(len(b)) > c.maxSize {
c.lru.RemoveOldest()
if _, val, ok := c.lru.RemoveOldest(); ok {
v := val.([]byte)
c.curSize -= uint64(len(v))
}
}
return true
}
Expand All @@ -152,6 +155,7 @@ func (c *indexCache) setPostings(b ulid.ULID, l labels.Label, v []byte) {

c.currentSize.WithLabelValues(cacheTypePostings).Add(float64(len(v)))
c.current.WithLabelValues(cacheTypePostings).Inc()
c.curSize += uint64(len(v))
}

func (c *indexCache) postings(b ulid.ULID, l labels.Label) ([]byte, bool) {
Expand Down Expand Up @@ -187,6 +191,7 @@ func (c *indexCache) setSeries(b ulid.ULID, id uint64, v []byte) {

c.currentSize.WithLabelValues(cacheTypeSeries).Add(float64(len(v)))
c.current.WithLabelValues(cacheTypeSeries).Inc()
c.curSize += uint64(len(v))
}

func (c *indexCache) series(b ulid.ULID, id uint64) ([]byte, bool) {
Expand Down

0 comments on commit fbaae7c

Please sign in to comment.