-
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
Draft
rahulgoswami
wants to merge
2
commits into
apache:main
Choose a base branch
from
Commvault:reindexing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+75
−0
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
solr/core/src/java/org/apache/solr/index/LatestVersionFilterMergePolicy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package org.apache.solr.index; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
| import org.apache.lucene.index.FilterMergePolicy; | ||
| 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.util.Version; | ||
|
|
||
| /** | ||
| * Prevents any older version segment (< {@link Version.LATEST}), either original or one derived as | ||
| * a result of merging with an older version segment, from being considered for merges. That way a | ||
| * snapshot of older segments remains consistent. This assists in upgrading to a future Lucene major | ||
| * version if existing documents are reindexed in the current version with this merge policy in | ||
| * place. | ||
| */ | ||
| public class LatestVersionFilterMergePolicy extends FilterMergePolicy { | ||
|
|
||
| public LatestVersionFilterMergePolicy(MergePolicy in) { | ||
| super(in); | ||
| } | ||
|
|
||
| @Override | ||
| public MergeSpecification findMerges( | ||
| MergeTrigger mergeTrigger, SegmentInfos infos, MergeContext mergeContext) throws IOException { | ||
| return in.findMerges(mergeTrigger, getFilteredInfosClone(infos), mergeContext); | ||
| } | ||
|
|
||
| @Override | ||
| public MergeSpecification findForcedMerges( | ||
| SegmentInfos infos, | ||
| int maxSegmentCount, | ||
| Map<SegmentCommitInfo, Boolean> segmentsToMerge, | ||
| MergeContext mergeContext) | ||
| throws IOException { | ||
| return in.findForcedMerges( | ||
| getFilteredInfosClone(infos), maxSegmentCount, segmentsToMerge, mergeContext); | ||
| } | ||
|
|
||
| @Override | ||
| public MergeSpecification findForcedDeletesMerges(SegmentInfos infos, MergeContext mergeContext) | ||
| throws IOException { | ||
| return in.findForcedDeletesMerges(getFilteredInfosClone(infos), mergeContext); | ||
| } | ||
|
|
||
| @Override | ||
| public MergeSpecification findFullFlushMerges( | ||
| MergeTrigger mergeTrigger, SegmentInfos infos, MergeContext mergeContext) throws IOException { | ||
| return in.findFullFlushMerges(mergeTrigger, getFilteredInfosClone(infos), mergeContext); | ||
| } | ||
|
|
||
| private SegmentInfos getFilteredInfosClone(SegmentInfos infos) { | ||
| // We should not remove from the original SegmentInfos. Hence we clone. | ||
| SegmentInfos infosClone = infos.clone(); | ||
| infosClone.clear(); | ||
| for (SegmentCommitInfo info : infos) { | ||
| if (allowSegmentForMerge(info)) { | ||
| infosClone.add(info); | ||
| } | ||
| } | ||
| return infosClone; | ||
| } | ||
|
|
||
| /** | ||
| * Determines if a SegmentCommitInfo should be part of the candidate set of segments that will be | ||
| * considered for merges. By default, we only allow LATEST version segments to participate in | ||
| * merges. | ||
| */ | ||
| protected boolean allowSegmentForMerge(SegmentCommitInfo info) { | ||
| return info.info.getMinVersion() != null | ||
| && info.info.getMinVersion().major == Version.LATEST.major; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: clone is an implementation detail that doesn't belong in the method. For example, maybe we see that rebuilding this thing is expensive-ish and we decide to first check if all segments are current to not clone. Or if no segments are updated, and return an empty one.