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

Reduce DeletesMerges time when softdelete enable #12350

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 9 additions & 1 deletion lucene/core/src/java/org/apache/lucene/index/MergePolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,16 @@ public boolean useCompoundFile(
* non-deleted documents is set.
*/
protected long size(SegmentCommitInfo info, MergeContext mergeContext) throws IOException {
long byteSize = info.sizeInBytes();
int delCount = mergeContext.numDeletesToMerge(info);
return size(info, delCount);
}

/**
* Return the byte size of the provided {@link SegmentCommitInfo}, pro-rated by percentage of
* non-deleted documents is set.
*/
protected final long size(SegmentCommitInfo info, int delCount) throws IOException {
long byteSize = info.sizeInBytes();
assert assertDelCount(delCount, info);
double delRatio =
info.info.maxDoc() <= 0 ? 0d : (double) delCount / (double) info.info.maxDoc();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,21 +915,30 @@ public MergeSpecification findForcedDeletesMerges(SegmentInfos infos, MergeConte
final Set<SegmentCommitInfo> merging = mergeContext.getMergingSegments();

boolean haveWork = false;
List<SegmentSizeAndDocs> sortedInfos = new ArrayList<>();
for (SegmentCommitInfo info : infos) {
int delCount = mergeContext.numDeletesToMerge(info);
assert assertDelCount(delCount, info);
sortedInfos.add(new SegmentSizeAndDocs(info, size(info, delCount), delCount));
double pctDeletes = 100. * ((double) delCount) / info.info.maxDoc();
if (pctDeletes > forceMergeDeletesPctAllowed && !merging.contains(info)) {
haveWork = true;
break;
}
}

if (haveWork == false) {
return null;
}

List<SegmentSizeAndDocs> sortedInfos = getSortedBySegmentSize(infos, mergeContext);
sortedInfos.sort(
(o1, o2) -> {
// Sort by largest size:
int cmp = Long.compare(o2.sizeInBytes, o1.sizeInBytes);
if (cmp == 0) {
cmp = o1.name.compareTo(o2.name);
}
return cmp;
});

Iterator<SegmentSizeAndDocs> iter = sortedInfos.iterator();
while (iter.hasNext()) {
Expand Down