-
Notifications
You must be signed in to change notification settings - Fork 791
SOLR-17725: Add merge policy to block older segments from participating in merges #3883
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package org.apache.solr.index; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
| import org.apache.lucene.index.MergePolicy; | ||
| import org.apache.lucene.index.MergeTrigger; | ||
| import org.apache.lucene.index.SegmentCommitInfo; | ||
| import org.apache.lucene.index.SegmentInfos; | ||
| import org.apache.lucene.index.TieredMergePolicy; | ||
| import org.apache.lucene.util.Version; | ||
|
|
||
| /** | ||
| * Only allows latest version segments to be considered for merges. That way a snapshot of older | ||
| * segments can remain consistent | ||
| */ | ||
| public class LatestVersionFilterMergePolicy extends MergePolicy { | ||
|
||
| MergePolicy delegatePolicy = new TieredMergePolicy(); | ||
|
|
||
| @Override | ||
| public MergeSpecification findMerges( | ||
| MergeTrigger mergeTrigger, SegmentInfos infos, MergeContext mergeContext) throws IOException { | ||
| /*we don't want to remove from the original SegmentInfos, else the segments may not carry forward upon a commit. | ||
|
||
| That would be catastrophic. Hence we clone.*/ | ||
| SegmentInfos infosClone = infos.clone(); | ||
| infosClone.clear(); | ||
| for (SegmentCommitInfo info : infos) { | ||
| if (info.info.getMinVersion() != null | ||
| && info.info.getMinVersion().major == Version.LATEST.major) { | ||
| infosClone.add(info); | ||
| } | ||
| } | ||
|
|
||
| return delegatePolicy.findMerges(mergeTrigger, infosClone, mergeContext); | ||
| } | ||
|
|
||
| @Override | ||
| public MergeSpecification findForcedMerges( | ||
| SegmentInfos segmentInfos, | ||
| int maxSegmentCount, | ||
| Map<SegmentCommitInfo, Boolean> segmentsToMerge, | ||
| MergeContext mergeContext) | ||
| throws IOException { | ||
| return delegatePolicy.findForcedMerges( | ||
|
||
| segmentInfos, maxSegmentCount, segmentsToMerge, mergeContext); | ||
| } | ||
|
|
||
| @Override | ||
| public MergeSpecification findForcedDeletesMerges( | ||
| SegmentInfos segmentInfos, MergeContext mergeContext) throws IOException { | ||
| return delegatePolicy.findForcedDeletesMerges(segmentInfos, mergeContext); | ||
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest this wording instead: