VIVO-945 Produce more concise log messages when a failure is caused by shutdown.

This commit is contained in:
Jim Blake 2015-01-20 18:08:52 -05:00
parent d5a497774e
commit 7d16e10357
8 changed files with 88 additions and 18 deletions

View file

@ -9,6 +9,11 @@ import edu.cornell.mannlib.vitro.webapp.modules.Application;
/** /**
* The principle interface for the SearchEngine. All search-related objects are * The principle interface for the SearchEngine. All search-related objects are
* created by these methods. * created by these methods.
*
* All methods that throw SearchEngineException should attempt to distinguish
* whether the exception is caused because the SearchEngine is not responding.
* In that case, they should throw a SearchEngineNotRespondingException, so the
* client code can choose to respond accordingly.
*/ */
public interface SearchEngine extends Application.Module { public interface SearchEngine extends Application.Module {
@ -86,7 +91,7 @@ public interface SearchEngine extends Application.Module {
* Query the search index and return the results. Response is never null. * Query the search index and return the results. Response is never null.
*/ */
SearchResponse query(SearchQuery query) throws SearchEngineException; SearchResponse query(SearchQuery query) throws SearchEngineException;
/** /**
* Find the number of documents in the search index. * Find the number of documents in the search index.
*/ */

View file

@ -0,0 +1,27 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.modules.searchEngine;
/**
* Indicates that a request to the SearchEngine has timed out, or given some
* other indication that no response will be coming.
*/
public class SearchEngineNotRespondingException extends SearchEngineException {
public SearchEngineNotRespondingException() {
super();
}
public SearchEngineNotRespondingException(String message) {
super(message);
}
public SearchEngineNotRespondingException(Throwable cause) {
super(cause);
}
public SearchEngineNotRespondingException(String message, Throwable cause) {
super(message, cause);
}
}

View file

@ -3,6 +3,7 @@
package edu.cornell.mannlib.vitro.webapp.searchengine.solr; package edu.cornell.mannlib.vitro.webapp.searchengine.solr;
import java.io.IOException; import java.io.IOException;
import java.net.SocketTimeoutException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -19,6 +20,7 @@ import edu.cornell.mannlib.vitro.webapp.modules.Application;
import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus; import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineNotRespondingException;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse;
@ -72,8 +74,8 @@ public class SolrSearchEngine implements SearchEngine {
try { try {
server.ping(); server.ping();
} catch (SolrServerException | IOException e) { } catch (SolrServerException | IOException e) {
throw new SearchEngineException( throw appropriateException("Solr server did not respond to ping.",
"Solr server did not respont to ping.", e); e);
} }
} }
@ -93,8 +95,8 @@ public class SolrSearchEngine implements SearchEngine {
try { try {
server.add(SolrConversionUtils.convertToSolrInputDocuments(docs)); server.add(SolrConversionUtils.convertToSolrInputDocuments(docs));
} catch (SolrServerException | IOException e) { } catch (SolrServerException | IOException e) {
throw new SearchEngineException( throw appropriateException("Solr server failed to add documents "
"Solr server failed to add documents " + docs, e); + docs, e);
} }
} }
@ -103,8 +105,7 @@ public class SolrSearchEngine implements SearchEngine {
try { try {
server.commit(); server.commit();
} catch (SolrServerException | IOException e) { } catch (SolrServerException | IOException e) {
throw new SearchEngineException("Failed to commit to Solr server.", throw appropriateException("Failed to commit to Solr server.", e);
e);
} }
} }
@ -113,8 +114,7 @@ public class SolrSearchEngine implements SearchEngine {
try { try {
server.commit(wait, wait); server.commit(wait, wait);
} catch (SolrServerException | IOException e) { } catch (SolrServerException | IOException e) {
throw new SearchEngineException("Failed to commit to Solr server.", throw appropriateException("Failed to commit to Solr server.", e);
e);
} }
} }
@ -128,7 +128,7 @@ public class SolrSearchEngine implements SearchEngine {
try { try {
server.deleteById(new ArrayList<>(ids)); server.deleteById(new ArrayList<>(ids));
} catch (SolrServerException | IOException e) { } catch (SolrServerException | IOException e) {
throw new SearchEngineException( throw appropriateException(
"Solr server failed to delete documents: " + ids, e); "Solr server failed to delete documents: " + ids, e);
} }
} }
@ -138,7 +138,7 @@ public class SolrSearchEngine implements SearchEngine {
try { try {
server.deleteByQuery(query); server.deleteByQuery(query);
} catch (SolrServerException | IOException e) { } catch (SolrServerException | IOException e) {
throw new SearchEngineException( throw appropriateException(
"Solr server failed to delete documents: " + query, e); "Solr server failed to delete documents: " + query, e);
} }
} }
@ -162,14 +162,32 @@ public class SolrSearchEngine implements SearchEngine {
QueryResponse response = server.query(solrQuery); QueryResponse response = server.query(solrQuery);
return SolrConversionUtils.convertToSearchResponse(response); return SolrConversionUtils.convertToSearchResponse(response);
} catch (SolrServerException e) { } catch (SolrServerException e) {
throw new SearchEngineException( throw appropriateException(
"Solr server failed to execute the query" + query, e); "Solr server failed to execute the query" + query, e);
} }
} }
@Override @Override
public int documentCount() throws SearchEngineException { public int documentCount() throws SearchEngineException {
SearchResponse response = query(createQuery("*:*")); SearchResponse response = query(createQuery("*:*"));
return (int) response.getResults().getNumFound(); return (int) response.getResults().getNumFound();
} }
/**
* If there is a SocketTimeoutException in the causal chain for this
* exception, then wrap it in a SearchEngineNotRespondingException instead
* of a generic SearchEngineException.
*/
private SearchEngineException appropriateException(String message,
Exception e) {
Throwable cause = e;
while (cause != null) {
if (cause instanceof SocketTimeoutException) {
return new SearchEngineNotRespondingException(message, e);
}
cause = cause.getCause();
}
return new SearchEngineException(message, e);
}
} }

View file

@ -15,6 +15,7 @@ import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
import edu.cornell.mannlib.vitro.webapp.modules.Application; import edu.cornell.mannlib.vitro.webapp.modules.Application;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineNotRespondingException;
import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexer; import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexer;
import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexer.Event; import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexer.Event;
import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexer.Event.Type; import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexer.Event.Type;
@ -118,6 +119,9 @@ public class SearchIndexerSetup implements ServletContextListener {
private void commitChanges() { private void commitChanges() {
try { try {
searchEngine.commit(); searchEngine.commit();
} catch (SearchEngineNotRespondingException e) {
log.error("Failed to commit the changes: "
+ "the search engine is not responding.");
} catch (Exception e) { } catch (Exception e) {
log.error("Failed to commit the changes.", e); log.error("Failed to commit the changes.", e);
} }

View file

@ -17,6 +17,7 @@ import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineNotRespondingException;
import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexer.Event; import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexer.Event;
import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexerStatus; import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexerStatus;
import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexerStatus.RebuildCounts; import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexerStatus.RebuildCounts;
@ -105,6 +106,9 @@ public class RebuildIndexTask implements Task {
try { try {
searchEngine.deleteByQuery(query); searchEngine.deleteByQuery(query);
searchEngine.commit(); searchEngine.commit();
} catch (SearchEngineNotRespondingException e) {
log.warn("Failed to delete outdated documents from the search index: "
+ "the search engine is not responding.");
} catch (SearchEngineException e) { } catch (SearchEngineException e) {
log.warn("Failed to delete outdated documents " log.warn("Failed to delete outdated documents "
+ "from the search index", e); + "from the search index", e);
@ -114,8 +118,12 @@ public class RebuildIndexTask implements Task {
private int getDocumentCount() { private int getDocumentCount() {
try { try {
return searchEngine.documentCount(); return searchEngine.documentCount();
} catch (SearchEngineNotRespondingException e) {
log.warn("Failed to get document count from the search index: "
+ "the search engine is not responding.");
return 0;
} catch (SearchEngineException e) { } catch (SearchEngineException e) {
log.warn("Failed to get docoument count from the search index.", e); log.warn("Failed to get document count from the search index.", e);
return 0; return 0;
} }
} }

View file

@ -31,6 +31,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineNotRespondingException;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument;
import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexerUtils; import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexerUtils;
import edu.cornell.mannlib.vitro.webapp.searchindex.documentBuilding.DocumentModifier; import edu.cornell.mannlib.vitro.webapp.searchindex.documentBuilding.DocumentModifier;
@ -65,6 +66,9 @@ public class UpdateDocumentWorkUnit implements Runnable {
modifiers.modifyDocument(ind, doc); modifiers.modifyDocument(ind, doc);
addIndexedTime(doc); addIndexedTime(doc);
searchEngine.add(doc); searchEngine.add(doc);
} catch (SearchEngineNotRespondingException e) {
log.warn("Failed to add '" + ind + "' to the search index: "
+ "the search engine is not responding.");
} catch (Exception e) { } catch (Exception e) {
log.warn("Failed to add '" + ind + "' to the search index.", e); log.warn("Failed to add '" + ind + "' to the search index.", e);
} }

View file

@ -21,6 +21,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineNotRespondingException;
import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexer.Event; import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexer.Event;
import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexerStatus; import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexerStatus;
import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexerStatus.UriCounts; import edu.cornell.mannlib.vitro.webapp.modules.searchIndexer.SearchIndexerStatus.UriCounts;
@ -131,6 +132,9 @@ public class UpdateUrisTask implements Task {
searchEngine.deleteById(SearchIndexerUtils.getIdForUri(uri)); searchEngine.deleteById(SearchIndexerUtils.getIdForUri(uri));
status.incrementDeletes(); status.incrementDeletes();
log.debug("deleted '" + uri + "' from search index."); log.debug("deleted '" + uri + "' from search index.");
} catch (SearchEngineNotRespondingException e) {
log.warn("Failed to delete '" + uri + "' from search index: "
+ "the search engine is not responding.");
} catch (Exception e) { } catch (Exception e) {
log.warn("Failed to delete '" + uri + "' from search index", e); log.warn("Failed to delete '" + uri + "' from search index", e);
} }
@ -142,6 +146,9 @@ public class UpdateUrisTask implements Task {
searchEngine.deleteById(SearchIndexerUtils.getIdForUri(uri)); searchEngine.deleteById(SearchIndexerUtils.getIdForUri(uri));
status.incrementExclusions(); status.incrementExclusions();
log.debug("excluded '" + uri + "' from search index."); log.debug("excluded '" + uri + "' from search index.");
} catch (SearchEngineNotRespondingException e) {
log.warn("Failed to exclude '" + uri + "' from search index: "
+ "the search engine is not responding.", e);
} catch (Exception e) { } catch (Exception e) {
log.warn("Failed to exclude '" + uri + "' from search index", e); log.warn("Failed to exclude '" + uri + "' from search index", e);
} }

View file

@ -13,10 +13,7 @@ import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualListQueryResults;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngine;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchEngineException;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery.Order; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchQuery.Order;
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse; import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchResponse;