Skip to content
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

SOLR-17636: make Lucene's BPReorderingMergePolicy configurable in Solr #2641

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.solr.index;

import java.util.Set;
import org.apache.lucene.index.MergePolicy;
import org.apache.lucene.misc.index.BPIndexReorderer;
import org.apache.lucene.misc.index.BPReorderingMergePolicy;
import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.util.SolrPluginUtils;

/** A {@link MergePolicyFactory} for {@code BPReorderingMergePolicy} objects. */
public class BPReorderingMergePolicyFactory extends WrapperMergePolicyFactory {

private static final String BPR_PREFIX = "bpr.prefix";

private final BPIndexReorderer reorderer;

public BPReorderingMergePolicyFactory(
SolrResourceLoader resourceLoader, MergePolicyFactoryArgs args, IndexSchema schema) {
super(resourceLoader, args, schema);
reorderer = new BPIndexReorderer();
MergePolicyFactoryArgs bprArgs = filterWrappedMergePolicyFactoryArgs(BPR_PREFIX);
if (bprArgs != null) {
final String fields = (String) bprArgs.remove("fields");
if (fields != null) {
reorderer.setFields(Set.of(fields.split(",")));
}
SolrPluginUtils.invokeSetters(reorderer, bprArgs.args.entrySet());
}
}

@Override
protected MergePolicy getMergePolicyInstance(MergePolicy wrappedMP) {
final MergePolicy mp = new BPReorderingMergePolicy(wrappedMP, reorderer);
return mp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public class MergePolicyFactoryArgs {

private final Map<String, Object> args;
final Map<String, Object> args;

public MergePolicyFactoryArgs() {
this.args = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public abstract class WrapperMergePolicyFactory extends MergePolicyFactory {
protected WrapperMergePolicyFactory(
SolrResourceLoader resourceLoader, MergePolicyFactoryArgs args, IndexSchema schema) {
super(resourceLoader, args, schema);
wrappedMergePolicyArgs = filterWrappedMergePolicyFactoryArgs();
wrappedMergePolicyArgs = filterWrappedMergePolicyFactoryArgs(WRAPPED_PREFIX);
if (wrappedMergePolicyArgs == null) {
wrappedMergePolicyClassName = null;
} else {
Expand Down Expand Up @@ -108,8 +108,8 @@ public final MergePolicy getMergePolicy() {
* Returns a {@link MergePolicyFactoryArgs} for the wrapped {@link MergePolicyFactory}. This
* method also removes all args from this instance's args.
*/
private MergePolicyFactoryArgs filterWrappedMergePolicyFactoryArgs() {
final String wrappedPolicyPrefix = (String) args.remove(WRAPPED_PREFIX);
protected MergePolicyFactoryArgs filterWrappedMergePolicyFactoryArgs(String wrappedPrefix) {
final String wrappedPolicyPrefix = (String) args.remove(wrappedPrefix);
if (wrappedPolicyPrefix == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" ?>

<!--
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.
-->

<config>
<luceneMatchVersion>${tests.luceneMatchVersion:LATEST}</luceneMatchVersion>
<directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.MockDirectoryFactory}"/>
<schemaFactory class="ClassicIndexSchemaFactory"/>

<indexConfig>
<mergePolicyFactory class="org.apache.solr.index.BPReorderingMergePolicyFactory">
<str name="wrapped.prefix">in</str>
<str name="in.class">org.apache.solr.util.RandomForceMergePolicyFactory</str>
<str name="bpr.prefix">bpr</str>
<int name="bpr.minDocFreq">1</int>
<float name="bpr.maxDocFreq">1</float>
<int name="bpr.minPartitionSize">32</int>
<int name="bpr.maxIters">20</int>
<double name="bpr.RAMBudgetMB">42.42</double>
<str name="bpr.fields">foo,bar</str>
<int name="minNaturalMergeNumDocs">1</int>
<float name="minNaturalMergeRatioFromBiggestSegment">0.0</float>
</mergePolicyFactory>
<lockType>${solr.tests.lockType:single}</lockType>
</indexConfig>

<requestHandler name="/select" class="solr.SearchHandler" />

<updateHandler class="solr.DirectUpdateHandler2">
<updateLog>
<str name="dir">${solr.ulog.dir:}</str>
</updateLog>

<autoCommit>
<maxTime>${solr.autoCommit.maxTime:-1}</maxTime>
<openSearcher>false</openSearcher>
</autoCommit>

<autoSoftCommit>
<maxTime>${solr.autoSoftCommit.maxTime:-1}</maxTime>
</autoSoftCommit>
</updateHandler>
<initParams path="/select">
<lst name="defaults">
<str name="df">text</str>
</lst>
</initParams>

</config>
20 changes: 20 additions & 0 deletions solr/core/src/test/org/apache/solr/update/SolrIndexConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.lucene.index.MergePolicy;
import org.apache.lucene.index.SimpleMergedSegmentWarmer;
import org.apache.lucene.index.TieredMergePolicy;
import org.apache.lucene.misc.index.BPReorderingMergePolicy;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.solr.SolrTestCaseJ4;
Expand Down Expand Up @@ -55,6 +56,8 @@ public class SolrIndexConfigTest extends SolrTestCaseJ4 {
"solrconfig-concurrentmergescheduler.xml";
private static final String solrConfigFileNameSortingMergePolicyFactory =
"solrconfig-sortingmergepolicyfactory.xml";
private static final String solrConfigFileNameBPReorderingMergePolicyFactory =
"solrconfig-bpreorderingmergepolicyfactory.xml";
private static final String schemaFileName = "schema.xml";

private static boolean compoundMergePolicySort = false;
Expand Down Expand Up @@ -169,6 +172,23 @@ public void testSortingMPSolrIndexConfigCreation() throws Exception {
assertEquals("SortingMergePolicy.getSort", expected, actual);
}

public void testBPReorderingMPSolrIndexConfigCreation() throws Exception {
SolrConfig solrConfig =
new SolrConfig(instanceDir, solrConfigFileNameBPReorderingMergePolicyFactory);
SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null);
assertNotNull(solrIndexConfig);
IndexSchema indexSchema = IndexSchemaFactory.buildIndexSchema(schemaFileName, solrConfig);

h.getCore().setLatestSchema(indexSchema);
IndexWriterConfig iwc = solrIndexConfig.toIndexWriterConfig(h.getCore());

final MergePolicy mergePolicy = iwc.getMergePolicy();
assertNotNull("null mergePolicy", mergePolicy);
assertTrue(
"mergePolicy (" + mergePolicy + ") is not a BPReorderingMergePolicy",
mergePolicy instanceof BPReorderingMergePolicy);
}

public void testMergedSegmentWarmerIndexConfigCreation() throws Exception {
SolrConfig solrConfig =
new SolrConfig(instanceDir, solrConfigFileNameWarmerRandomMergePolicyFactory);
Expand Down
Loading