mirror of https://github.com/apache/lucene.git
LUCENE-10574: Fix TestTieredMergePolicy's expectations about the segment count.
This commit is contained in:
parent
8db1e41fc0
commit
318177af83
|
@ -53,6 +53,7 @@ public class TestTieredMergePolicy extends BaseMergePolicyTestCase {
|
||||||
int totalDelCount = 0;
|
int totalDelCount = 0;
|
||||||
int totalMaxDoc = 0;
|
int totalMaxDoc = 0;
|
||||||
long totalBytes = 0;
|
long totalBytes = 0;
|
||||||
|
List<Long> segmentSizes = new ArrayList<>();
|
||||||
for (SegmentCommitInfo sci : infos) {
|
for (SegmentCommitInfo sci : infos) {
|
||||||
totalDelCount += sci.getDelCount();
|
totalDelCount += sci.getDelCount();
|
||||||
totalMaxDoc += sci.info.maxDoc();
|
totalMaxDoc += sci.info.maxDoc();
|
||||||
|
@ -60,6 +61,7 @@ public class TestTieredMergePolicy extends BaseMergePolicyTestCase {
|
||||||
double liveRatio = 1 - (double) sci.getDelCount() / sci.info.maxDoc();
|
double liveRatio = 1 - (double) sci.getDelCount() / sci.info.maxDoc();
|
||||||
long weightedByteSize = (long) (liveRatio * byteSize);
|
long weightedByteSize = (long) (liveRatio * byteSize);
|
||||||
totalBytes += weightedByteSize;
|
totalBytes += weightedByteSize;
|
||||||
|
segmentSizes.add(weightedByteSize);
|
||||||
minSegmentBytes = Math.min(minSegmentBytes, weightedByteSize);
|
minSegmentBytes = Math.min(minSegmentBytes, weightedByteSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +91,25 @@ public class TestTieredMergePolicy extends BaseMergePolicyTestCase {
|
||||||
}
|
}
|
||||||
allowedSegCount = Math.max(allowedSegCount, tmp.getSegmentsPerTier());
|
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();
|
int numSegments = infos.asList().size();
|
||||||
assertTrue(
|
assertTrue(
|
||||||
String.format(
|
String.format(
|
||||||
|
@ -104,7 +125,7 @@ public class TestTieredMergePolicy extends BaseMergePolicyTestCase {
|
||||||
totalBytes,
|
totalBytes,
|
||||||
delPercentage,
|
delPercentage,
|
||||||
tmp.getDeletesPctAllowed()),
|
tmp.getDeletesPctAllowed()),
|
||||||
numSegments <= allowedSegCount);
|
numSegments <= allowedSegCount || hasBalancedMerges == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue