Skip to content

Apache Lucene open-source search software

SOLR-2615: log individual updates at DEBUG level, fix NPE when no unique key

Yonik Seeley30b3cc881d3a
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 653bcfa58e6..61f80061b29 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -317,6 +317,11 @@ New Features
handler, as long as you also provide a XSL to transform them to a valid
Solr input document. (Upayavira, Uwe Schindler)
+* SOLR-2615: Log individual updates (adds and deletes) at the FINE level
+ before adding to the index. Fix a null pointer exception in logging
+ when there was no unique key. (David Smiley via yonik)
+
+
Optimizations
----------------------
diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java
index 10d992adf51..de6837122c0 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrCore.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java
@@ -659,8 +659,8 @@ public final class SolrCore implements SolrInfoMBean {
if (def == null) {
// construct the default chain
UpdateRequestProcessorFactory[] factories = new UpdateRequestProcessorFactory[]{
- new RunUpdateProcessorFactory(),
- new LogUpdateProcessorFactory()
+ new LogUpdateProcessorFactory(),
+ new RunUpdateProcessorFactory()
};
def = new UpdateRequestProcessorChain(factories, this);
}
diff --git a/solr/core/src/java/org/apache/solr/update/AddUpdateCommand.java b/solr/core/src/java/org/apache/solr/update/AddUpdateCommand.java
index a8599b47f5f..cf6ce93083e 100644
--- a/solr/core/src/java/org/apache/solr/update/AddUpdateCommand.java
+++ b/solr/core/src/java/org/apache/solr/update/AddUpdateCommand.java
@@ -90,15 +90,15 @@ public class AddUpdateCommand extends UpdateCommand {
public String getPrintableId(IndexSchema schema) {
SchemaField sf = schema.getUniqueKeyField();
- if (indexedId != null) {
- return schema.getUniqueKeyField().getType().indexedToReadable(indexedId);
+ if (indexedId != null && sf != null) {
+ return sf.getType().indexedToReadable(indexedId);
}
if (doc != null) {
return schema.printableUniqueKey(doc);
}
- if (solrDoc != null) {
+ if (solrDoc != null && sf != null) {
SolrInputField field = solrDoc.getField(sf.getName());
if (field != null) {
return field.getFirstValue().toString();
diff --git a/solr/core/src/java/org/apache/solr/update/processor/LogUpdateProcessorFactory.java b/solr/core/src/java/org/apache/solr/update/processor/LogUpdateProcessorFactory.java
index 750e10ce7b0..16df29e66b2 100644
--- a/solr/core/src/java/org/apache/solr/update/processor/LogUpdateProcessorFactory.java
+++ b/solr/core/src/java/org/apache/solr/update/processor/LogUpdateProcessorFactory.java
@@ -31,12 +31,15 @@ import org.apache.solr.update.CommitUpdateCommand;
import org.apache.solr.update.DeleteUpdateCommand;
import org.apache.solr.update.MergeIndexesCommand;
import org.apache.solr.update.RollbackUpdateCommand;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* A logging processor. This keeps track of all commands that have passed through
- * the chain and prints them on finish();
+ * the chain and prints them on finish(). At the Debug (FINE) level, a message
+ * will be logged for each command prior to the next stage in the chain.
*
- * If the Log level is not INFO the processor will not be created or added to the chain
+ * If the Log level is not >= INFO the processor will not be created or added to the chain.
*
* @since solr 1.3
*/
@@ -54,11 +57,14 @@ public class LogUpdateProcessorFactory extends UpdateRequestProcessorFactory {
@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp, UpdateRequestProcessor next) {
- boolean doLog = LogUpdateProcessor.log.isInfoEnabled();
+ final Logger logger = LoggerFactory.getLogger(LogUpdateProcessor.class);
+ boolean doLog = logger.isInfoEnabled();
// LogUpdateProcessor.log.error("Will Log=" + doLog);
if( doLog ) {
// only create the log processor if we will use it
- return new LogUpdateProcessor(req, rsp, this, next);
+ final LogUpdateProcessor processor = new LogUpdateProcessor(req, rsp, this, next);
+ assert processor.log == logger;
+ return processor;
}
return null;
}
@@ -78,6 +84,8 @@ class LogUpdateProcessor extends UpdateRequestProcessor {
private final int maxNumToLog;
+ private final boolean logDebug = log.isDebugEnabled();//cache to avoid volatile-read
+
public LogUpdateProcessor(SolrQueryRequest req, SolrQueryResponse rsp, LogUpdateProcessorFactory factory, UpdateRequestProcessor next) {
super( next );
this.req = req;
@@ -91,8 +99,6 @@ class LogUpdateProcessor extends UpdateRequestProcessor {
@Override
public void processAdd(AddUpdateCommand cmd) throws IOException {
- if (next != null) next.processAdd(cmd);
-
// Add a list of added id's to the response
if (adds == null) {
adds = new ArrayList<String>();
@@ -102,14 +108,15 @@ class LogUpdateProcessor extends UpdateRequestProcessor {
if (adds.size() < maxNumToLog) {
adds.add(cmd.getPrintableId(req.getSchema()));
}
+ if (logDebug) { log.debug("add {}", cmd.getPrintableId(req.getSchema())); }
numAdds++;
+
+ if (next != null) next.processAdd(cmd);
}
@Override
public void processDelete( DeleteUpdateCommand cmd ) throws IOException {
- if (next != null) next.processDelete(cmd);
-
if (cmd.id != null) {
if (deletes == null) {
deletes = new ArrayList<String>();
@@ -118,26 +125,33 @@ class LogUpdateProcessor extends UpdateRequestProcessor {
if (deletes.size() < maxNumToLog) {
deletes.add(cmd.id);
}
+ if (logDebug) { log.debug("delete {}", cmd.id); }
} else {
if (toLog.size() < maxNumToLog) {
toLog.add("deleteByQuery", cmd.query);
}
+ if (logDebug) { log.debug("deleteByQuery {}", cmd.query); }
}
numDeletes++;
+
+ if (next != null) next.processDelete(cmd);
}
@Override
public void processMergeIndexes(MergeIndexesCommand cmd) throws IOException {
- if (next != null) next.processMergeIndexes(cmd);
-
toLog.add("mergeIndexes", cmd.toString());
+ if (logDebug) { log.debug("mergeIndexes {}",cmd.toString()); }
+
+ if (next != null) next.processMergeIndexes(cmd);
}
@Override
public void processCommit( CommitUpdateCommand cmd ) throws IOException {
+ final String msg = cmd.optimize ? "optimize" : "commit";
+ toLog.add(msg, "");
+ if (logDebug) { log.debug(msg); }
+
if (next != null) next.processCommit(cmd);
-
- toLog.add(cmd.optimize ? "optimize" : "commit", "");
}
/**
@@ -145,15 +159,18 @@ class LogUpdateProcessor extends UpdateRequestProcessor {
*/
@Override
public void processRollback( RollbackUpdateCommand cmd ) throws IOException {
- if (next != null) next.processRollback(cmd);
-
toLog.add("rollback", "");
+ if (logDebug) { log.debug("rollback"); }
+
+ if (next != null) next.processRollback(cmd);
}
@Override
public void finish() throws IOException {
if (next != null) next.finish();
+
+ // LOG A SUMMARY WHEN ALL DONE (INFO LEVEL)
// TODO: right now, update requests are logged twice...
// this will slow down things compared to Solr 1.2
diff --git a/solr/core/src/java/org/apache/solr/update/processor/UpdateRequestProcessor.java b/solr/core/src/java/org/apache/solr/update/processor/UpdateRequestProcessor.java
index 10e317d5023..99dff327ca4 100644
--- a/solr/core/src/java/org/apache/solr/update/processor/UpdateRequestProcessor.java
+++ b/solr/core/src/java/org/apache/solr/update/processor/UpdateRequestProcessor.java
@@ -41,7 +41,7 @@ import org.apache.solr.update.RollbackUpdateCommand;
* @since solr 1.3
*/
public abstract class UpdateRequestProcessor {
- protected static Logger log = LoggerFactory.getLogger(UpdateRequestProcessor.class);
+ protected final Logger log = LoggerFactory.getLogger(getClass());
protected final UpdateRequestProcessor next;