Skip to content

Conversation

@salvatorecampagna
Copy link

Summary

Changes IndexWriter.forceMergeDeletes() to return MergePolicy.MergeObserver instead 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.MergeObserver as a new public API with methods to:

  • Check merge status (hasNewMerges, numMerges)
  • Wait synchronously with optional timeout
  • Wait asynchronously via CompletableFuture
  • Access individual OneMerge instances

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 updated RandomIndexWriter to 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

  • MergePolicy.java - New MergeObserver class
  • IndexWriter.java - Updated return types and javadoc
  • RandomIndexWriter.java - Propagated return type
  • TestIndexWriterMerging.java - New tests
  • CHANGES.txt - Added entry under Improvements

@github-actions github-actions bot added this to the 11.0.0 milestone Oct 28, 2025
@salvatorecampagna salvatorecampagna force-pushed the feature/issue-14515-forceMergeDeletes-return-mergespec branch 3 times, most recently from 78dedde to 9c6683f Compare October 28, 2025 20:06
IndexWriter.forceMergeDeletes() now returns MergePolicy.MergeObserver
instead of void, allowing applications to monitor merge progress and
wait for completion. This enables coordination between merge completion
and other application logic, and supports both synchronous (await) and
asynchronous (CompletableFuture) waiting patterns.

Key capabilities:
- Query merge status: hasNewMerges(), numMerges()
- Wait synchronously: await(), await(timeout, unit)
- Wait asynchronously: awaitAsync() returns CompletableFuture<Void>
- Inspect individual merges: getMerge(int)

Changes:
- Add MergePolicy.MergeObserver nested class
- Update IndexWriter.forceMergeDeletes() methods to return MergeObserver
- Update RandomIndexWriter to propagate return type
- Add comprehensive tests (blocking/non-blocking modes, timeout handling)

Backward compatible: existing code that ignores the return value
continues to work without modification.
@salvatorecampagna salvatorecampagna force-pushed the feature/issue-14515-forceMergeDeletes-return-mergespec branch from 9c6683f to 53dbb7f Compare October 28, 2025 20:11
Measure actual merge time in testForceMergeDeletesWithObserver and
testMergeObserverAwaitWithTimeout, failing if merges take longer than
30 seconds. This helps detect stuck merges or performance regressions
while being generous enough for slow CI machines.

Both tests maintain their upper timeouts (implicit for await() and
10 minutes for await(timeout, unit)) to prevent indefinite hangs,
but now also fail fast at 30 seconds if something is wrong.
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.

IndexWriter forceMergeDeletes should return its MergeSpec

1 participant