Skip to content

Throw exceptions if nextOrd called more than docValueCount times #17649

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

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

Conversation

msfroh
Copy link
Contributor

@msfroh msfroh commented Mar 21, 2025

Description

This is a work in progress to try to catch cases where we're calling nextOrd() more than docValueCount() times on SortedSetDocValues.

Related Issues

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

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.

Copy link
Contributor

❌ Gradle check result for c7b46c0: 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?

@@ -365,6 +366,9 @@ public int docValueCount() {
@Override
public long nextOrd() throws IOException {
if (hasOrds) {
if (++ordCount > values.docValueCount()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@msfroh This is failing due to the check we are doing here.

The values here is MultiOrdinals$MultiOrds ( for TermsAggregatorTests #testBucketInTermsAggregationWithMissingValue ) and its docValueCount decreases with each call to nextOrd

 public int docValueCount() {
      return Math.toIntExact(currentEndOffset - currentOffset);
}

Copy link
Contributor

@expani expani Mar 28, 2025

Choose a reason for hiding this comment

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

This behavior is the same since Lucene 9.2.0 upgrade so shouldn't be a problem. 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.

Hmm... that implementation in MultiDocs seems wrong. The response for docValueCount() should only change when we move to another doc. If it's changing as a result of nextOrd calls, that's wrong.

Copy link
Contributor

❌ Gradle check result for 5ff7e4d: 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

❌ Gradle check result for a9da573: 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?

@msfroh msfroh force-pushed the explosive_next_ord branch from a9da573 to e2d6961 Compare March 31, 2025 21:55
Copy link
Contributor

✅ Gradle check result for e2d6961: SUCCESS

Copy link

codecov bot commented Mar 31, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 7 lines in your changes missing coverage. Please review.

Project coverage is 72.44%. Comparing base (8182bb0) to head (e2d6961).
Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
...rch/search/aggregations/support/MissingValues.java 33.33% 2 Missing and 2 partials ⚠️
...index/fielddata/ordinals/GlobalOrdinalMapping.java 0.00% 2 Missing ⚠️
...search/index/fielddata/ordinals/MultiOrdinals.java 75.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #17649      +/-   ##
============================================
+ Coverage     72.29%   72.44%   +0.15%     
- Complexity    65900    66011     +111     
============================================
  Files          5350     5350              
  Lines        306185   306190       +5     
  Branches      44373    44375       +2     
============================================
+ Hits         221347   221815     +468     
+ Misses        66670    66193     -477     
- Partials      18168    18182      +14     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@msfroh msfroh changed the title [DRAFT] Throw exceptions if nextOrd called more than docValueCount times Throw exceptions if nextOrd called more than docValueCount times Apr 4, 2025
}

@Override
public long nextOrd() throws IOException {
if (currentOffset == currentEndOffset) {
return SortedSetDocValues.NO_MORE_DOCS;
throw new IllegalStateException("nextOrd() called more than docValueCount() times");
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if this exception and Called nextOrd after docValueCount have different meaning? If not, we should reuse the same message for all instances? Should we create custom exception for this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Called nextOrd after docValueCount was something generated by IntelliJ's auto-complete. This message is better IMO. I can make it consistent across the different implementations.

In practice, these checks should be short-lived. Lucene doesn't even do checks. The JavaDoc there just says "It is illegal to call this more than docValueCount() times for the currently-positioned doc." Some implementations will just return the same value over and over. Other implementations may do something else.

I added these exceptions to highlight the places where we were doing the wrong thing. The later commits on this PR were where I fixed those places. In theory, before we ship OpenSearch 3.0, we could probably remove these exceptions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, let us make these exceptions consistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants