Permalink
Browse files

DNA-644 Added TRACE-level logging to several dna-search-lucene classe…

…s to help debug what content is being added to and removed from the Lucene indexes. I tried to make the message very easy to read, especially as there is one line per add, per delete, and per commit or rollback. Also added a fragment to the 'dna-jcr' project's log4j.properties file used in the test cases that will turn on this logging, though this is commented out by default.

git-svn-id: https://svn.jboss.org/repos/modeshape/trunk@1591 76366958-4244-0410-ad5e-bbfabb93f86b
  • Loading branch information...
1 parent 5edcf9d commit 8c74bd4c9bc3c088846eee82f58ab97c0b60224b @rhauch rhauch committed Jan 11, 2010
@@ -10,3 +10,6 @@ log4j.rootLogger=INFO, stdout
# Set up the default logging to be INFO level, then override specific units
log4j.logger.org.jboss.dna=INFO
+# This line turns on TRACING messages in the LuceneSearchIndex, which show which
+# operations are being performed on the index (including the data going into the index) ...
+#log4j.logger.org.jboss.dna.search.lucene=TRACE
@@ -42,6 +42,7 @@
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.BooleanClause.Occur;
import org.jboss.dna.common.collection.SimpleProblems;
+import org.jboss.dna.common.util.Logger;
import org.jboss.dna.graph.DnaLexicon;
import org.jboss.dna.graph.ExecutionContext;
import org.jboss.dna.graph.GraphI18n;
@@ -151,6 +152,7 @@ protected AbstractLuceneSearchEngine( String sourceName,
protected final TypeSystem typeSystem;
protected final PropertyFactory propertyFactory;
protected final Workspaces<WorkspaceType> workspaces;
+ protected final Logger logger = Logger.getLogger(getClass());
protected AbstractLuceneProcessor( String sourceName,
ExecutionContext context,
@@ -68,6 +68,7 @@
public class LuceneSearchProcessor extends AbstractLuceneProcessor<LuceneSearchWorkspace, LuceneSearchSession> {
protected static final Columns FULL_TEXT_RESULT_COLUMNS = new FullTextSearchResultColumns();
+ private final Logger logger = Logger.getLogger(getClass());
protected LuceneSearchProcessor( String sourceName,
ExecutionContext context,
@@ -165,13 +166,6 @@ public void process( CreateNodeRequest request ) {
Location location = request.getActualLocationOfNode();
assert location != null;
- Logger logger = Logger.getLogger(getClass());
- if (logger.isTraceEnabled()) {
- logger.trace("indexing {0} in workspace \"{1}\"",
- location.getString(getExecutionContext().getNamespaceRegistry()),
- request.inWorkspace());
- }
-
try {
session.setOrReplaceProperties(location, request.properties());
session.recordChange();
@@ -218,6 +212,9 @@ public void process( DeleteBranchRequest request ) {
assert !readOnly;
try {
// Create a query to find all the nodes at or below the specified path (this efficiently handles the root path) ...
+ if (logger.isTraceEnabled()) {
+ logger.trace("index for \"{0}\" workspace: DEL '{1}' branch", request.inWorkspace(), stringFactory.create(path));
+ }
Query query = session.findAllNodesAtOrBelow(path);
// Now delete the documents from each index using this query, which we can reuse ...
session.getContentWriter().deleteDocuments(query);
@@ -57,6 +57,7 @@
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.Version;
+import org.jboss.dna.common.util.Logger;
import org.jboss.dna.graph.DnaLexicon;
import org.jboss.dna.graph.JcrLexicon;
import org.jboss.dna.graph.Location;
@@ -120,6 +121,7 @@ public FieldSelectorResult accept( String fieldName ) {
private IndexWriter contentWriter;
private IndexSearcher contentSearcher;
private int numChanges;
+ private final Logger logger = Logger.getLogger(getClass());
protected LuceneSearchSession( LuceneSearchWorkspace workspace,
LuceneSearchProcessor processor ) {
@@ -205,6 +207,10 @@ public final int getChangeCount() {
* @see org.jboss.dna.search.lucene.AbstractLuceneSearchEngine.WorkspaceSession#commit()
*/
public void commit() {
+ if (logger.isTraceEnabled() && numChanges > 0) {
+ logger.trace("index for \"{0}\" workspace: COMMIT", workspace.getWorkspaceName());
+ }
+
// Is optimization required ...
final boolean optimize = workspace.isOptimizationRequired(numChanges);
numChanges = 0;
@@ -256,6 +262,9 @@ public void commit() {
* @see org.jboss.dna.search.lucene.AbstractLuceneSearchEngine.WorkspaceSession#rollback()
*/
public void rollback() {
+ if (logger.isTraceEnabled() && numChanges > 0) {
+ logger.trace("index for \"{0}\" workspace: ROLLBACK", workspace.getWorkspaceName());
+ }
numChanges = 0;
IOException ioError = null;
RuntimeException runtimeError = null;
@@ -461,6 +470,7 @@ protected void setOrReplaceProperties( Location location,
if (fullTextSearchValue.length() != 0) {
doc.add(new Field(ContentIndex.FULL_TEXT, fullTextSearchValue.toString(), Field.Store.NO, Field.Index.ANALYZED));
}
+ logger.trace("index for \"{0}\" workspace: ADD {1}", workspace.getWorkspaceName(), doc);
getContentWriter().updateDocument(new Term(ContentIndex.PATH, pathStr), doc);
}

0 comments on commit 8c74bd4

Please sign in to comment.