Skip to content

Commit

Permalink
Cache: correctly check background cache size (grafana#11654)
Browse files Browse the repository at this point in the history
**What this PR does / why we need it**:
The size check was not being performed atomically, which led to
flakiness in the `TestBackgroundSizeLimit` test.

---------

Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
Co-authored-by: Christian Haudum <christian.haudum@gmail.com>
  • Loading branch information
2 people authored and rhnasc committed Apr 12, 2024
1 parent 8456d53 commit 5000fc7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* [11539](https://github.com/grafana/loki/pull/11539) **kaviraj,ashwanthgoli** Support caching /series and /labels query results
* [11545](https://github.com/grafana/loki/pull/11545) **dannykopping** Force correct memcached timeout when fetching chunks.
* [11589](https://github.com/grafana/loki/pull/11589) **ashwanthgoli** Results Cache: Adds `query_length_served` cache stat to measure the length of the query served from cache.
* [11654](https://github.com/grafana/loki/pull/11654) **dannykopping** Cache: atomically check background cache size limit correctly.

##### Fixes
* [11074](https://github.com/grafana/loki/pull/11074) **hainenber** Fix panic in lambda-promtail due to mishandling of empty DROP_LABELS env var.
Expand Down
5 changes: 4 additions & 1 deletion pkg/storage/chunk/cache/background.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,11 @@ func (c *backgroundCache) Store(ctx context.Context, keys []string, bufs [][]byt
}

size := bgWrite.size()
newSize := c.size.Load() + int64(size)
// prospectively add new size
newSize := c.size.Add(int64(size))
if newSize > int64(c.sizeLimit) {
// subtract it since we've exceeded the limit
c.size.Sub(int64(size))
c.failStore(ctx, size, num, "queue at byte size limit")
return nil
}
Expand Down

0 comments on commit 5000fc7

Please sign in to comment.