Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow LogMergePolicy to merge more than mergeFactor segments together when the merge is below the min merge size. #14166

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ Improvements
BulkAdder#add(IntsRef) method. They should provide better performance due to less virtual method calls and
more efficient bulk processing. (Ignacio Vera)

* GITHUB#14166: Log(ByteSize|Doc)MergePolicy now allow merging more than
mergeFactor segments together when the merge is below the min merge size.
(Adrien Grand)

Optimizations
---------------------

Expand Down
22 changes: 22 additions & 0 deletions lucene/core/src/java/org/apache/lucene/index/LogMergePolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,28 @@ public MergeSpecification findMerges(
mergeDocs += segmentDocs;
}

if (end - start >= mergeFactor && mergeSize < minMergeSize && anyMerging == false) {
// If the merge has mergeFactor segments but is still smaller than the min merged segment
// size, keep packing candidate segments.
while (end < 1 + upto) {
final SegmentInfoAndLevel segLevel = levels.get(end);
final SegmentCommitInfo info = segLevel.info;
if (mergingSegments.contains(info)) {
anyMerging = true;
break;
}
long segmentSize = size(info, mergeContext);
long segmentDocs = sizeDocs(info, mergeContext);
if (mergeSize + segmentSize > minMergeSize || mergeDocs + segmentDocs > maxMergeDocs) {
break;
}

mergeSize += segmentSize;
mergeDocs += segmentDocs;
end++;
}
}

if (anyMerging || end - start <= 1) {
// skip: there is an ongoing merge at the current level or the computed merge has a single
// segment and this merge policy doesn't do singleton merges
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ protected void assertSegmentInfos(MergePolicy policy, SegmentInfos infos) throws
@Override
protected void assertMerge(MergePolicy policy, MergeSpecification merge) throws IOException {
LogMergePolicy lmp = (LogMergePolicy) policy;
MergeContext mockMergeContext = new MockMergeContext(SegmentCommitInfo::getDelCount);
for (OneMerge oneMerge : merge.merges) {
assertTrue(oneMerge.segments.size() <= lmp.getMergeFactor());
long mergeSize = 0;
for (SegmentCommitInfo info : oneMerge.segments) {
mergeSize += lmp.size(info, mockMergeContext);
}
assertTrue(mergeSize < lmp.minMergeSize || oneMerge.segments.size() <= lmp.getMergeFactor());
}
}

Expand Down
Loading