|
21 | 21 |
|
22 | 22 | import java.io.Closeable;
|
23 | 23 | import java.io.IOException;
|
| 24 | +import java.io.UncheckedIOException; |
24 | 25 | import java.time.Instant;
|
25 | 26 | import java.util.ArrayDeque;
|
26 | 27 | import java.util.ArrayList;
|
@@ -3285,6 +3286,11 @@ public AddIndexesMergeSource(IndexWriter writer) {
|
3285 | 3286 | }
|
3286 | 3287 |
|
3287 | 3288 | public void registerMerge(MergePolicy.OneMerge merge) {
|
| 3289 | + try { |
| 3290 | + addEstimatedBytesToMerge(merge); |
| 3291 | + } catch (IOException e) { |
| 3292 | + throw new UncheckedIOException(e); |
| 3293 | + } |
3288 | 3294 | synchronized (IndexWriter.this) {
|
3289 | 3295 | pendingAddIndexesMerges.add(merge);
|
3290 | 3296 | }
|
@@ -4777,6 +4783,21 @@ private void abortOneMerge(MergePolicy.OneMerge merge) throws IOException {
|
4777 | 4783 | closeMergeReaders(merge, true, false);
|
4778 | 4784 | }
|
4779 | 4785 |
|
| 4786 | + /** Compute {@code estimatedMergeBytes} and {@code totalMergeBytes} for a merge. */ |
| 4787 | + void addEstimatedBytesToMerge(MergePolicy.OneMerge merge) throws IOException { |
| 4788 | + assert merge.estimatedMergeBytes == 0; |
| 4789 | + assert merge.totalMergeBytes == 0; |
| 4790 | + for (SegmentCommitInfo info : merge.segments) { |
| 4791 | + if (info.info.maxDoc() > 0) { |
| 4792 | + final int delCount = numDeletedDocs(info); |
| 4793 | + assert delCount <= info.info.maxDoc(); |
| 4794 | + final double delRatio = ((double) delCount) / info.info.maxDoc(); |
| 4795 | + merge.estimatedMergeBytes += (long) (info.sizeInBytes() * (1.0 - delRatio)); |
| 4796 | + merge.totalMergeBytes += info.sizeInBytes(); |
| 4797 | + } |
| 4798 | + } |
| 4799 | + } |
| 4800 | + |
4780 | 4801 | /**
|
4781 | 4802 | * Checks whether this merge involves any segments already participating in a merge. If not, this
|
4782 | 4803 | * merge is "registered", meaning we record that its segments are now participating in a merge,
|
@@ -4868,17 +4889,7 @@ private synchronized boolean registerMerge(MergePolicy.OneMerge merge) throws IO
|
4868 | 4889 | mergingSegments.add(info);
|
4869 | 4890 | }
|
4870 | 4891 |
|
4871 |
| - assert merge.estimatedMergeBytes == 0; |
4872 |
| - assert merge.totalMergeBytes == 0; |
4873 |
| - for (SegmentCommitInfo info : merge.segments) { |
4874 |
| - if (info.info.maxDoc() > 0) { |
4875 |
| - final int delCount = numDeletedDocs(info); |
4876 |
| - assert delCount <= info.info.maxDoc(); |
4877 |
| - final double delRatio = ((double) delCount) / info.info.maxDoc(); |
4878 |
| - merge.estimatedMergeBytes += (long) (info.sizeInBytes() * (1.0 - delRatio)); |
4879 |
| - merge.totalMergeBytes += info.sizeInBytes(); |
4880 |
| - } |
4881 |
| - } |
| 4892 | + addEstimatedBytesToMerge(merge); |
4882 | 4893 |
|
4883 | 4894 | // Merge is now registered
|
4884 | 4895 | merge.registerDone = true;
|
|
0 commit comments