Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b78f195
can it really be this simple?
not-napoleon Jan 27, 2025
5751f45
Update docs/changelog/120944.yaml
not-napoleon Jan 27, 2025
ca451b8
More correct exception type
not-napoleon Jan 27, 2025
18870c4
[CI] Auto commit changes from spotless
Jan 27, 2025
250bc9b
clean up some deprecations
not-napoleon Jan 27, 2025
696fdfc
Merge remote-tracking branch 'refs/remotes/not-napoleon/aggregations-…
not-napoleon Jan 27, 2025
32f079c
[CI] Auto commit changes from spotless
Jan 27, 2025
a4cabaf
Aggs: test super deep
nik9000 Jan 24, 2025
ec66b50
add cancellation case to aggs tests
not-napoleon Jan 28, 2025
8181260
Merge remote-tracking branch 'refs/remotes/not-napoleon/aggregations-…
not-napoleon Jan 28, 2025
bdc6516
some testing around reduce time cancellation
not-napoleon Jan 29, 2025
7eb1966
[CI] Auto commit changes from spotless
Jan 29, 2025
7e213b6
remove the nocommits
not-napoleon Jan 29, 2025
6454286
Merge remote-tracking branch 'refs/remotes/not-napoleon/aggregations-…
not-napoleon Jan 29, 2025
a0485b5
Merge branch 'main' into aggregations-cancellation-after-collection
not-napoleon Jan 29, 2025
c8024e7
Fix license
nik9000 Jan 29, 2025
0231c5a
Merge remote-tracking branch 'refs/remotes/not-napoleon/aggregations-…
nik9000 Jan 29, 2025
7d811a0
Update docs/changelog/120944.yaml
not-napoleon Jan 29, 2025
4a45481
oops, something was using that one
not-napoleon Jan 29, 2025
f2b240f
allow tests to opt out of reduce cancellation testing
not-napoleon Jan 29, 2025
6f51925
Merge branch 'main' into aggregations-cancellation-after-collection
not-napoleon Jan 31, 2025
8359e4e
Merge branch 'main' into aggregations-cancellation-after-collection
nik9000 Feb 3, 2025
2869310
Explain
nik9000 Feb 3, 2025
dc526a8
Merge remote-tracking branch 'refs/remotes/not-napoleon/aggregations-…
nik9000 Feb 3, 2025
e11ac1e
Merge branch 'main' into aggregations-cancellation-after-collection
not-napoleon Feb 6, 2025
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
6 changes: 6 additions & 0 deletions docs/changelog/120944.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 120944
summary: Aggregations cancellation after collection
area: Aggregations
type: bug
issues:
- 108701
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
import org.elasticsearch.tasks.TaskCancelledException;

import java.io.IOException;
import java.util.Collections;
Expand Down Expand Up @@ -573,7 +574,11 @@ private void rebucket() {
long[] mergeMap = new long[Math.toIntExact(oldOrds.size())];
bucketOrds = new LongKeyedBucketOrds.FromMany(bigArrays());
success = true;
for (long owningBucketOrd = 0; owningBucketOrd <= oldOrds.maxOwningBucketOrd(); owningBucketOrd++) {
long maxOwning = oldOrds.maxOwningBucketOrd();
for (long owningBucketOrd = 0; owningBucketOrd <= maxOwning; owningBucketOrd++) {
if (context.isCancelled()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: It is not clear to me why we are handling auto-date histogram in a special way. Could we add a comment explaining the why?

Copy link
Member

Choose a reason for hiding this comment

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

Sure! Its just that it spends a while spinning around doing extra stuff before it's ready for the normal build.

Copy link
Member

Choose a reason for hiding this comment

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

And I found it from an actual bug report of folks that were trying to terminate aggs and the thread was stuck here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks

Copy link
Member

Choose a reason for hiding this comment

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

you have not one but three typos in that sentence :D

throw new TaskCancelledException("cancelled");
}
LongKeyedBucketOrds.BucketOrdsEnum ordsEnum = oldOrds.ordsEnum(owningBucketOrd);
Rounding.Prepared preparedRounding = preparedRoundings[roundingIndexFor(owningBucketOrd)];
while (ordsEnum.next()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void testNoData() throws Exception {
MatrixStatsAggregationBuilder aggBuilder = new MatrixStatsAggregationBuilder("my_agg").fields(
Collections.singletonList("field")
);
InternalMatrixStats stats = searchAndReduce(reader, new AggTestConfig(aggBuilder, ft));
InternalMatrixStats stats = searchAndReduce(reader, new AggTestConfig(aggBuilder, ft).noReductionCancellation());
assertNull(stats.getStats());
assertEquals(0L, stats.getDocCount());
}
Expand All @@ -54,7 +54,7 @@ public void testUnmapped() throws Exception {
MatrixStatsAggregationBuilder aggBuilder = new MatrixStatsAggregationBuilder("my_agg").fields(
Collections.singletonList("bogus")
);
InternalMatrixStats stats = searchAndReduce(reader, new AggTestConfig(aggBuilder, ft));
InternalMatrixStats stats = searchAndReduce(reader, new AggTestConfig(aggBuilder, ft).noReductionCancellation());
assertNull(stats.getStats());
assertEquals(0L, stats.getDocCount());
}
Expand Down Expand Up @@ -88,7 +88,7 @@ public void testTwoFields() throws Exception {
MatrixStatsAggregationBuilder aggBuilder = new MatrixStatsAggregationBuilder("my_agg").fields(
Arrays.asList(fieldA, fieldB)
);
InternalMatrixStats stats = searchAndReduce(reader, new AggTestConfig(aggBuilder, ftA, ftB));
InternalMatrixStats stats = searchAndReduce(reader, new AggTestConfig(aggBuilder, ftA, ftB).noReductionCancellation());
multiPassStats.assertNearlyEqual(stats);
assertTrue(MatrixAggregationInspectionHelper.hasValue(stats));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.search.aggregations.support.AggregationPath;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.tasks.TaskCancelledException;

import java.io.IOException;
import java.util.AbstractList;
Expand Down Expand Up @@ -163,6 +164,10 @@ protected void prepareSubAggs(LongArray ordsToCollect) throws IOException {}
* array of ordinals
*/
protected final IntFunction<InternalAggregations> buildSubAggsForBuckets(LongArray bucketOrdsToCollect) throws IOException {
if (context.isCancelled()) {
throw new TaskCancelledException("not building sub-aggregations due to task cancellation");
}

prepareSubAggs(bucketOrdsToCollect);
InternalAggregation[][] aggregations = new InternalAggregation[subAggregators.length][];
for (int i = 0; i < subAggregators.length; i++) {
Expand Down
Loading