Author: markrmiller
Date: Mon Jul 6 19:31:37 2009
New Revision: 791578
URL: http://svn.apache.org/viewvc?rev=791578&view=rev
Log:
SOLR-1145: Add capability to specify an infoStream log file for the underlying
Lucene IndexWriter in solrconfig.xml
Modified:
lucene/solr/trunk/CHANGES.txt
lucene/solr/trunk/example/solr/conf/solrconfig.xml
lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexConfig.java
lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexWriter.java
Modified: lucene/solr/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=791578&r1=791577&r2=791578&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Mon Jul 6 19:31:37 2009
@@ -242,7 +242,11 @@
and 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 the
Modified: lucene/solr/trunk/example/solr/conf/solrconfig.xml
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/example/solr/conf/solrconfig.xml?rev=791578&r1=791577&r2=791578&view=diff
==============================================================================
--- lucene/solr/trunk/example/solr/conf/solrconfig.xml (original)
+++ lucene/solr/trunk/example/solr/conf/solrconfig.xml Mon Jul 6 19:31:37 2009
@@ -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.
Modified: lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexConfig.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexConfig.java?rev=791578&r1=791577&r2=791578&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexConfig.java
(original)
+++ lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexConfig.java Mon
Jul 6 19:31:37 2009
@@ -20,6 +20,8 @@
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 @@
* @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 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 @@
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);
+ }
+
}
}
Modified: lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexWriter.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexWriter.java?rev=791578&r1=791577&r2=791578&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexWriter.java
(original)
+++ lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexWriter.java Mon
Jul 6 19:31:37 2009
@@ -27,7 +27,14 @@
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 @@
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 @@
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 void close() throws IOException {
log.debug("Closing Writer " + name);
super.close();
+ if(infoStream != null) {
+ infoStream.close();
+ }
}
@Override
@@ -207,5 +227,23 @@
}
}
+
+ // 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);
+ }
+ }
}