Skip to content

Commit

Permalink
feat: soft delete optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
fudongyingluck committed Jun 9, 2023
1 parent 5b63a18 commit d21ae98
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
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 @@ -295,9 +295,8 @@ private List<SegmentSizeAndDocs> getSortedBySegmentSize(
List<SegmentSizeAndDocs> sortedBySize = new ArrayList<>();

for (SegmentCommitInfo info : infos) {
sortedBySize.add(
new SegmentSizeAndDocs(
info, size(info, mergeContext), mergeContext.numDeletesToMerge(info)));
final int delCount = mergeContext.numDeletesToMerge(info);
sortedBySize.add(new SegmentSizeAndDocs(info, size(info, delCount), delCount));
}

sortedBySize.sort(
Expand Down

0 comments on commit d21ae98

Please sign in to comment.