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

Set INDICES_MAX_CLAUSE_COUNT dynamically #13568

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

harshavamsi
Copy link
Contributor

@harshavamsi harshavamsi commented May 6, 2024

Description

Changes the INDICES_MAX_CLAUSE_COUNT_SETTING to be dynamic instead of being static.

This PR is virtually identical to #1527, but there was earlier push back around making this an updateable dynamic setting due to the assumption that users would abuse this setting rather than optimize their underlying query. Lucene has since updated the way the clause counts work and this is now enforced at the indexSearcher level -- https://issues.apache.org/jira/browse/LUCENE-8811.

More info can be found in #12549 around the motivation for this change, but I ended up raising a PR to make a simple dynamic setting.

Related Issues

Resolves #1526 #12549

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Failing checks are inspected and point to the corresponding known issue(s) (See: Troubleshooting Failing Builds)
  • Commits are signed per the DCO using --signoff
  • Commit changes are listed out in CHANGELOG.md file (See: Changelog)
  • Public documentation issue/PR created

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com>
Copy link
Contributor

github-actions bot commented May 6, 2024

❌ Gradle check result for dd140e2: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Comment on lines 404 to 405
IndexSearcher.setMaxClauseCount(INDICES_MAX_CLAUSE_COUNT_SETTING.get(settings));
clusterService.getClusterSettings().addSettingsUpdateConsumer(INDICES_MAX_CLAUSE_COUNT_SETTING, IndexSearcher::setMaxClauseCount);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add local settings consumer? That can further delegate the new value to IndexSearcher.setMaxClauseCount. The local attribute can be used as is within checkForTooManyFields method above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thx @jainankitk for the feedback! I'm wondering what the use-case for the consumer might be? If we're only setting the searcher clause count and feeding it to the settings consumer wouldn't that be enough?

Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of below expression? Is it possible to override this setting at index or request level? If not, we can add getter in search using the consumer mentioned above.

Integer limit = SearchService.INDICES_MAX_CLAUSE_COUNT_SETTING.get(context.getIndexSettings().getSettings());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It registers a consumer for and adds it to the cluster settings. The consumer is the IndexSearcher.setMaxClauseCount.

Is it possible to override this setting at index or request level?

It is only possible to override this setting at the cluster level since we'd want all indices to have this effect.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is only possible to override this setting at the cluster level since we'd want all indices to have this effect.

In that case, why not change to below:

this.setMaxClauseCount(INDICES_MAX_CLAUSE_COUNT_SETTING.get(settings));
clusterService.getClusterSettings().addSettingsUpdateConsumer(INDICES_MAX_CLAUSE_COUNT_SETTING, this::setMaxClauseCount);
private void setMaxClauseCount(int maxClauseCount) {
  this.maxClauseCount = maxClauseCount;
  IndexSearcher.setMaxClauseCount(maxClauseCount);
}

// Used in SearchModule above
public int getMaxClauseCount() {
  return this.maxClauseCount;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made it a static method and now using getter and setter.

Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com>
Copy link
Contributor

github-actions bot commented May 7, 2024

❌ Gradle check result for 28d5525: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com>
@@ -177,7 +177,7 @@ static Map<String, Float> resolveMappingField(
}

static void checkForTooManyFields(int numberOfFields, QueryShardContext context, @Nullable String inputPattern) {
Integer limit = SearchModule.INDICES_MAX_CLAUSE_COUNT_SETTING.get(context.getIndexSettings().getSettings());
Integer limit = SearchService.INDICES_MAX_CLAUSE_COUNT_SETTING.get(context.getIndexSettings().getSettings());
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be changed to below:

Integer limit = SearchService.getMaxClauseCount();

Comment on lines 404 to 405
IndexSearcher.setMaxClauseCount(INDICES_MAX_CLAUSE_COUNT_SETTING.get(settings));
clusterService.getClusterSettings().addSettingsUpdateConsumer(INDICES_MAX_CLAUSE_COUNT_SETTING, IndexSearcher::setMaxClauseCount);
Copy link
Contributor

Choose a reason for hiding this comment

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

It is only possible to override this setting at the cluster level since we'd want all indices to have this effect.

In that case, why not change to below:

this.setMaxClauseCount(INDICES_MAX_CLAUSE_COUNT_SETTING.get(settings));
clusterService.getClusterSettings().addSettingsUpdateConsumer(INDICES_MAX_CLAUSE_COUNT_SETTING, this::setMaxClauseCount);
private void setMaxClauseCount(int maxClauseCount) {
  this.maxClauseCount = maxClauseCount;
  IndexSearcher.setMaxClauseCount(maxClauseCount);
}

// Used in SearchModule above
public int getMaxClauseCount() {
  return this.maxClauseCount;
}

Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com>
Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com>
Copy link
Contributor

github-actions bot commented Jun 5, 2024

❌ Gradle check result for b11ca0b: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

github-actions bot commented Jun 5, 2024

❌ Gradle check result for a65cecc: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

github-actions bot commented Jun 5, 2024

❌ Gradle check result for de6d547: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

github-actions bot commented Jun 5, 2024

❌ Gradle check result for 05f8d30: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

github-actions bot commented Jun 5, 2024

❌ Gradle check result for 05f8d30: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

github-actions bot commented Jun 5, 2024

❌ Gradle check result for 55496a4: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com>
Copy link
Contributor

github-actions bot commented Jun 5, 2024

❌ Gradle check result for 15d3f96: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com>
@harshavamsi harshavamsi added the v2.15.0 Issues and PRs related to version 2.15.0 label Jun 5, 2024
@harshavamsi
Copy link
Contributor Author

@msfroh @reta @dblock could you take a look?

Copy link
Contributor

@jainankitk jainankitk left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -177,7 +177,7 @@ static Map<String, Float> resolveMappingField(
}

static void checkForTooManyFields(int numberOfFields, QueryShardContext context, @Nullable String inputPattern) {
Integer limit = SearchModule.INDICES_MAX_CLAUSE_COUNT_SETTING.get(context.getIndexSettings().getSettings());
int limit = SearchService.INDICES_MAX_CLAUSE_COUNT_SETTING.get(context.getIndexSettings().getSettings());
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not have getMaxClauseCount in SearchService as suggested earlier as well:

public int getMaxClauseCount() {
  return this.maxClauseCount;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, I think the problem there would be to make maxClauseCount static. If we do make it static the clause count is not dynamically update-able. I could be wrong here

Copy link
Contributor

Choose a reason for hiding this comment

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

No, you're right. Also, the QueryParserHelper class is helper, so makes sense for it to be static and not have the SearchService instance injected. Thanks for clarifying!

Copy link
Contributor

github-actions bot commented Jun 6, 2024

❌ Gradle check result for 75331e8: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@harshavamsi
Copy link
Contributor Author

❌ Gradle check result for 75331e8: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

#13600

@@ -465,6 +480,11 @@ private void setLowLevelCancellation(Boolean lowLevelCancellation) {
this.lowLevelCancellation = lowLevelCancellation;
}

private void setMaxClauseCount(int maxClauseCount) {
this.maxClauseCount = maxClauseCount;
IndexSearcher.setMaxClauseCount(maxClauseCount);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, this is the only shaky place I see: trying to apply volatile semantics (maxClauseCount) to non-volatile static variable (IndexSearcher::maxClauseCount). It is certainly safer to keep this setting static, @msfroh wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@reta is there any way forward other than making IndexSearcher::maxClauseCount volatile within lucene itself? I understand the semantics of this affect per shard state where some shards will reference the old clause count and new ones will have the new count but eventually consistency will prevail

Copy link
Collaborator

Choose a reason for hiding this comment

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

@reta is there any way forward other than making IndexSearcher::maxClauseCount volatile within lucene itself?

No (AFAIK), we need changes in Apache Lucene (either non static args or thread friendly primitives). We just need to accept the limitation may be and document that behaviour.

Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com>
Copy link
Contributor

github-actions bot commented Jun 6, 2024

❌ Gradle check result for a265a2e: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

github-actions bot commented Jun 6, 2024

❌ Gradle check result for 7ede1eb: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com>
Copy link
Contributor

github-actions bot commented Jun 6, 2024

✅ Gradle check result for dd840fa: SUCCESS

Copy link

codecov bot commented Jun 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.71%. Comparing base (b15cb0c) to head (dd840fa).
Report is 363 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #13568      +/-   ##
============================================
+ Coverage     71.42%   71.71%   +0.29%     
- Complexity    59978    61529    +1551     
============================================
  Files          4985     5081      +96     
  Lines        282275   289040    +6765     
  Branches      40946    41826     +880     
============================================
+ Hits         201603   207295    +5692     
- Misses        63999    64635     +636     
- Partials      16673    17110     +437     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch enhancement Enhancement or improvement to existing feature or request Search Search query, autocomplete ...etc v2.15.0 Issues and PRs related to version 2.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic max boolean clause counts
3 participants