SOLR-18136: Fix ArrayStoreException when combining rerank with sort under multi-threaded segment-parallel search#4164
Open
limingnihao wants to merge 1 commit intoapache:mainfrom
Conversation
…nder multi-threaded segment-parallel search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://issues.apache.org/jira/browse/SOLR-18136
Description
When multi-threaded segment-parallel search is enabled (indexSearcherExecutorThreads > 0 and multiThreaded=true) and a query uses both reranking and a sort, an ArrayStoreException is thrown during the merge phase if some Lucene slices have matching documents and others do not.
Solution
The root cause is in MultiThreadedSearcher.TopDocsCM.reduce(). It decides how to merge TopDocs from different slices based solely on the type of topDocs[0]:
When ReRankCollector is used with a sort, empty-result slices return TopFieldDocs (from the underlying TopFieldCollector), while non-empty slices return plain TopDocs (after ReRankCollector.toRescoredDocs() wraps results with new TopDocs(...), discarding the TopFieldDocs subtype). If an empty-result slice is first in the array, Arrays.copyOf(..., TopFieldDocs[].class) fails because the array contains mixed types.
The fix checks all elements instead of only topDocs[0]:
When not all elements are TopFieldDocs, the code falls through to TopDocs.merge(), which handles mixed types correctly.
This fix was developed with help from an AI coding assistant (Cursor with Claude).
Tests
Added TestMultiThreadedSearcher.testReRankWithMultiThreadedSearch() which:
Checklist
Please review the following and check all that apply:
mainbranch../gradlew check.