diff --git a/source/net/yacy/cora/federate/solr/connector/CachedSolrConnector.java b/source/net/yacy/cora/federate/solr/connector/CachedSolrConnector.java index 58705b5d9..cf28b3021 100644 --- a/source/net/yacy/cora/federate/solr/connector/CachedSolrConnector.java +++ b/source/net/yacy/cora/federate/solr/connector/CachedSolrConnector.java @@ -73,6 +73,11 @@ public class CachedSolrConnector extends AbstractSolrConnector implements SolrCo this.documentCache.clear(); if (this.solr != null) this.solr.commit(true); } + + @Override + public boolean isClosed() { + return this.solr == null || this.solr.isClosed(); + } protected void finalize() throws Throwable { this.close(); diff --git a/source/net/yacy/cora/federate/solr/connector/ConcurrentUpdateSolrConnector.java b/source/net/yacy/cora/federate/solr/connector/ConcurrentUpdateSolrConnector.java index e51f4f99c..a696e1fa0 100644 --- a/source/net/yacy/cora/federate/solr/connector/ConcurrentUpdateSolrConnector.java +++ b/source/net/yacy/cora/federate/solr/connector/ConcurrentUpdateSolrConnector.java @@ -291,6 +291,11 @@ public class ConcurrentUpdateSolrConnector implements SolrConnector { return this.connector.getSegmentCount(); } + @Override + public boolean isClosed() { + return this.connector == null || this.connector.isClosed(); + } + @Override public void close() { ensureAliveDeletionHandler(); @@ -301,6 +306,8 @@ public class ConcurrentUpdateSolrConnector implements SolrConnector { try {this.updateHandler.join();} catch (final InterruptedException e) {} this.connector.close(); this.idCache.clear(); + this.connector = null; + this.idCache = null; } @Override diff --git a/source/net/yacy/cora/federate/solr/connector/EmbeddedSolrConnector.java b/source/net/yacy/cora/federate/solr/connector/EmbeddedSolrConnector.java index 263579c87..1262a7b6f 100644 --- a/source/net/yacy/cora/federate/solr/connector/EmbeddedSolrConnector.java +++ b/source/net/yacy/cora/federate/solr/connector/EmbeddedSolrConnector.java @@ -141,6 +141,11 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo public SolrConfig getConfig() { return this.core.getSolrConfig(); } + + @Override + public boolean isClosed() { + return this.core == null || this.core.isClosed(); + } protected void finalize() throws Throwable { this.close(); diff --git a/source/net/yacy/cora/federate/solr/connector/MirrorSolrConnector.java b/source/net/yacy/cora/federate/solr/connector/MirrorSolrConnector.java index 9adf6bffd..b44bc68c2 100644 --- a/source/net/yacy/cora/federate/solr/connector/MirrorSolrConnector.java +++ b/source/net/yacy/cora/federate/solr/connector/MirrorSolrConnector.java @@ -120,11 +120,16 @@ public class MirrorSolrConnector extends AbstractSolrConnector implements SolrCo int s1 = this.solr1 == null ? 0 : this.solr1.getSegmentCount(); return Math.max(s0, s1); } + + @Override + public boolean isClosed() { + return (this.solr0 == null || this.solr0.isClosed()) && (this.solr1 == null || this.solr1.isClosed()); + } @Override public synchronized void close() { - if (this.solr0 != null) this.solr0.close(); - if (this.solr1 != null) this.solr1.close(); + if (this.solr0 != null) {this.solr0.close(); this.solr0 = null;} + if (this.solr1 != null) {this.solr1.close(); this.solr1 = null;} } /** diff --git a/source/net/yacy/cora/federate/solr/connector/SolrConnector.java b/source/net/yacy/cora/federate/solr/connector/SolrConnector.java index 67a101538..5b61ed310 100644 --- a/source/net/yacy/cora/federate/solr/connector/SolrConnector.java +++ b/source/net/yacy/cora/federate/solr/connector/SolrConnector.java @@ -69,6 +69,12 @@ public interface SolrConnector extends Iterable /* Iterable of document */ public int getSegmentCount(); + /** + * test if the connector is already closed + * @return true if the connector is closed + */ + public boolean isClosed(); + /** * close the server connection */ diff --git a/source/net/yacy/cora/federate/solr/connector/SolrServerConnector.java b/source/net/yacy/cora/federate/solr/connector/SolrServerConnector.java index 7582a2f27..4a5ed0ffe 100644 --- a/source/net/yacy/cora/federate/solr/connector/SolrServerConnector.java +++ b/source/net/yacy/cora/federate/solr/connector/SolrServerConnector.java @@ -120,13 +120,24 @@ public abstract class SolrServerConnector extends AbstractSolrConnector implemen return 0; } } - + + @Override + public boolean isClosed() { + return this.server == null; // we cannot now this exactly when server != null, because SolrServer does not provide a method to test the close status + } @Override public void close() { if (this.server == null) return; try { - if (this.server instanceof EmbeddedSolrServer) synchronized (this.server) {this.server.commit(true, true, false);} + if (this.server instanceof EmbeddedSolrServer) { + synchronized (this.server) { + this.server.commit(true, true, false); + } + } + synchronized (this.server) { + this.server.shutdown(); // if the server is embedded, resources are freed, if it is a HttpSolrServer, only the httpclient is shut down, not the remote server + } this.server = null; } catch (final Throwable e) { ConcurrentLog.logException(e); diff --git a/source/net/yacy/peers/Protocol.java b/source/net/yacy/peers/Protocol.java index 215b56042..dcc997174 100644 --- a/source/net/yacy/peers/Protocol.java +++ b/source/net/yacy/peers/Protocol.java @@ -1040,8 +1040,11 @@ public final class Protocol { if (localsearch && !Switchboard.getSwitchboard().getConfigBool(SwitchboardConstants.DEBUG_SEARCH_REMOTE_SOLR_TESTLOCAL, false)) { // search the local index try { - rsp[0] = event.getQuery().getSegment().fulltext().getDefaultConnector().getResponseByParams(solrQuery); - docList[0] = rsp[0].getResults(); + SolrConnector sc = event.getQuery().getSegment().fulltext().getDefaultConnector(); + if (!sc.isClosed()) { + rsp[0] = sc.getResponseByParams(solrQuery); + docList[0] = rsp[0].getResults(); + } } catch (final Throwable e) { Network.log.info("SEARCH failed (solr), localpeer (" + e.getMessage() + ")", e); return -1; @@ -1061,7 +1064,7 @@ public final class Protocol { RemoteInstance instance = new RemoteInstance("http://" + address, null, "solr", solrtimeout); // this is a 'patch configuration' which considers 'solr' as default collection try { SolrConnector solrConnector = new RemoteSolrConnector(instance, myseed ? true : target.getVersion() >= 1.63, "solr"); - try { + if (!solrConnector.isClosed()) try { rsp[0] = solrConnector.getResponseByParams(solrQuery); docList[0] = rsp[0].getResults(); } catch (Throwable e) {} finally {