From 412d55523caaf852be1c0cf4d174efc6e279ad72 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Sun, 9 Feb 2014 12:36:14 +0100 Subject: [PATCH] enhanced memory protection and OOM exception handling in Solr connector --- .../solr/connector/ConcurrentUpdateSolrConnector.java | 10 +++++++++- .../federate/solr/connector/EmbeddedSolrConnector.java | 3 ++- .../federate/solr/connector/SolrServerConnector.java | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/source/net/yacy/cora/federate/solr/connector/ConcurrentUpdateSolrConnector.java b/source/net/yacy/cora/federate/solr/connector/ConcurrentUpdateSolrConnector.java index c63a0663d..3d9838618 100644 --- a/source/net/yacy/cora/federate/solr/connector/ConcurrentUpdateSolrConnector.java +++ b/source/net/yacy/cora/federate/solr/connector/ConcurrentUpdateSolrConnector.java @@ -109,9 +109,17 @@ public class ConcurrentUpdateSolrConnector implements SolrConnector { } else { // if there is only a single document, send this directly to solr //ConcurrentLog.info("ConcurrentUpdateSolrConnector", "sending one document to solr"); + updateIdCache((String) doc.getFieldValue(CollectionSchema.id.getSolrFieldName())); try { - updateIdCache((String) doc.getFieldValue(CollectionSchema.id.getSolrFieldName())); ConcurrentUpdateSolrConnector.this.connector.add(doc); + } catch (final OutOfMemoryError e) { + // clear and try again... + clearCaches(); + try { + ConcurrentUpdateSolrConnector.this.connector.add(doc); + } catch (final IOException ee) { + ConcurrentLog.logException(e); + } } catch (final IOException e) { ConcurrentLog.logException(e); } diff --git a/source/net/yacy/cora/federate/solr/connector/EmbeddedSolrConnector.java b/source/net/yacy/cora/federate/solr/connector/EmbeddedSolrConnector.java index ab8897cbe..8af3058d7 100644 --- a/source/net/yacy/cora/federate/solr/connector/EmbeddedSolrConnector.java +++ b/source/net/yacy/cora/federate/solr/connector/EmbeddedSolrConnector.java @@ -38,6 +38,7 @@ import net.yacy.search.schema.CollectionSchema; import org.apache.lucene.document.Document; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.search.FieldCache; import org.apache.lucene.search.Query; import org.apache.lucene.util.BytesRef; import org.apache.solr.client.solrj.SolrQuery; @@ -133,7 +134,7 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo // clear 'lost' caches if (ib instanceof SolrCache) ((SolrCache) ib).clear(); } - // this.core.getInfoRegistry().clear(); + FieldCache.DEFAULT.purgeAllCaches(); // purge the lucene field cache } public SolrInstance getInstance() { diff --git a/source/net/yacy/cora/federate/solr/connector/SolrServerConnector.java b/source/net/yacy/cora/federate/solr/connector/SolrServerConnector.java index b28a9b75a..e8b670ee2 100644 --- a/source/net/yacy/cora/federate/solr/connector/SolrServerConnector.java +++ b/source/net/yacy/cora/federate/solr/connector/SolrServerConnector.java @@ -71,6 +71,7 @@ public abstract class SolrServerConnector extends AbstractSolrConnector implemen @Override public void commit(final boolean softCommit) { + if (this.server == null) return; synchronized (this.server) { try { this.server.commit(true, true, softCommit);