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

SOLR-17670: Fix unnecessary memory allocation caused by a large reRankDocs param #3181

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

Conversation

gaojiabao1991
Copy link

@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

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