SOLR-4976: infostream doesn't work with merged segment warmer

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1497968 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2013-06-29 01:27:52 +00:00
parent 25b562d059
commit 92c42511c7
5 changed files with 31 additions and 29 deletions

View File

@ -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

View File

@ -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";
@ -146,10 +152,20 @@ public class SolrIndexConfig {
boolean infoStreamEnabled = solrConfig.getBool(prefix + "/infoStream", false);
if(infoStreamEnabled) {
infoStreamFile= solrConfig.get(prefix + "/infoStream/@file", null);
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);
}

View File

@ -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();
}
isClosed = true;
directoryFactory.release(directory);
numCloses.incrementAndGet();
}
}

View File

@ -24,5 +24,6 @@
<indexConfig>
<useCompoundFile>${useCompoundFile:false}</useCompoundFile>
<maxIndexingThreads>123</maxIndexingThreads>
<infoStream file="infostream.txt">true</infoStream>
</indexConfig>
</config>

View File

@ -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);
}
}