better control over close-state of remote solr connections

pull/1/head
Michael Peter Christen 11 years ago
parent 1a364572a5
commit 1b5e3d523a

@ -73,6 +73,11 @@ public class CachedSolrConnector extends AbstractSolrConnector implements SolrCo
this.documentCache.clear(); this.documentCache.clear();
if (this.solr != null) this.solr.commit(true); if (this.solr != null) this.solr.commit(true);
} }
@Override
public boolean isClosed() {
return this.solr == null || this.solr.isClosed();
}
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
this.close(); this.close();

@ -291,6 +291,11 @@ public class ConcurrentUpdateSolrConnector implements SolrConnector {
return this.connector.getSegmentCount(); return this.connector.getSegmentCount();
} }
@Override
public boolean isClosed() {
return this.connector == null || this.connector.isClosed();
}
@Override @Override
public void close() { public void close() {
ensureAliveDeletionHandler(); ensureAliveDeletionHandler();
@ -301,6 +306,8 @@ public class ConcurrentUpdateSolrConnector implements SolrConnector {
try {this.updateHandler.join();} catch (final InterruptedException e) {} try {this.updateHandler.join();} catch (final InterruptedException e) {}
this.connector.close(); this.connector.close();
this.idCache.clear(); this.idCache.clear();
this.connector = null;
this.idCache = null;
} }
@Override @Override

@ -141,6 +141,11 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
public SolrConfig getConfig() { public SolrConfig getConfig() {
return this.core.getSolrConfig(); return this.core.getSolrConfig();
} }
@Override
public boolean isClosed() {
return this.core == null || this.core.isClosed();
}
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
this.close(); this.close();

@ -120,11 +120,16 @@ public class MirrorSolrConnector extends AbstractSolrConnector implements SolrCo
int s1 = this.solr1 == null ? 0 : this.solr1.getSegmentCount(); int s1 = this.solr1 == null ? 0 : this.solr1.getSegmentCount();
return Math.max(s0, s1); return Math.max(s0, s1);
} }
@Override
public boolean isClosed() {
return (this.solr0 == null || this.solr0.isClosed()) && (this.solr1 == null || this.solr1.isClosed());
}
@Override @Override
public synchronized void close() { public synchronized void close() {
if (this.solr0 != null) this.solr0.close(); if (this.solr0 != null) {this.solr0.close(); this.solr0 = null;}
if (this.solr1 != null) this.solr1.close(); if (this.solr1 != null) {this.solr1.close(); this.solr1 = null;}
} }
/** /**

@ -69,6 +69,12 @@ public interface SolrConnector extends Iterable<String> /* Iterable of document
*/ */
public int getSegmentCount(); public int getSegmentCount();
/**
* test if the connector is already closed
* @return true if the connector is closed
*/
public boolean isClosed();
/** /**
* close the server connection * close the server connection
*/ */

@ -120,13 +120,24 @@ public abstract class SolrServerConnector extends AbstractSolrConnector implemen
return 0; 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 @Override
public void close() { public void close() {
if (this.server == null) return; if (this.server == null) return;
try { 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; this.server = null;
} catch (final Throwable e) { } catch (final Throwable e) {
ConcurrentLog.logException(e); ConcurrentLog.logException(e);

@ -1040,8 +1040,11 @@ public final class Protocol {
if (localsearch && !Switchboard.getSwitchboard().getConfigBool(SwitchboardConstants.DEBUG_SEARCH_REMOTE_SOLR_TESTLOCAL, false)) { if (localsearch && !Switchboard.getSwitchboard().getConfigBool(SwitchboardConstants.DEBUG_SEARCH_REMOTE_SOLR_TESTLOCAL, false)) {
// search the local index // search the local index
try { try {
rsp[0] = event.getQuery().getSegment().fulltext().getDefaultConnector().getResponseByParams(solrQuery); SolrConnector sc = event.getQuery().getSegment().fulltext().getDefaultConnector();
docList[0] = rsp[0].getResults(); if (!sc.isClosed()) {
rsp[0] = sc.getResponseByParams(solrQuery);
docList[0] = rsp[0].getResults();
}
} catch (final Throwable e) { } catch (final Throwable e) {
Network.log.info("SEARCH failed (solr), localpeer (" + e.getMessage() + ")", e); Network.log.info("SEARCH failed (solr), localpeer (" + e.getMessage() + ")", e);
return -1; 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 RemoteInstance instance = new RemoteInstance("http://" + address, null, "solr", solrtimeout); // this is a 'patch configuration' which considers 'solr' as default collection
try { try {
SolrConnector solrConnector = new RemoteSolrConnector(instance, myseed ? true : target.getVersion() >= 1.63, "solr"); SolrConnector solrConnector = new RemoteSolrConnector(instance, myseed ? true : target.getVersion() >= 1.63, "solr");
try { if (!solrConnector.isClosed()) try {
rsp[0] = solrConnector.getResponseByParams(solrQuery); rsp[0] = solrConnector.getResponseByParams(solrQuery);
docList[0] = rsp[0].getResults(); docList[0] = rsp[0].getResults();
} catch (Throwable e) {} finally { } catch (Throwable e) {} finally {

Loading…
Cancel
Save