Skip to content

Comments

Aggregations cancellation after collection (#120944)#121936

Merged
elasticsearchmachine merged 1 commit intoelastic:8.16from
not-napoleon:backport-120944-to-8.16
Feb 6, 2025
Merged

Aggregations cancellation after collection (#120944)#121936
elasticsearchmachine merged 1 commit intoelastic:8.16from
not-napoleon:backport-120944-to-8.16

Conversation

@not-napoleon
Copy link
Member

This PR addresses issues around aggregations cancellation, mentioned in #108701 and other places. In brief, during aggregations collection time, we respect cancellation via the mechanisms in the searcher to poison cancelled queries. But once the aggregation finishes collection, there is no further need to interact with the searcher, so we cannot rely on that for cancellation checking. In particular, deeply nested aggregations can spend a long time constructing the results tree.

Checking for cancellation is a trade off, as the check itself is somewhat expensive (it involves a volatile read), so we want to balance checking often enough that cancelled queries aren't taking up resources for a long time, but not so frequently that it slows down most aggregation queries. Our first attempt to this is to check once when we go to build sub-aggregations, as the worst cases for this that we've seen involve needing to build deep sub-aggregation trees. Checking at sub-aggregation construction time also provides a conveniently centralized method call to add the check to.


Conflicts:
server/src/main/java/org/elasticsearch/search/aggregations/bucket/BucketsAggregator.java
test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java

This PR addresses issues around aggregations cancellation, mentioned in elastic#108701 and other places. In brief, during aggregations collection time, we respect cancellation via the mechanisms in the searcher to poison cancelled queries. But once the aggregation finishes collection, there is no further need to interact with the searcher, so we cannot rely on that for cancellation checking. In particular, deeply nested aggregations can spend a long time constructing the results tree.

Checking for cancellation is a trade off, as the check itself is somewhat expensive (it involves a volatile read), so we want to balance checking often enough that cancelled queries aren't taking up resources for a long time, but not so frequently that it slows down most aggregation queries. Our first attempt to this is to check once when we go to build sub-aggregations, as the worst cases for this that we've seen involve needing to build deep sub-aggregation trees. Checking at sub-aggregation construction time also provides a conveniently centralized method call to add the check to.

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
Co-authored-by: Nik Everett <nik9000@gmail.com>
 Conflicts:
	server/src/main/java/org/elasticsearch/search/aggregations/bucket/BucketsAggregator.java
	test/framework/src/main/java/org/elasticsearch/search/aggregations/AggregatorTestCase.java
@not-napoleon not-napoleon added >bug backport auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Analytics/ES|QL AKA ESQL v8.16.5 labels Feb 6, 2025
@elasticsearchmachine elasticsearchmachine merged commit cf36d97 into elastic:8.16 Feb 6, 2025
15 checks passed
@not-napoleon not-napoleon deleted the backport-120944-to-8.16 branch February 6, 2025 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) backport >bug v8.16.5

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants