diff --git a/lucene/core/src/java/org/apache/lucene/index/MergePolicy.java b/lucene/core/src/java/org/apache/lucene/index/MergePolicy.java index 50d81ad6941..b344d41e5ba 100644 --- a/lucene/core/src/java/org/apache/lucene/index/MergePolicy.java +++ b/lucene/core/src/java/org/apache/lucene/index/MergePolicy.java @@ -117,8 +117,9 @@ public abstract class MergePolicy { * @param segments List of {@link SegmentCommitInfo}s * to be merged. */ public OneMerge(List segments) { - if (0 == segments.size()) + if (0 == segments.size()) { throw new RuntimeException("segments must include at least one segment"); + } // clone the list, as the in list may be based off original SegmentInfos and may be modified this.segments = new ArrayList<>(segments); int count = 0; @@ -239,14 +240,17 @@ public abstract class MergePolicy { StringBuilder b = new StringBuilder(); final int numSegments = segments.size(); for(int i=0;i 0) b.append(' '); + if (i > 0) { + b.append(' '); + } b.append(segments.get(i).toString(dir, 0)); } if (info != null) { b.append(" into ").append(info.info.name); } - if (maxNumSegments != -1) + if (maxNumSegments != -1) { b.append(" [maxNumSegments=" + maxNumSegments + "]"); + } if (aborted) { b.append(" [ABORTED]"); } @@ -312,8 +316,9 @@ public abstract class MergePolicy { StringBuilder b = new StringBuilder(); b.append("MergeSpec:\n"); final int count = merges.size(); - for(int i=0;i=0 (got " + v + ")"); } v *= 1024 * 1024; - this.maxCFSSegmentSize = (v > Long.MAX_VALUE) ? Long.MAX_VALUE : (long) v; + this.maxCFSSegmentSize = v > Long.MAX_VALUE ? Long.MAX_VALUE : (long) v; } } diff --git a/lucene/core/src/java/org/apache/lucene/index/TieredMergePolicy.java b/lucene/core/src/java/org/apache/lucene/index/TieredMergePolicy.java index 1f7bb9c01cc..049c067b4ab 100644 --- a/lucene/core/src/java/org/apache/lucene/index/TieredMergePolicy.java +++ b/lucene/core/src/java/org/apache/lucene/index/TieredMergePolicy.java @@ -142,7 +142,7 @@ public class TieredMergePolicy extends MergePolicy { throw new IllegalArgumentException("maxMergedSegmentMB must be >=0 (got " + v + ")"); } v *= 1024 * 1024; - maxMergedSegmentBytes = (v > Long.MAX_VALUE) ? Long.MAX_VALUE : (long) v; + maxMergedSegmentBytes = v > Long.MAX_VALUE ? Long.MAX_VALUE : (long) v; return this; } @@ -183,7 +183,7 @@ public class TieredMergePolicy extends MergePolicy { throw new IllegalArgumentException("floorSegmentMB must be >= 0.0 (got " + v + ")"); } v *= 1024 * 1024; - floorSegmentBytes = (v > Long.MAX_VALUE) ? Long.MAX_VALUE : (long) v; + floorSegmentBytes = v > Long.MAX_VALUE ? Long.MAX_VALUE : (long) v; return this; } @@ -314,8 +314,12 @@ public class TieredMergePolicy extends MergePolicy { // If we have too-large segments, grace them out // of the maxSegmentCount: int tooBigCount = 0; - while (tooBigCount < infosSorted.size() && size(infosSorted.get(tooBigCount), writer) >= maxMergedSegmentBytes/2.0) { - totIndexBytes -= size(infosSorted.get(tooBigCount), writer); + while (tooBigCount < infosSorted.size()) { + long segBytes = size(infosSorted.get(tooBigCount), writer); + if (segBytes < maxMergedSegmentBytes/2.0) { + break; + } + totIndexBytes -= segBytes; tooBigCount++; } @@ -351,7 +355,7 @@ public class TieredMergePolicy extends MergePolicy { for(int idx = tooBigCount; idx 0; + final MergeScore score = score(candidate, hitTooLarge, mergingBytes, writer); if (verbose(writer)) { message(" maybe=" + writer.segString(candidate) + " score=" + score.getScore() + " " + score.getExplanation() + " tooLarge=" + hitTooLarge + " size=" + String.format(Locale.ROOT, "%.3f MB", totAfterMergeBytes/1024./1024.), writer);