-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Return MergeObserver from IndexWriter.forceMergeDeletes() (#14515) #15378
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
Changes from 2 commits
53dbb7f
d8790f0
05b8266
a1b3d13
9ca3ea0
c0708b9
4ad6ff0
a50a851
5dfaa08
2d055e0
353b253
5b015ff
58882a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -939,4 +939,96 @@ static final class MergeReader { | |
| this.hardLiveDocs = hardLiveDocs; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Observer for merge operations returned by {@link IndexWriter#forceMergeDeletes(boolean)}. | ||
| * Provides methods to query merge status and wait for completion. | ||
| * | ||
| * <p>When no merges are needed, {@link #hasNewMerges()} returns {@code false} and {@link | ||
| * #numMerges()} returns 0. In this case, {@link #await()} returns {@code true} immediately since | ||
| * there is nothing to wait for. | ||
| * | ||
| * @lucene.experimental | ||
| */ | ||
| public static final class MergeObserver { | ||
| private final MergePolicy.MergeSpecification spec; | ||
|
|
||
| MergeObserver(MergePolicy.MergeSpecification spec) { | ||
| this.spec = spec; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the number of merges in this specification. | ||
| * | ||
| * @return number of merges, or 0 if no merges were scheduled | ||
| */ | ||
| public int numMerges() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about we also expose the no. of completed merges? You will need to run through all the OneMerge objects in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excellent suggestion! This is a far better way to provide progress tracking without exposing mutable Users can then track progress as:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Later I decided not to include completed merges in |
||
| return spec == null ? 0 : spec.merges.size(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns whether any new merges were scheduled. | ||
| * | ||
| * @return {@code true} if merges were scheduled, {@code false} if no merges needed | ||
| */ | ||
| public boolean hasNewMerges() { | ||
|
||
| return spec != null; | ||
| } | ||
|
|
||
| /** | ||
| * Waits for all merges in this specification to complete. Returns immediately if no merges were | ||
| * scheduled. | ||
| * | ||
| * @return {@code true} if all merges completed successfully or no merges were needed, {@code | ||
| * false} on error | ||
| */ | ||
| public boolean await() { | ||
| return spec == null || spec.await(); | ||
| } | ||
|
|
||
| /** | ||
| * Waits for all merges in this specification to complete, with timeout. Returns immediately if | ||
| * no merges were scheduled. | ||
| * | ||
| * @param timeout maximum time to wait | ||
| * @param unit time unit for timeout | ||
| * @return {@code true} if all merges completed within timeout or no merges were needed, {@code | ||
| * false} on timeout or error | ||
| */ | ||
| public boolean await(long timeout, TimeUnit unit) { | ||
| return spec == null || spec.await(timeout, unit); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a {@link CompletableFuture} that completes when all merges finish. Returns an | ||
| * already-completed future if no merges were scheduled. | ||
| * | ||
| * @return future that completes when merges finish | ||
| */ | ||
| public CompletableFuture<Void> awaitAsync() { | ||
| return spec == null | ||
| ? CompletableFuture.completedFuture(null) | ||
| : spec.getMergeCompletedFutures(); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return spec == null ? "MergeObserver: no merges" : spec.toString(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the merge at the specified index. Caller must ensure {@link #hasNewMerges()} returns | ||
| * {@code true} and index is within bounds. | ||
| * | ||
| * @param i merge index (0 to {@link #numMerges()} - 1) | ||
| * @return the merge at index i | ||
| * @throws IndexOutOfBoundsException if index is invalid or no merges exist | ||
| */ | ||
| public MergePolicy.OneMerge getMerge(int i) { | ||
|
||
| if (spec == null) { | ||
| throw new IndexOutOfBoundsException("No merges available"); | ||
| } | ||
| return spec.merges.get(i); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change can go into 10.4. Let's move this entry to the "API Changes" section under 10.4?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the PR is targeting main (milestone 11.0.0). According to
CONTRIBUTING.mdShould I keep the
CHANGES.txtentry in11.0.0for now, and then it gets moved to10.4in a backport PR if needed? Or should I change it to10.4now and update the milestone as well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We add the changes entry in the Lucene version we are targeting. All changes go to
mainbranch regardless, but the ones for a specific target branch (like 10.4 in this case) additionally get backported to 10.x.So you should just add the entry to 10.4 in this PR itself and remove it from 11.0. After I merge this into main, i'll backport the commit to 10.x branch. Will reach out to you if I need any help with backport.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick question for future contributions: How do I know upfront which version a change is targeting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally default to the next minor version. If it's a breaking change or a major change in existing behavior, we defer it for a major version release.