-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Adding support for context aware segments #19098
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
Merged
Merged
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
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
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
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
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
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
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
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
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
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
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
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
42 changes: 42 additions & 0 deletions
42
server/src/main/java/org/opensearch/index/BucketedCompositeDirectory.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,42 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.index; | ||
|
|
||
| import org.apache.lucene.store.Directory; | ||
| import org.apache.lucene.store.FilterDirectory; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Arrays; | ||
|
|
||
| /** | ||
| * Directory wrapper used to filter out child level directory for context aware enabled indices. | ||
| * | ||
| */ | ||
| public class BucketedCompositeDirectory extends FilterDirectory { | ||
|
|
||
| public static final String CHILD_DIRECTORY_PREFIX = "temp_"; | ||
RS146BIJAY marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| protected BucketedCompositeDirectory(Directory in) { | ||
| super(in); | ||
| } | ||
|
|
||
| /** | ||
| * List all files within directory filtering out child level directory. | ||
| * @return files excluding child level directory. | ||
| * | ||
| * @throws IOException in case of I/O error | ||
| */ | ||
| @Override | ||
| public String[] listAll() throws IOException { | ||
| return Arrays.stream(super.listAll()) | ||
| .filter(fileName -> !fileName.startsWith(CHILD_DIRECTORY_PREFIX)) | ||
| .distinct() | ||
| .toArray(String[]::new); | ||
| } | ||
| } | ||
82 changes: 82 additions & 0 deletions
82
server/src/main/java/org/opensearch/index/CriteriaBasedMergePolicy.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,82 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.index; | ||
|
|
||
| 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.opensearch.index.codec.CriteriaBasedCodec; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * Wrapper merge policy which is used for context aware enabled indices. This merge policy merges segments that belongs | ||
| * to same bucket. | ||
| * | ||
| */ | ||
| public class CriteriaBasedMergePolicy extends FilterMergePolicy { | ||
|
|
||
| protected final MergePolicy in; | ||
|
|
||
| public CriteriaBasedMergePolicy(MergePolicy in) { | ||
| super(in); | ||
| this.in = in; | ||
| } | ||
|
|
||
| /** | ||
| * Merges the segments belonging to same group. | ||
| * | ||
| * @param mergeTrigger the event that triggered the merge | ||
| * @param infos the total set of segments in the index | ||
| * @param mergeContext the IndexWriter to find the merges on | ||
| * @return | ||
| * @throws IOException | ||
| */ | ||
| @Override | ||
| public MergeSpecification findMerges(MergeTrigger mergeTrigger, SegmentInfos infos, MergeContext mergeContext) throws IOException { | ||
| final Set<SegmentCommitInfo> merging = mergeContext.getMergingSegments(); | ||
| MergeSpecification spec = null; | ||
| final Map<String, List<SegmentCommitInfo>> commitInfos = new HashMap<>(); | ||
| for (SegmentCommitInfo si : infos) { | ||
| if (merging.contains(si)) { | ||
| continue; | ||
| } | ||
|
|
||
| final String dwptGroupNumber = si.info.getAttribute(CriteriaBasedCodec.BUCKET_NAME); | ||
| commitInfos.computeIfAbsent(dwptGroupNumber, k -> new ArrayList<>()).add(si); | ||
| } | ||
|
|
||
| for (String dwptGroupNumber : commitInfos.keySet()) { | ||
| if (commitInfos.get(dwptGroupNumber).size() > 1) { | ||
| final SegmentInfos newSIS = new SegmentInfos(infos.getIndexCreatedVersionMajor()); | ||
| for (SegmentCommitInfo info : commitInfos.get(dwptGroupNumber)) { | ||
| newSIS.add(info); | ||
| } | ||
|
|
||
| final MergeSpecification tieredMergePolicySpec = in.findMerges(mergeTrigger, newSIS, mergeContext); | ||
| if (tieredMergePolicySpec != null) { | ||
| if (spec == null) { | ||
| spec = new MergeSpecification(); | ||
| } | ||
RS146BIJAY marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| spec.merges.addAll(tieredMergePolicySpec.merges); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return spec; | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.