dweiss commented on code in PR #15120:
URL: https://github.com/apache/lucene/pull/15120#discussion_r2298924395
##########
lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMerging.java:
##########
@@ -461,4 +461,33 @@ public void run() {
directory.close();
}
+
+ public void testAddEstimatedBytesToMerge() throws IOException {
+ Directory dir = newDirectory();
+ IndexWriter writer =
+ new IndexWriter(
+ dir,
+ newIndexWriterConfig(new MockAnalyzer(random()))
+ .setMergePolicy(NoMergePolicy.INSTANCE));
+
+ Document doc = new Document();
+ doc.add(newTextField("field", "content", Field.Store.YES));
+ for (int i = 0; i < 10; i++) {
+ writer.addDocument(doc);
+ }
+ writer.flush();
+
+ // Create a merge with the segments
+ SegmentInfos segmentInfos = writer.cloneSegmentInfos();
+ MergePolicy.OneMerge merge = new
MergePolicy.OneMerge(segmentInfos.asList());
+
+ writer.addEstimatedBytesToMerge(merge);
+
+ assertTrue(merge.estimatedMergeBytes > 0);
+ assertTrue(merge.totalMergeBytes > 0);
+ assertTrue(merge.estimatedMergeBytes <= merge.totalMergeBytes);
+
+ writer.close();
+ dir.close();
Review Comment:
A try-with-resources block on both, perhaps? This is important for clean up
if a test fails.
##########
lucene/core/src/java/org/apache/lucene/index/IndexWriter.java:
##########
@@ -3285,6 +3285,11 @@ public AddIndexesMergeSource(IndexWriter writer) {
}
public void registerMerge(MergePolicy.OneMerge merge) {
+ try {
+ addEstimatedBytesToMerge(merge);
+ } catch (IOException _) {
+ // ignore and append to pending merges
Review Comment:
I would throw an UncheckedIOException here. If something is wrong, it'll be
wrong. Let the caller know early.
##########
lucene/core/src/java/org/apache/lucene/index/IndexWriter.java:
##########
@@ -4777,6 +4782,21 @@ private void abortOneMerge(MergePolicy.OneMerge merge)
throws IOException {
closeMergeReaders(merge, true, false);
}
+ /** Compute {@code estimatedMergeBytes} and {@code totalMergeBytes} for a
merge. */
+ void addEstimatedBytesToMerge(MergePolicy.OneMerge merge) throws IOException
{
Review Comment:
Can this method be static too? I wonder if it uses any IW's state at all.
--
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]