From 4815713ec72a194d3bc8dcf864f4d03734354660 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Fri, 31 Aug 2012 15:16:33 +0200 Subject: [PATCH] added synchronization to solr server requests since lucene is not thread-safe. We experienced problems as described in http://stackoverflow.com/questions/5327978/lockobtainfailedexception-updating-lucene-search-index-using-solr --- .../federated/solr/SolrServerConnector.java | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/source/net/yacy/cora/services/federated/solr/SolrServerConnector.java b/source/net/yacy/cora/services/federated/solr/SolrServerConnector.java index 1c83f833f..9b91faf73 100644 --- a/source/net/yacy/cora/services/federated/solr/SolrServerConnector.java +++ b/source/net/yacy/cora/services/federated/solr/SolrServerConnector.java @@ -78,7 +78,9 @@ public abstract class SolrServerConnector extends AbstractSolrConnector implemen @Override public synchronized void close() { try { - this.server.commit(); + synchronized (this.server) { + this.server.commit(); + } this.server = null; } catch (SolrServerException e) { Log.logException(e); @@ -108,8 +110,10 @@ public abstract class SolrServerConnector extends AbstractSolrConnector implemen @Override public void clear() throws IOException { try { - this.server.deleteByQuery("*:*"); - this.server.commit(); + synchronized (this.server) { + this.server.deleteByQuery("*:*"); + this.server.commit(); + } } catch (final Throwable e) { throw new IOException(e); } @@ -118,7 +122,9 @@ public abstract class SolrServerConnector extends AbstractSolrConnector implemen @Override public void delete(final String id) throws IOException { try { - this.server.deleteById(id, this.commitWithinMs); + synchronized (this.server) { + this.server.deleteById(id, this.commitWithinMs); + } } catch (final Throwable e) { throw new IOException(e); } @@ -127,7 +133,9 @@ public abstract class SolrServerConnector extends AbstractSolrConnector implemen @Override public void delete(final List ids) throws IOException { try { - this.server.deleteById(ids, this.commitWithinMs); + synchronized (this.server) { + this.server.deleteById(ids, this.commitWithinMs); + } } catch (final Throwable e) { throw new IOException(e); } @@ -141,7 +149,9 @@ public abstract class SolrServerConnector extends AbstractSolrConnector implemen @Override public void deleteByQuery(final String querystring) throws IOException { try { - this.server.deleteByQuery(querystring, this.commitWithinMs); + synchronized (this.server) { + this.server.deleteByQuery(querystring, this.commitWithinMs); + } } catch (final Throwable e) { throw new IOException(e); } @@ -156,8 +166,10 @@ public abstract class SolrServerConnector extends AbstractSolrConnector implemen up.setCommitWithin(this.commitWithinMs); //up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); try { - this.server.request(up); - this.server.commit(); + synchronized (this.server) { + this.server.request(up); + this.server.commit(); + } } catch (final Throwable e) { throw new IOException(e); } @@ -166,8 +178,10 @@ public abstract class SolrServerConnector extends AbstractSolrConnector implemen @Override public void add(final SolrInputDocument solrdoc) throws IOException, SolrException { try { - this.server.add(solrdoc, this.commitWithinMs); - //this.server.commit(); + synchronized (this.server) { + this.server.add(solrdoc, this.commitWithinMs); + //this.server.commit(); + } } catch (SolrServerException e) { Log.logWarning("SolrConnector", e.getMessage() + " DOC=" + solrdoc.toString()); throw new IOException(e); @@ -179,8 +193,10 @@ public abstract class SolrServerConnector extends AbstractSolrConnector implemen ArrayList l = new ArrayList(); for (SolrInputDocument d: solrdocs) l.add(d); try { - this.server.add(l, this.commitWithinMs); - //this.server.commit(); + synchronized (this.server) { + this.server.add(l, this.commitWithinMs); + //this.server.commit(); + } } catch (SolrServerException e) { Log.logWarning("SolrConnector", e.getMessage() + " DOC=" + solrdocs.toString()); throw new IOException(e);