salvatorecampagna commented on code in PR #15378:
URL: https://github.com/apache/lucene/pull/15378#discussion_r2482351737
##########
lucene/core/src/java/org/apache/lucene/index/MergePolicy.java:
##########
@@ -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() {
+ 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() {
Review Comment:
You're right, the naming is confusing. "New" is ambiguous: does it mean not
yetstarted? Does it include in-progress or completed merges?
`numMerges() > 0` is much clearer and eliminates the ambiguity.
I'll remove `hasNewMerges()` and update all test call sites to use
`numMerges() > 0` instead.
One less method to maintain and better clarity.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]