SOLR-1145: Add capability to specify an infoStream log file for the underlying Lucene IndexWriter in solrconfig.xml

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@791578 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2009-07-06 19:31:37 +00:00
parent 33ba738883
commit 7c5825cf25
4 changed files with 62 additions and 1 deletions

View File

@ -243,6 +243,10 @@ New Features
62. SOLR-1216 : disambiguate the replication command names. 'snappull' becomes 'fetchindex' 'abortsnappull' becomes 'abortfetch' (noble) 62. SOLR-1216 : disambiguate the replication command names. 'snappull' becomes 'fetchindex' 'abortsnappull' becomes 'abortfetch' (noble)
63. SOLR-1145: Add capability to specify an infoStream log file for the underlying Lucene IndexWriter in solrconfig.xml.
This is an advanced debug log file that can be used to aid developers in fixing IndexWriter bugs. See the commented
out example in the example solrconfig.xml under the indexDefaults section.
(Chris Harris, Mark Miller)
Optimizations Optimizations
---------------------- ----------------------
1. SOLR-374: Use IndexReader.reopen to save resources by re-using parts of the 1. SOLR-374: Use IndexReader.reopen to save resources by re-using parts of the

View File

@ -81,6 +81,12 @@
--> -->
<!--<mergeScheduler>org.apache.lucene.index.ConcurrentMergeScheduler</mergeScheduler>--> <!--<mergeScheduler>org.apache.lucene.index.ConcurrentMergeScheduler</mergeScheduler>-->
<!--
To aid in advanced debugging, you may turn on IndexWriter debug logging. Uncommenting this and setting to true
will set the file that the underlying Lucene IndexWriter will write its debug infostream to.
-->
<!-- <infoStream file="/path/file">false</infoStream> -->
<!-- <!--
This option specifies which Lucene LockFactory implementation to use. This option specifies which Lucene LockFactory implementation to use.

View File

@ -20,6 +20,8 @@ package org.apache.solr.update;
import org.apache.solr.core.SolrConfig; import org.apache.solr.core.SolrConfig;
import org.apache.lucene.index.LogByteSizeMergePolicy; import org.apache.lucene.index.LogByteSizeMergePolicy;
import org.apache.lucene.index.ConcurrentMergeScheduler; import org.apache.lucene.index.ConcurrentMergeScheduler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// //
// For performance reasons, we don't want to re-read // For performance reasons, we don't want to re-read
@ -30,6 +32,8 @@ import org.apache.lucene.index.ConcurrentMergeScheduler;
* @version $Id$ * @version $Id$
*/ */
public class SolrIndexConfig { public class SolrIndexConfig {
public static final Logger log = LoggerFactory.getLogger(SolrIndexConfig.class);
public static final String defaultsName ="indexDefaults"; public static final String defaultsName ="indexDefaults";
public static final String DEFAULT_MERGE_POLICY_CLASSNAME = LogByteSizeMergePolicy.class.getName(); public static final String DEFAULT_MERGE_POLICY_CLASSNAME = LogByteSizeMergePolicy.class.getName();
public static final String DEFAULT_MERGE_SCHEDULER_CLASSNAME = ConcurrentMergeScheduler.class.getName(); public static final String DEFAULT_MERGE_SCHEDULER_CLASSNAME = ConcurrentMergeScheduler.class.getName();
@ -66,6 +70,8 @@ public class SolrIndexConfig {
public final String mergeSchedulerClassname; public final String mergeSchedulerClassname;
public final boolean luceneAutoCommit; public final boolean luceneAutoCommit;
public String infoStreamFile = null;
public SolrIndexConfig(SolrConfig solrConfig, String prefix, SolrIndexConfig def) { public SolrIndexConfig(SolrConfig solrConfig, String prefix, SolrIndexConfig def) {
if (prefix == null) if (prefix == null)
prefix = defaultsName; prefix = defaultsName;
@ -84,5 +90,12 @@ public class SolrIndexConfig {
mergePolicyClassName = solrConfig.get(prefix + "/mergePolicy", def.mergePolicyClassName); mergePolicyClassName = solrConfig.get(prefix + "/mergePolicy", def.mergePolicyClassName);
mergeSchedulerClassname = solrConfig.get(prefix + "/mergeScheduler", def.mergeSchedulerClassname); mergeSchedulerClassname = solrConfig.get(prefix + "/mergeScheduler", def.mergeSchedulerClassname);
luceneAutoCommit = solrConfig.getBool(prefix + "/luceneAutoCommit", def.luceneAutoCommit); luceneAutoCommit = solrConfig.getBool(prefix + "/luceneAutoCommit", def.luceneAutoCommit);
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);
}
} }
} }

View File

@ -27,7 +27,14 @@ import org.apache.solr.schema.IndexSchema;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.text.DateFormat;
import java.util.Date;
/** /**
* An IndexWriter that is configured via Solr config mechanisms. * An IndexWriter that is configured via Solr config mechanisms.
@ -43,6 +50,8 @@ public class SolrIndexWriter extends IndexWriter {
String name; String name;
IndexSchema schema; IndexSchema schema;
private PrintStream infoStream;
private void init(String name, IndexSchema schema, SolrIndexConfig config) throws IOException { private void init(String name, IndexSchema schema, SolrIndexConfig config) throws IOException {
log.debug("Opened Writer " + name); log.debug("Opened Writer " + name);
this.name = name; this.name = name;
@ -73,6 +82,14 @@ public class SolrIndexWriter extends IndexWriter {
setMergeScheduler(scheduler); setMergeScheduler(scheduler);
} }
String infoStreamFile = config.infoStreamFile;
if (infoStreamFile != null) {
File f = new File(infoStreamFile);
f.getParentFile().mkdirs();
FileOutputStream fos = new FileOutputStream(f, true);
infoStream = new TimeLoggingPrintStream(fos, true);
setInfoStream(infoStream);
}
//if (config.commitLockTimeout != -1) setWriteLockTimeout(config.commitLockTimeout); //if (config.commitLockTimeout != -1) setWriteLockTimeout(config.commitLockTimeout);
} }
@ -196,6 +213,9 @@ public class SolrIndexWriter extends IndexWriter {
public void close() throws IOException { public void close() throws IOException {
log.debug("Closing Writer " + name); log.debug("Closing Writer " + name);
super.close(); super.close();
if(infoStream != null) {
infoStream.close();
}
} }
@Override @Override
@ -208,4 +228,22 @@ public class SolrIndexWriter extends IndexWriter {
} }
// Helper class for adding timestamps to infoStream logging
class TimeLoggingPrintStream extends PrintStream {
private DateFormat dateFormat;
public TimeLoggingPrintStream(OutputStream underlyingOutputStream,
boolean autoFlush) {
super(underlyingOutputStream, autoFlush);
this.dateFormat = DateFormat.getDateTimeInstance();
}
// We might ideally want to override print(String) as well, but
// looking through the code that writes to infoStream, it appears
// that all the classes except CheckIndex just use println.
public void println(String x) {
print(dateFormat.format(new Date()) + " ");
super.println(x);
}
}
} }