Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store/cache: fix broken metric and current index cache size handling #873

Merged
merged 5 commits into from
Mar 4, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pkg/store/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ func (c *indexCache) ensureFits(b []byte) bool {
if uint64(len(b)) > c.maxSize {
return false
}
for c.curSize+uint64(len(b)) > c.maxSize {
c.lru.RemoveOldest()
for c.curSize > c.maxSize-uint64(len(b)) {
if _, val, ok := c.lru.RemoveOldest(); ok {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we handle something if that does not ok ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How we could inform the users about such case? AFAICT there is no way ok can be false due to the check before-hand.

v := val.([]byte)
c.curSize -= uint64(len(v))
}
}
return true
}
Expand All @@ -151,6 +154,8 @@ func (c *indexCache) setPostings(b ulid.ULID, l labels.Label, v []byte) {
c.lru.Add(cacheItem{b, cacheKeyPostings(l)}, cv)

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 @@ -185,6 +190,8 @@ func (c *indexCache) setSeries(b ulid.ULID, id uint64, v []byte) {
c.lru.Add(cacheItem{b, cacheKeySeries(id)}, cv)

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