Return MergeObserver from IndexWriter.forceMergeDeletes() (#14515) #15378
+454
−15
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.
Summary
Changes
IndexWriter.forceMergeDeletes()to returnMergePolicy.MergeObserverinstead of void, allowing applications to monitor merge progress and wait for completion.Fixes #14515
Motivation
Currently when calling
forceMergeDeletes(false), there's no way to monitor whether merges were scheduled or wait for them to complete. This makes it difficult to coordinate merge completion with other operations or implement custom scheduling strategies.Changes
Added
MergePolicy.MergeObserveras a new public API with methods to:The observer is thread-safe and handles cases where no merges are needed.
Updated
IndexWriter.forceMergeDeletes()methods to return the observer instead of void. Also updatedRandomIndexWriterto propagate the new return type.Testing
Added 7 tests covering blocking and non-blocking modes, timeout handling, null spec cases, and bounds checking. All tests passed 500 iterations each with no failures.
Backward Compatibility
Fully backward compatible. Existing code that ignores the return value continues to work unchanged. Changing void to a return type is not a breaking change in Java.
Files Modified