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

MQE: Fix panic in loading too many samples #10261

Merged
merged 8 commits into from
Dec 18, 2024

Conversation

jhesketh
Copy link
Contributor

@jhesketh jhesketh commented Dec 17, 2024

What this PR does

This PR solves two bugs:

Bug 1:

BucketedPool would create pools in powers of two up to a set maxSize. That is, if maxSize isn't a power of two itself,
then the maximum bucket would be less than the maxSize.

However, when requesting a slice from the pool we were only checking against the maxSize, and not whether a bucket existed for that size. Now, instead, calculate the bucketIndex and check if that exists before using it.

This would cause panic's in range vectors of more than 65,536 samples.

This problem was introduced in #10199

Bug 2:

If a requested slice size exceeded the size of the pools it would just be returned as the requested size. This caused a bug in the buffers which require the slices to be powers of two.

This PR ensures that the returned slice is always of power two. This means we will return a slice greater than the MaxExpectedPointsPerSeries, but it won't be from a pool (and similarly won't be returned to a pool). We are protected by the MemoryConsumptionTracker for any unreasonable requests.

This was introduced in #9664

Originally this would cause panic's in sub-queries selecting more than 65,536 samples, but since #10199 it returns just errors.

Which issue(s) this PR fixes or relates to

Fixes #

Checklist

  • Tests updated.
  • Documentation added.
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX].
  • about-versioning.md updated with experimental features.

BucketedPool would create pools in powers of two up to a set
`maxSize`. That is, if `maxSize` isn't a power of two itself,
then the maximum bucket would be less than the maxSize.

However, when requesting a slice from the pool we were only checking
against the maxSize, and not whether a bucket existed for that size.
Instead calculate the bucketIndex and check if that exists
before using it.
This is to guarantee they work with the ring buffers which expect slices
to always be power of two.

The limiting pool still protects us from requesting an unreasonable
amount of points with the MemoryConsumptionTracker.
@jhesketh jhesketh requested a review from a team as a code owner December 17, 2024 09:28
@jhesketh jhesketh mentioned this pull request Dec 17, 2024
@jhesketh
Copy link
Contributor Author

(this will need backporting to r321)

pkg/util/pool/bucketed_pool.go Show resolved Hide resolved
pkg/util/pool/bucketed_pool.go Show resolved Hide resolved
@jhesketh jhesketh merged commit 34a24b1 into grafana:main Dec 18, 2024
29 checks passed
@jhesketh jhesketh deleted the jhesketh/mqe-pooling branch December 18, 2024 09:52
jhesketh added a commit that referenced this pull request Dec 18, 2024
* MQE: Fix panic in loading too many samples

BucketedPool would create pools in powers of two up to a set
`maxSize`. That is, if `maxSize` isn't a power of two itself,
then the maximum bucket would be less than the maxSize.

However, when requesting a slice from the pool we were only checking
against the maxSize, and not whether a bucket existed for that size.
Instead calculate the bucketIndex and check if that exists
before using it.

* Use a power of two size max bucket

* MQE: Ensure BucketedPool always returns slices of power two

This is to guarantee they work with the ring buffers which expect slices
to always be power of two.

The limiting pool still protects us from requesting an unreasonable
amount of points with the MemoryConsumptionTracker.

* Fix tests

* Correctly return slices to their respective buckets or discard them

* Extra tests

* Address review feedback

* Remove unncessary slice length check

(cherry picked from commit 34a24b1)

Co-authored-by: Joshua Hesketh <joshua.hesketh@grafana.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants