mirror of https://github.com/apache/lucene.git
[SOLR-2983] - fix custom merge policy instantiation issue in SolrIndexConfig
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1304098 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c9c1166d07
commit
e3056ee81d
|
@ -471,6 +471,10 @@ Documentation
|
|||
|
||||
Upgrading from Solr 3.5
|
||||
----------------------
|
||||
* SOLR-2983: As a consequence of moving the code which sets a MergePolicy from SolrIndexWriter to SolrIndexConfig,
|
||||
(custom) MergePolicies should now have an empty constructor; thus an IndexWriter should not be passed as constructor
|
||||
parameter but instead set using the setIndexWriter() method.
|
||||
|
||||
* As doGet() methods in SimplePostTool was changed to static, the client applications of this
|
||||
class need to be recompiled.
|
||||
|
||||
|
|
|
@ -160,14 +160,9 @@ public class SolrIndexConfig {
|
|||
}
|
||||
|
||||
private MergePolicy buildMergePolicy(IndexSchema schema) {
|
||||
MergePolicy policy;
|
||||
String mpClassName = mergePolicyInfo == null ? defaultMergePolicyClassName : mergePolicyInfo.className;
|
||||
|
||||
try {
|
||||
policy = (MergePolicy) schema.getResourceLoader().newInstance(mpClassName, null, new Class[]{IndexWriter.class}, new Object[]{this});
|
||||
} catch (Exception e) {
|
||||
policy = (MergePolicy) schema.getResourceLoader().newInstance(mpClassName);
|
||||
}
|
||||
MergePolicy policy = (MergePolicy) schema.getResourceLoader().newInstance(mpClassName);
|
||||
|
||||
if (policy instanceof LogMergePolicy) {
|
||||
LogMergePolicy logMergePolicy = (LogMergePolicy) policy;
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
<?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>
|
||||
|
||||
<directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.RAMDirectoryFactory}"/>
|
||||
|
||||
<luceneMatchVersion>${tests.luceneMatchVersion:LUCENE_CURRENT}</luceneMatchVersion>
|
||||
|
||||
<indexDefaults>
|
||||
|
||||
<useCompoundFile>false</useCompoundFile>
|
||||
<mergeFactor>10</mergeFactor>
|
||||
<ramBufferSizeMB>32</ramBufferSizeMB>
|
||||
<maxMergeDocs>2147483647</maxMergeDocs>
|
||||
<maxFieldLength>10000</maxFieldLength>
|
||||
<writeLockTimeout>1000</writeLockTimeout>
|
||||
<mergePolicy class="org.apache.solr.update.DummyMergePolicy"/>
|
||||
|
||||
</indexDefaults>
|
||||
|
||||
<mainIndex>
|
||||
<useCompoundFile>false</useCompoundFile>
|
||||
<mergeFactor>8</mergeFactor>
|
||||
<maxBufferedDocs>10</maxBufferedDocs>
|
||||
<maxMergeDocs>2147483647</maxMergeDocs>
|
||||
<maxFieldLength>10000</maxFieldLength>
|
||||
<mergePolicy class="org.apache.solr.update.DummyMergePolicy"/>
|
||||
<unlockOnStartup>true</unlockOnStartup>
|
||||
</mainIndex>
|
||||
|
||||
<updateHandler class="solr.DirectUpdateHandler2"/>
|
||||
<requestHandler name="standard" class="solr.StandardRequestHandler"></requestHandler>
|
||||
|
||||
</config>
|
|
@ -0,0 +1,35 @@
|
|||
package org.apache.solr.update;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.LogByteSizeMergePolicy;
|
||||
|
||||
/**
|
||||
* Dummy implementation of {@link org.apache.lucene.index.MergePolicy} which doesn't have an empty constructor and
|
||||
* is expected to fail if used within Solr
|
||||
*/
|
||||
class DummyMergePolicy extends LogByteSizeMergePolicy {
|
||||
|
||||
private DummyMergePolicy() {}
|
||||
|
||||
public DummyMergePolicy(IndexWriter writer) {
|
||||
super();
|
||||
setIndexWriter(writer);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package org.apache.solr.update;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.core.SolrConfig;
|
||||
import org.apache.solr.schema.IndexSchema;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Testcase for {@link SolrIndexConfig}
|
||||
*/
|
||||
public class SolrIndexConfigTest extends SolrTestCaseJ4 {
|
||||
|
||||
@Test
|
||||
public void testFailingSolrIndexConfigCreation() {
|
||||
try {
|
||||
SolrConfig solrConfig = new SolrConfig("bad-mp-solrconfig.xml");
|
||||
SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null);
|
||||
IndexSchema indexSchema = new IndexSchema(solrConfig, "schema.xml", null);
|
||||
solrIndexConfig.toIndexWriterConfig(indexSchema);
|
||||
fail("a mergePolicy should have an empty constructor in order to be instantiated in Solr thus this should fail ");
|
||||
} catch (Exception e) {
|
||||
// it failed as expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTieredMPSolrIndexConfigCreation() throws Exception {
|
||||
SolrConfig solrConfig = new SolrConfig("solrconfig-mergepolicy.xml");
|
||||
SolrIndexConfig solrIndexConfig = new SolrIndexConfig(solrConfig, null, null);
|
||||
assertNotNull(solrIndexConfig);
|
||||
assertEquals("org.apache.lucene.index.TieredMergePolicy", solrIndexConfig.defaultMergePolicyClassName);
|
||||
IndexSchema indexSchema = new IndexSchema(solrConfig, "schema.xml", null);
|
||||
solrIndexConfig.toIndexWriterConfig(indexSchema);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue