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

Fix IndexReader ref leak when Lucene index modified and read in transaction #10261

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,8 @@ public boolean hasNext() {
final boolean hasNext = index < (totalHits - deletedMatchCount);
if (!hasNext && !closed) {
final IndexSearcher searcher = queryContext.getSearcher();
if (searcher.getIndexReader().getRefCount() > 1) {
engine.release(searcher);
closed = true;
}
engine.release(searcher);
closed = true;
}
return hasNext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Map;
import java.util.Optional;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.MultiReader;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
Expand Down Expand Up @@ -104,9 +105,15 @@ public IndexSearcher getSearcher() {
}

private MultiReader multiReader(final OLuceneTxChanges luceneTxChanges) {
final IndexReader primaryReader = searcher.getIndexReader();
final IndexReader txReader = luceneTxChanges.searcher().getIndexReader();
try {
return new MultiReader(
searcher.getIndexReader(), luceneTxChanges.searcher().getIndexReader());
// Transfer ownership to the MultiReader so the index searcher can be releases transparently.
// Without this, the primary IndexReader will leak a refcount each time it is wrapped.
MultiReader multiReader = new MultiReader(new IndexReader[] {primaryReader, txReader}, false);
primaryReader.decRef();
txReader.decRef();
return multiReader;
} catch (final IOException e) {
throw OException.wrapException(
new OLuceneIndexException("unable to create reader on changes"), e);
Expand Down
Loading