Skip to content

Conversation

gaojiabao1991
Copy link
Contributor

@gaojiabao1991 gaojiabao1991 commented Feb 13, 2025

https://issues.apache.org/jira/browse/SOLR-17670

Description

For a query containing re-ranking, such as:
{
"start": "0",
"rows": 10,
"fl": "ID,score",
"q": ":",
"rq": "{!rerank reRankQuery='{!func} 100' reRankDocs=1000000000 reRankWeight=2}"
}

The current execution logic is as follows:

  1. Perform normal retrieval using the q parameter.
  2. Re-score all documents retrieved in the q phase using the rq parameter.

During the retrieval in phase 1 (using q), a TopScoreDocCollector is created. Underneath, this creates a PriorityQueue which contains an Object[]. The length of this Object[] continuously increases with reRankDocs without any limit.

On my local test cluster with limited JVM memory, this can even trigger an OOM, causing the Solr node to crash. I can also reproduce the OOM situation using the SolrCloudTestCase unit test.

Solution

I think limiting the length of the Object[] array using searcher.getIndexReader().maxDoc() at ReRankCollector would resolve this issue. This way, when reRankDocs exceeds maxDoc, memory allocation will not continue to increase indefinitely.

Tests

TestRerankOnSolrCloud will reproduce the OOM situation without my fix.

Checklist

Please review the following and check all that apply:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have created a Jira issue and added the issue ID to my pull request title.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended, not available for branches on forks living under an organisation)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.
  • I have added documentation for the Reference Guide

@dsmiley
Copy link
Contributor

dsmiley commented Feb 22, 2025

I'll be merging this nice fix into 9.8.1

@dsmiley dsmiley merged commit 76c09a3 into apache:main Feb 22, 2025
2 of 3 checks passed
dsmiley pushed a commit that referenced this pull request Feb 22, 2025
dsmiley pushed a commit that referenced this pull request Feb 22, 2025
@gaojiabao1991
Copy link
Contributor Author

I'll be merging this nice fix into 9.8.1

Thanks so much, David!

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