LUCENE-10574: Fix TestTieredMergePolicy's expectations about the segment count.

This commit is contained in:
Adrien Grand 2022-05-30 11:28:58 +02:00
parent 8db1e41fc0
commit 318177af83
1 changed files with 22 additions and 1 deletions

View File

@ -53,6 +53,7 @@ public class TestTieredMergePolicy extends BaseMergePolicyTestCase {
int totalDelCount = 0;
int totalMaxDoc = 0;
long totalBytes = 0;
List<Long> segmentSizes = new ArrayList<>();
for (SegmentCommitInfo sci : infos) {
totalDelCount += sci.getDelCount();
totalMaxDoc += sci.info.maxDoc();
@ -60,6 +61,7 @@ public class TestTieredMergePolicy extends BaseMergePolicyTestCase {
double liveRatio = 1 - (double) sci.getDelCount() / sci.info.maxDoc();
long weightedByteSize = (long) (liveRatio * byteSize);
totalBytes += weightedByteSize;
segmentSizes.add(weightedByteSize);
minSegmentBytes = Math.min(minSegmentBytes, weightedByteSize);
}
@ -89,6 +91,25 @@ public class TestTieredMergePolicy extends BaseMergePolicyTestCase {
}
allowedSegCount = Math.max(allowedSegCount, tmp.getSegmentsPerTier());
// It's ok to be over the allowed segment count if none of the most balanced merges are balanced
// enough
Collections.sort(segmentSizes);
boolean hasBalancedMerges = false;
for (int i = 0; i < segmentSizes.size() - mergeFactor; ++i) {
long maxMergeSegmentSize = segmentSizes.get(i + mergeFactor - 1);
if (maxMergeSegmentSize >= maxMergedSegmentBytes / 2) {
break;
}
long totalMergeSize = 0;
for (int j = 0; j < i + mergeFactor; ++j) {
totalMergeSize += segmentSizes.get(j);
}
if (maxMergedSegmentBytes * 1.5 <= totalMergeSize) {
hasBalancedMerges = true;
break;
}
}
int numSegments = infos.asList().size();
assertTrue(
String.format(
@ -104,7 +125,7 @@ public class TestTieredMergePolicy extends BaseMergePolicyTestCase {
totalBytes,
delPercentage,
tmp.getDeletesPctAllowed()),
numSegments <= allowedSegCount);
numSegments <= allowedSegCount || hasBalancedMerges == false);
}
@Override