diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index f2e94d05414..6521b54d508 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -92,8 +92,9 @@ New Features * SOLR-3251: Dynamically add fields to schema. (Steve Rowe, Robert Muir, yonik) -* SOLR-4761: Add option to plugin a merged segment warmer into solrconfig.xml - (Mark Miller, Mike McCandless, Robert Muir) +* SOLR-4761, SOLR-4976: Add option to plugin a merged segment warmer into solrconfig.xml. + Info about segments warmed in the background is available via infostream. + (Mark Miller, Ryan Ernst, Mike McCandless, Robert Muir) * SOLR-3240: Add "spellcheck.collateMaxCollectDocs" option so that when testing potential Collations against the index, SpellCheckComponent will only collect diff --git a/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java b/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java index 3cf63ffe1fe..0a5f0555b97 100644 --- a/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java +++ b/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java @@ -17,9 +17,11 @@ package org.apache.solr.update; +import org.apache.commons.io.FileUtils; import org.apache.lucene.index.*; import org.apache.lucene.index.IndexWriter.IndexReaderWarmer; import org.apache.lucene.util.InfoStream; +import org.apache.lucene.util.PrintStreamInfoStream; import org.apache.lucene.util.Version; import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; @@ -31,6 +33,10 @@ import org.apache.solr.util.SolrPluginUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintStream; import java.util.List; /** @@ -67,7 +73,7 @@ public class SolrIndexConfig { public final PluginInfo mergedSegmentWarmerInfo; - public String infoStreamFile = null; + public InfoStream infoStream = InfoStream.NO_OUTPUT; // Available lock types public final static String LOCK_TYPE_SIMPLE = "simple"; @@ -143,13 +149,23 @@ public class SolrIndexConfig { mergePolicyInfo = getPluginInfo(prefix + "/mergePolicy", solrConfig, def.mergePolicyInfo); termIndexInterval = solrConfig.getInt(prefix + "/termIndexInterval", def.termIndexInterval); - + boolean infoStreamEnabled = solrConfig.getBool(prefix + "/infoStream", false); if(infoStreamEnabled) { - infoStreamFile= solrConfig.get(prefix + "/infoStream/@file", null); - log.info("IndexWriter infoStream debug log is enabled: " + infoStreamFile); + String infoStreamFile = solrConfig.get(prefix + "/infoStream/@file", null); + if (infoStreamFile != null) { + log.info("IndexWriter infoStream debug log is enabled: " + infoStreamFile); + File f = new File(infoStreamFile); + File parent = f.getParentFile(); + if (parent != null) parent.mkdirs(); + try { + FileOutputStream fos = new FileOutputStream(f, true); + infoStream = new PrintStreamInfoStream(new PrintStream(fos, true, "UTF-8")); + } catch (Exception e) { + log.error("Could not create info stream for file " + infoStreamFile, e); + } + } } - mergedSegmentWarmerInfo = getPluginInfo(prefix + "/mergedSegmentWarmer", solrConfig, def.mergedSegmentWarmerInfo); if (mergedSegmentWarmerInfo != null && solrConfig.reopenReaders == false) { throw new IllegalArgumentException("Supplying a mergedSegmentWarmer will do nothing since reopenReaders is false"); @@ -197,6 +213,7 @@ public class SolrIndexConfig { iwc.setSimilarity(schema.getSimilarity()); iwc.setMergePolicy(buildMergePolicy(schema)); iwc.setMergeScheduler(buildMergeScheduler(schema)); + iwc.setInfoStream(infoStream); // do this after buildMergePolicy since the backcompat logic // there may modify the effective useCompoundFile @@ -212,7 +229,7 @@ public class SolrIndexConfig { IndexReaderWarmer.class, null, new Class[] { InfoStream.class }, - new Object[] { InfoStream.NO_OUTPUT }); + new Object[] { iwc.getInfoStream() }); iwc.setMergedSegmentWarmer(warmer); } diff --git a/solr/core/src/java/org/apache/solr/update/SolrIndexWriter.java b/solr/core/src/java/org/apache/solr/update/SolrIndexWriter.java index 464bdec0474..d68450a278b 100644 --- a/solr/core/src/java/org/apache/solr/update/SolrIndexWriter.java +++ b/solr/core/src/java/org/apache/solr/update/SolrIndexWriter.java @@ -77,7 +77,7 @@ public class SolrIndexWriter extends IndexWriter { super(directory, config.toIndexWriterConfig(schema). setOpenMode(create ? IndexWriterConfig.OpenMode.CREATE : IndexWriterConfig.OpenMode.APPEND). - setIndexDeletionPolicy(delPolicy).setCodec(codec).setInfoStream(toInfoStream(config)) + setIndexDeletionPolicy(delPolicy).setCodec(codec) ); log.debug("Opened Writer " + name); this.name = name; @@ -88,20 +88,6 @@ public class SolrIndexWriter extends IndexWriter { this.directoryFactory = factory; } - private static InfoStream toInfoStream(SolrIndexConfig config) throws IOException { - String infoStreamFile = config.infoStreamFile; - if (infoStreamFile != null) { - File f = new File(infoStreamFile); - File parent = f.getParentFile(); - if (parent != null) parent.mkdirs(); - FileOutputStream fos = new FileOutputStream(f, true); - return new PrintStreamInfoStream(new PrintStream(fos, true, "UTF-8")); - } else { - return InfoStream.NO_OUTPUT; - } - } - - /** * use DocumentBuilder now... * private final void addField(Document doc, String name, String val) { @@ -161,14 +147,9 @@ public class SolrIndexWriter extends IndexWriter { break; } } finally { - if (infoStream != null) { - infoStream.close(); - } - + infoStream.close(); isClosed = true; - directoryFactory.release(directory); - numCloses.incrementAndGet(); } } diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig-indexconfig.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig-indexconfig.xml index 3ee859af3dd..a26b78edbc5 100644 --- a/solr/core/src/test-files/solr/collection1/conf/solrconfig-indexconfig.xml +++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig-indexconfig.xml @@ -24,5 +24,6 @@ ${useCompoundFile:false} 123 + true diff --git a/solr/core/src/test/org/apache/solr/core/TestSolrIndexConfig.java b/solr/core/src/test/org/apache/solr/core/TestSolrIndexConfig.java index 9fa3af18f32..d6b00054641 100644 --- a/solr/core/src/test/org/apache/solr/core/TestSolrIndexConfig.java +++ b/solr/core/src/test/org/apache/solr/core/TestSolrIndexConfig.java @@ -18,6 +18,7 @@ package org.apache.solr.core; */ import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.util.PrintStreamInfoStream; import org.apache.solr.SolrTestCaseJ4; import org.junit.BeforeClass; @@ -32,5 +33,6 @@ public class TestSolrIndexConfig extends SolrTestCaseJ4 { IndexWriterConfig iwc = solrConfig.indexConfig.toIndexWriterConfig(h.getCore().getLatestSchema()); assertEquals(123, iwc.getMaxThreadStates()); + assertTrue(iwc.getInfoStream() instanceof PrintStreamInfoStream); } }