Fix race condition in LuceneIndex GraphDirectory during store#628
Merged
Fix race condition in LuceneIndex GraphDirectory during store#628
Conversation
…ization Lucene's default ConcurrentMergeScheduler runs background merge threads that modify the GraphDirectory's fileEntries map concurrently with GigaMap#store, causing BinaryPersistenceException with inconsistent element counts. Use SerialMergeScheduler when GraphDirectory is active to ensure merges run on the caller's thread under the GigaMap lock.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a concurrency issue when using the in-graph Lucene GraphDirectory by preventing Lucene from mutating the persistent fileEntries map from background merge threads during GigaMap serialization.
Changes:
- Refactors
lazyInit()to build a reusableIndexWriterConfigand conditionally configure aSerialMergeScheduler. - Introduces
usesGraphDirectory()and simplifiescreateDirectory()to centralize the “in-graph vs external directory” decision.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
zdenek-jonas
approved these changes
Mar 30, 2026
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.
This pull request refactors the initialization logic for the Lucene index in
LuceneIndex.java, primarily to improve clarity and ensure thread safety when using aGraphDirectory. The main changes involve extracting logic for determining directory type and configuring merge schedulers to prevent concurrency issues.Initialization and thread safety improvements:
GraphDirectoryis used into a newusesGraphDirectory()method, improving readability and maintainability.createDirectory()to useusesGraphDirectory(), clarifying the choice betweenGraphDirectoryand a custom directory creator.lazyInit(), when using aGraphDirectory, configured theIndexWriterConfigto use aSerialMergeSchedulerinstead of the defaultConcurrentMergeScheduler, ensuring merges run on the caller's thread and preventing race conditions with GigaMap serialization.These changes help ensure that Lucene index merges are handled safely in environments where background thread concurrency could cause data corruption or race conditions.