Repository navigation
SOLR-18551: Prevent mmap leak in IndexFetcher - #5173
Open
gerlowskija wants to merge 2 commits into
Open
gerlowskija wants to merge 2 commits into
gerlowskija wants to merge 2 commits into
Conversation
Prior to this commit, IndexFetcher's "slowFileExists" method checked existence by attempting to open and then close the file. When MMapDirectoryFactory was in use, this "open" creates an mmap that remains somewhat "leaked" until the DirectoryReader is closed, due to idiosyncracies in how Lucene pools mmaps into "arenas" based on their segment. This caused a pretty significant mmap leak in later Solr 9.x releases. It's less likely to impact Solr 10.x or later versions due to changes in Lucene, but it's still possible. This commit fixes the issue by reworking IndexFetcher's "exists" check. Now instead of opening the file, IndexFetcher does a size-check which can be used to determine existence with only an OS 'stat' call and without creating an mmap at all.
jaykay12
reviewed
Oct 16, 2026
jaykay12
left a comment
Contributor
There was a problem hiding this comment.
+1 on using fileLength - definitely better than READONCE for just existence check.
Please fix the PR title to SOLR-18551
also, will this be backported in 9.x branch?
| } | ||
|
|
||
| /** | ||
| * Returns true if the file exists (can be opened), false if it cannot be opened, and (unlike |
Contributor
There was a problem hiding this comment.
Lets refresh this javadoc as well?
dsmiley
approved these changes
Oct 16, 2026
dsmiley
left a comment
Contributor
There was a problem hiding this comment.
the PR template 1st line includes a JIRA URL with that is to be edited. Please retain that. Otherwise, as a reviewer I have extra steps to go look in JIRA beyond clicking a link.
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-18551
Description
Prior to this commit, IndexFetcher's "slowFileExists" method checked existence by attempting to open and then close the file. When MMapDirectoryFactory was in use, this "open" creates an mmap that remains somewhat "leaked" until the DirectoryReader is closed, due to idiosyncracies in how Lucene pools mmaps into "arenas" based on their segment.
This caused a pretty significant mmap leak in later Solr 9.x releases. It's less likely to impact Solr 10.x or later versions due to changes in Lucene, but it's still possible.
Solution
This commit fixes the issue by reworking IndexFetcher's "exists" check. Now instead of opening the file, IndexFetcher does a size-check which can be used to determine existence with only an OS 'stat' call and without creating an mmap at all.
Tests
None. I'd like to write tests here, but I can't think of a good way to write an automated test for this. If anyone has ideas I'm very open to suggestions!
Checklist
Please review the following and check all that apply:
mainbranch../gradlew check.