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

Short circuited to MatchNone for non-participating slice #51207

Merged
merged 4 commits into from
Jan 22, 2020

Conversation

nirmalc
Copy link
Contributor

@nirmalc nirmalc commented Jan 20, 2020

When the query is expensive parallel usage of scroll/slice API overloads cluster, ( In my case a span_multi query causes heap / gc issues )

Looks like its because same query is processed against all non-matching shards with a MatchNoDocs and matching-shards with MatchAllDocs filter. In case of number of shards =< number of slices, returning a MatchNoDocs query instead of filter seems to avoid that problem.

In case of numSlices = numShards , use a MatchNone query instead of
boolean with a MatchNone - MUST clause
@cbuescher cbuescher added the :Search/Search Search-related issues that do not fall into other categories label Jan 21, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Search)

@mayya-sharipova
Copy link
Contributor

@elasticmachine test this please

Copy link
Contributor

@mayya-sharipova mayya-sharipova left a comment

Choose a reason for hiding this comment

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

thanks @nirmalc, nice enhancement!
I left small comments to be addressed

Query slicedQuery = sliceBuilder.toFilter(clusterService, request, queryShardContext);
if ( slicedQuery instanceof MatchNoDocsQuery){
return slicedQuery;
}else {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: space before else

@@ -274,7 +275,12 @@ public Query buildFilteredQuery(Query query) {
}

if (sliceBuilder != null) {
filters.add(sliceBuilder.toFilter(clusterService, request, queryShardContext));
Query slicedQuery = sliceBuilder.toFilter(clusterService, request, queryShardContext);
if ( slicedQuery instanceof MatchNoDocsQuery){
Copy link
Contributor

Choose a reason for hiding this comment

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

extra space after (

when(queryShardContext.fieldMapper(anyString())).thenReturn(mock(MappedFieldType.class));
when(shardSearchRequest.indexRoutings()).thenReturn(new String[0]);

DefaultSearchContext context4 = new DefaultSearchContext(3L, shardSearchRequest, target, searcher, null,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: new DefaultSearchContext(3L, => new DefaultSearchContext(4L,

@@ -178,6 +182,20 @@ public void testPreProcess() throws Exception {
ParsedQuery parsedQuery = ParsedQuery.parsedMatchAllQuery();
context3.sliceBuilder(null).parsedQuery(parsedQuery).preProcess(false);
assertEquals(context3.query(), context3.buildFilteredQuery(parsedQuery.query()));

when(queryShardContext.getIndexSettings()).thenReturn(indexSettings);
when(indexService.newQueryShardContext(anyInt(),anyObject(),anyObject(),anyString())).thenReturn(queryShardContext);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like, line 187 in not necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for review , it is not necessary. I think i added in my first attempt to include use-case with routings in test. I've reformatted code with intelliJ - sorry for formatting issues.

@mayya-sharipova
Copy link
Contributor

@elasticmachine test this please

@mayya-sharipova
Copy link
Contributor

@elasticmachine run elasticsearch-ci/default-distro

@mayya-sharipova
Copy link
Contributor

@elasticmachine run elasticsearch-ci/bwc

@mayya-sharipova
Copy link
Contributor

@elasticmachine update branch

@mayya-sharipova
Copy link
Contributor

@elasticmachine test this please

@mayya-sharipova mayya-sharipova merged commit c7aaf5a into elastic:master Jan 22, 2020
mayya-sharipova pushed a commit that referenced this pull request Jan 22, 2020
In case of numSlices = numShards, use a MatchNone query
instead of boolean with a MatchNone - MUST clause

Backport for #51207
@mayya-sharipova
Copy link
Contributor

@nirmalc Thank you for the PR, your change has ben merged, and will be available from 7.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Search/Search Search-related issues that do not fall into other categories v7.7.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants