Apache Lucene open-source search software
SOLR-1145: Add capability to specify an infoStream log file for the underlying Lucene IndexWriter in solrconfig.xml
Mark Robert Miller7c5825cf257f
diff --git a/CHANGES.txt b/CHANGES.txtindex 851ca4afbf5..8034be98ac6 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -242,7 +242,11 @@ New Featuresand it is renamed to locateSolrHome (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----------------------1. SOLR-374: Use IndexReader.reopen to save resources by re-using parts of thediff --git a/example/solr/conf/solrconfig.xml b/example/solr/conf/solrconfig.xmlindex c007d7c426c..572d1a65ade 100755--- a/example/solr/conf/solrconfig.xml+++ b/example/solr/conf/solrconfig.xml@@ -81,6 +81,12 @@--><!--<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.diff --git a/src/java/org/apache/solr/update/SolrIndexConfig.java b/src/java/org/apache/solr/update/SolrIndexConfig.javaindex 7ab603382c3..2325f5fb050 100644--- a/src/java/org/apache/solr/update/SolrIndexConfig.java+++ b/src/java/org/apache/solr/update/SolrIndexConfig.java@@ -20,6 +20,8 @@ package org.apache.solr.update;import org.apache.solr.core.SolrConfig;import org.apache.lucene.index.LogByteSizeMergePolicy;import org.apache.lucene.index.ConcurrentMergeScheduler;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;//// For performance reasons, we don't want to re-read@@ -30,6 +32,8 @@ import org.apache.lucene.index.ConcurrentMergeScheduler;* @version $Id$*/public class SolrIndexConfig {+ public static final Logger log = LoggerFactory.getLogger(SolrIndexConfig.class);+public static final String defaultsName ="indexDefaults";public static final String DEFAULT_MERGE_POLICY_CLASSNAME = LogByteSizeMergePolicy.class.getName();public static final String DEFAULT_MERGE_SCHEDULER_CLASSNAME = ConcurrentMergeScheduler.class.getName();@@ -65,6 +69,8 @@ public class SolrIndexConfig {public final String mergePolicyClassName;public final String mergeSchedulerClassname;public final boolean luceneAutoCommit;++ public String infoStreamFile = null;public SolrIndexConfig(SolrConfig solrConfig, String prefix, SolrIndexConfig def) {if (prefix == null)@@ -84,5 +90,12 @@ public class SolrIndexConfig {mergePolicyClassName = solrConfig.get(prefix + "/mergePolicy", def.mergePolicyClassName);mergeSchedulerClassname = solrConfig.get(prefix + "/mergeScheduler", def.mergeSchedulerClassname);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);+ }+}}diff --git a/src/java/org/apache/solr/update/SolrIndexWriter.java b/src/java/org/apache/solr/update/SolrIndexWriter.javaindex 1e8287f1324..edea78762f0 100644--- a/src/java/org/apache/solr/update/SolrIndexWriter.java+++ b/src/java/org/apache/solr/update/SolrIndexWriter.java@@ -27,7 +27,14 @@ import org.apache.solr.schema.IndexSchema;import org.slf4j.Logger;import org.slf4j.LoggerFactory;++import java.io.File;+import java.io.FileOutputStream;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.@@ -43,6 +50,8 @@ public class SolrIndexWriter extends IndexWriter {String name;IndexSchema schema;+ private PrintStream infoStream;+private void init(String name, IndexSchema schema, SolrIndexConfig config) throws IOException {log.debug("Opened Writer " + name);this.name = name;@@ -73,6 +82,14 @@ public class SolrIndexWriter extends IndexWriter {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);}@@ -196,6 +213,9 @@ public class SolrIndexWriter extends IndexWriter {public void close() throws IOException {log.debug("Closing Writer " + name);super.close();+ if(infoStream != null) {+ infoStream.close();+ }}@Override@@ -207,5 +227,23 @@ 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);+ }+ }}