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

Allow aggs to disable offloading sequential collection #98276

Merged
merged 6 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,39 @@ public boolean isInSortOrderExecutionRequired() {
}

/**
* Return false if this aggregation or any of the child aggregations does not support concurrent search
* Return false if this aggregation or any of the child aggregations does not support concurrent search.
* As a result, such aggregation will always be executed sequentially despite concurrency is enabled for the query phase.
* Note: aggregations that don't support concurrency, may or may not support offloading their collection to the search worker threads,
* depending on what {@link #supportsOffloadingSequentialCollection()} returns.
*/
public boolean supportsConcurrentExecution() {
if (isInSortOrderExecutionRequired()) {
return false;
}
for (AggregationBuilder builder : factoriesBuilder.getAggregatorFactories()) {
if (builder.supportsOffloadingSequentialCollection() == false || builder.supportsConcurrentExecution() == false) {
return false;
}
}
return true;
}

/**
* Returns false if this aggregation or any of its child aggregations does not support offloading its sequential collection
* to a separate thread. As a result, such aggregation will always be executed sequentially, and fully in the search thread,
* without offloading its collection to the search worker threads.
* Note: aggregations that don't support offloading sequential collection, don't support concurrency by definition.
*/
public boolean supportsOffloadingSequentialCollection() {
if (isInSortOrderExecutionRequired()) {
return false;
}
for (AggregationBuilder builder : factoriesBuilder.getAggregatorFactories()) {
if (builder.supportsConcurrentExecution() == false) {
if (builder.supportsOffloadingSequentialCollection() == false) {
return false;
}
}
return isInSortOrderExecutionRequired() == false;
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public boolean supportsSampling() {
}

@Override
public boolean supportsConcurrentExecution() {
public boolean supportsOffloadingSequentialCollection() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public BucketCardinality bucketCardinality() {
}

@Override
public boolean supportsConcurrentExecution() {
public boolean supportsOffloadingSequentialCollection() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public boolean supportsSampling() {
}

@Override
public boolean supportsConcurrentExecution() {
public boolean supportsOffloadingSequentialCollection() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ public class CardinalityAggregatorTests extends AggregatorTestCase {
/** Script to extract a collection of numeric values from the 'numbers' field **/
public static final String NUMERIC_VALUES_SCRIPT = "doc['numbers']";

public static final int HASHER_DEFAULT_SEED = 17;

@Override
protected ScriptService getMockScriptService() {
final Map<String, Function<Map<String, Object>, Object>> scripts = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,25 @@ public void testFromXContent() throws IOException {
public void testSupportsConcurrentExecution() {
AB builder = createTestAggregatorBuilder();
boolean supportsConcurrency = builder.supportsConcurrentExecution();
if (supportsConcurrency == false) {
assertFalse(builder.supportsOffloadingSequentialCollection());
javanna marked this conversation as resolved.
Show resolved Hide resolved
}
AggregationBuilder bucketBuilder = new HistogramAggregationBuilder("test");
assertThat(bucketBuilder.supportsConcurrentExecution(), equalTo(true));
assertTrue(bucketBuilder.supportsConcurrentExecution());
bucketBuilder.subAggregation(builder);
assertThat(bucketBuilder.supportsConcurrentExecution(), equalTo(supportsConcurrency));
if (bucketBuilder.supportsConcurrentExecution() == false) {
assertFalse(bucketBuilder.supportsOffloadingSequentialCollection());
}
}

public void testSupportsOffloadingSequentialCollection() {
AB builder = createTestAggregatorBuilder();
boolean supportsOffloadingSequentialCollection = builder.supportsOffloadingSequentialCollection();
AggregationBuilder bucketBuilder = new HistogramAggregationBuilder("test");
assertTrue(bucketBuilder.supportsOffloadingSequentialCollection());
bucketBuilder.subAggregation(builder);
assertThat(bucketBuilder.supportsOffloadingSequentialCollection(), equalTo(supportsOffloadingSequentialCollection));
}

/**
Expand Down