Skip to content

check allocated buckets when allocating empty buckets to avoid OOM#80789

Closed
boicehuang wants to merge 5 commits intoelastic:mainfrom
TencentCloudES:date_hisgram_check_step
Closed

check allocated buckets when allocating empty buckets to avoid OOM#80789
boicehuang wants to merge 5 commits intoelastic:mainfrom
TencentCloudES:date_hisgram_check_step

Conversation

@boicehuang
Copy link
Copy Markdown
Contributor

In addEmptyBuckets of date histogram, it introduces a counter to accumulate the number of empty buckets to trigger the "search.max_bucket" breaker, but the parent breaker would probably not be triggered because no bucket is allocated in the first accumulation process. When it allocates memory for empty buckets on the second iterateEmptyBuckets, without any memory circuit breaker check, the memory rises and may cause OOM.
For example, people may set search.max_buckets to 20w, but 20w empty buckets may fill up remaining heap memory when there are other write and search tasks in ES node. In this case, we can still use check allocated_buckets to prevent date histogram from causing OOM in advance.

This PR adds checks on real memory parent circuit breaker when allocating empty buckets.

@elasticsearchmachine elasticsearchmachine added external-contributor Pull request authored by a developer outside the Elasticsearch team v8.1.0 labels Nov 17, 2021
@elasticmachine elasticmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Nov 20, 2021
@elasticmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-analytics-geo (Team:Analytics)

@nik9000 nik9000 self-requested a review November 30, 2021 20:23
@nik9000
Copy link
Copy Markdown
Member

nik9000 commented Nov 30, 2021

Sorry it took us so long to get to reviewing this one!

For example, people may set search.max_buckets to 20w,

That sounds like they are intentionally trying to defeat the protection from search.max_buckets. I'm not sure we should really support this.

@imotov, what do you think?

Copy link
Copy Markdown
Contributor

@imotov imotov left a comment

Choose a reason for hiding this comment

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

I think it could be a helpful change for some users, but it kind of depends on side effects from two functions working together and it has no tests. So, I am not sure I would be comfortable merging it in like this.

@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

@boicehuang please enable the option "Allow edits and access to secrets by maintainers" on your PR. For more information, see the documentation.

@nik9000 nik9000 added the >bug label Jul 20, 2022
@elasticsearchmachine elasticsearchmachine changed the base branch from master to main July 22, 2022 23:09
@wchaparro
Copy link
Copy Markdown
Member

@boicehuang This seems useful, would you please add tests to verify the functionality added here?

@boicehuang
Copy link
Copy Markdown
Contributor Author

@boicehuang This seems useful, would you please add tests to verify the functionality added here?

fine, i will add some tests.

@mark-vieira mark-vieira added v8.5.0 and removed v8.4.0 labels Jul 27, 2022
@nik9000 nik9000 requested review from imotov and removed request for imotov August 2, 2022 13:01
@boicehuang
Copy link
Copy Markdown
Contributor Author

boicehuang commented Aug 14, 2022

@wchaparro I found it hard to add tests because it depends on real-memory parent breaker. can you help give me some examples?

@nik9000 nik9000 self-assigned this Aug 18, 2022
@nik9000
Copy link
Copy Markdown
Member

nik9000 commented Aug 18, 2022

Hey folks! I put together some tests but couldn't push them to this repo. I'm not super proud of the tests, but they do seem to get the job done. Could you give repo owners permission to push to this branch?

@nik9000
Copy link
Copy Markdown
Member

nik9000 commented Aug 22, 2022

Hey folks! I put together some tests but couldn't push them to this repo. I'm not super proud of the tests, but they do seem to get the job done. Could you give repo owners permission to push to this branch?

I see you've merged master. That's not enough to let me push to the repo - there's a button on the PR. Here are some instructions: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork

If you do that I should be able to push my test. And the changelog bot can push a changelog entry.

@boicehuang
Copy link
Copy Markdown
Contributor Author

boicehuang commented Aug 24, 2022

I can't find the button because the PR was made from an organization account.
image

I open a new PR #89568 from my owned forks with "Allow edits and access to secrets by maintainers" enabled. @nik9000

@nik9000
Copy link
Copy Markdown
Member

nik9000 commented Aug 24, 2022

I open a new PR #89568 from my owned forks with "Allow edits and access to secrets by maintainers" enabled. @nik9000

Sorry! I suppose our process isn't great for these. I've reviewed the PR on the other side, pushed a test, poked it a bit for performance, and an getting it merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/Aggregations Aggregations >bug external-contributor Pull request authored by a developer outside the Elasticsearch team Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants