-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13cf882
commit 6c52c00
Showing
11 changed files
with
376 additions
and
38 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
lucene/core/src/java/org/apache/lucene/index/CriteriaBasedGroupingTieredMergePolicy.java
This file contains 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,71 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.lucene.index; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* Decorator Merge policy over the existing Tiered Merge policy. During a segment merge, this policy would categorize | ||
* segments according to their grouping function outcomes before merging segments within the same category, thus | ||
* maintaining the grouping criteria’s integrity throughout the merge process. | ||
* | ||
* @lucene.experimental | ||
*/ | ||
public class CriteriaBasedGroupingTieredMergePolicy extends TieredMergePolicy { | ||
|
||
@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("dwptGroupNumber"); | ||
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 = | ||
super.findMerges(mergeTrigger, infos, mergeContext); | ||
if (tieredMergePolicySpec != null) { | ||
if (spec == null) { | ||
spec = new MergeSpecification(); | ||
} | ||
|
||
spec.merges.addAll(tieredMergePolicySpec.merges); | ||
} | ||
} | ||
} | ||
|
||
return spec; | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
lucene/core/src/java/org/apache/lucene/index/DWPTGroupingCriteriaDefinition.java
This file contains 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,85 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.lucene.index; | ||
|
||
import java.util.function.Function; | ||
|
||
/** | ||
* Structure of criteria on the basis of which group af a segment is selected. | ||
* | ||
*/ | ||
public class DWPTGroupingCriteriaDefinition { | ||
/** Grouping function which determines the DWPT group using which documents will be indexed. */ | ||
private final Function<Iterable<? extends Iterable<? extends IndexableField>>, Integer> | ||
dwptGroupingCriteriaFunction; | ||
|
||
/** | ||
* Maximum limit on DWPT group size. Any document evaluated in a group number greater this limit | ||
* is indexed using default DWPT group | ||
*/ | ||
private final int maxDWPTGroupSize; | ||
|
||
/** | ||
* Group number of default DWPT. This group is returned for documents whose grouping function outcome is greater than | ||
* max group limit. | ||
*/ | ||
public static final int DEFAULT_DWPT_GROUP_NUMBER = -1; | ||
|
||
/** | ||
* Grouping criteria function to select the DWPT pool group of a document. | ||
*/ | ||
public static final DWPTGroupingCriteriaDefinition DEFAULT_DWPT_GROUPING_CRITERIA_DEFINITION = | ||
new DWPTGroupingCriteriaDefinition( | ||
(document) -> { | ||
return DEFAULT_DWPT_GROUP_NUMBER; | ||
}, | ||
1); | ||
|
||
/** | ||
* Constructor to create a DWPTGroupingCriteriaDefinition on the basis of a criteria function and a max DWPT group | ||
* size. | ||
* | ||
* @param dwptGroupingCriteriaFunction the grouping criteria function. | ||
* @param maxDWPTGroupSize maximum number of groups allowed by grouping criteria function. | ||
*/ | ||
public DWPTGroupingCriteriaDefinition( | ||
final Function<Iterable<? extends Iterable<? extends IndexableField>>, Integer> | ||
dwptGroupingCriteriaFunction, | ||
final int maxDWPTGroupSize) { | ||
this.dwptGroupingCriteriaFunction = dwptGroupingCriteriaFunction; | ||
this.maxDWPTGroupSize = maxDWPTGroupSize; | ||
} | ||
|
||
/** | ||
* Returns the grouping criteria function. | ||
* | ||
* @return the grouping criteria function. | ||
*/ | ||
public Function<Iterable<? extends Iterable<? extends IndexableField>>, Integer> | ||
getDwptGroupingCriteriaFunction() { | ||
return dwptGroupingCriteriaFunction; | ||
} | ||
|
||
/** | ||
* Returns the max number of groups allowed for this grouping criteria function. | ||
* | ||
* @return the max number of groups allowed for this grouping criteria function. | ||
*/ | ||
public int getMaxDWPTGroupSize() { | ||
return maxDWPTGroupSize; | ||
} | ||
} |
This file contains 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 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 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
Oops, something went wrong.