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

TimeSeries Desc Sort gets skipped with Lucene 10 upgrade #17329

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

Conversation

expani
Copy link
Contributor

@expani expani commented Feb 11, 2025

Description

We override IndexSearcher#search(List<LeafReaderContext> leaves, Weight weight, Collector collector) and it contains the logic to apply time series desc optimisation for scanning segments in reverse for descending sort use-cases.

Existing Lucene 9.12.1 and OS 2.19 call flow

Screenshot 2025-02-11 at 2 40 05 PM

Lucene 10.1.0 and OS 3.0 call flow

Screenshot 2025-02-11 at 2 40 52 PM

With Lucene 10 changes, the new replacement method

search(LeafReaderContextPartition[] partitions, Weight weight, Collector collector)

only gets invoked via IndexSearcher#search(Query, CollecterManager) which is not used by OpenSearch in QueryPhase#searchWithCollector.

So, it was never getting called causing the time series desc optimization to be skipped.

My changes ensure it will be called in the same way that IndexSearcher does for CollectorManager variant.

Related Issues

Resolves #16934

@expani
Copy link
Contributor Author

expani commented Feb 11, 2025

@msfroh @reta Please help in reviewing the same.

I am trying to see if there is an easy to catch this with existing UTs as well.

@reta
Copy link
Collaborator

reta commented Feb 11, 2025

I am trying to see if there is an easy to catch this with existing UTs as well.

This is explains the xxx_desc regressions in OSB, thanks @expani !

@expani
Copy link
Contributor Author

expani commented Feb 11, 2025

@reta With this change, OS 2.19 and OS 3.0 are at same for following query types in big5

asc_sort_timestamp
asc_sort_timestamp_can_match_shortcut
asc_sort_timestamp_no_can_match_shortcut

Without it, the latency for OS 3.0 was 10ms more than OS 2.19

Copy link
Contributor

❌ Gradle check result for 21d5903: 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 368383f: 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?

// TODO : Remove when switching to use the @org.apache.lucene.search.IndexSearcher#search(Query, CollectorManager) variant from
// @org.opensearch.search.query.QueryPhase#searchWithCollector which then calls the overridden
// search(LeafReaderContextPartition[] partitions, Weight weight, Collector collector)
query = collector.scoreMode().needsScores() ? rewrite(query) : rewrite(new ConstantScoreQuery(query));
Copy link
Collaborator

Choose a reason for hiding this comment

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

@msfroh this change make sense to me to restore searchContext.shouldUseTimeSeriesDescSortOptimization() optimization, wdyt?

Copy link
Contributor

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

query = collector.scoreMode().needsScores() ? rewrite(query) : rewrite(new ConstantScoreQuery(query));
Weight weight = createWeight(query, collector.scoreMode(), 1);
LeafSlice[] leafSlices = getSlices();
for (LeafSlice leafSlice : leafSlices) {
Copy link
Collaborator

@reta reta Feb 12, 2025

Choose a reason for hiding this comment

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

@expani I think we should get all partitions across all slices and call search only once:

LeafReaderContextPartition[] partitions = Arrays.stream(getSlices()).flatMap(LeafSlice::partitions).toArray();
search(partitions, weight, collector)

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we can override the logic in getSlices, we could even handle the desc sort use-case more efficiently by returning slices that contain leafcontextpartitions with the higher doc ids and front-load those.

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 the suggestions @reta @msfroh

I am still facing regression with desc_sort_timestamp and it's variants let me try fixing using these and will update in sometime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Other skip-changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Performance Comparison of OS 3.0 Lucene 10 with Mainline
3 participants