better control over close-state of remote solr connections

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

@ -74,6 +74,11 @@ public class CachedSolrConnector extends AbstractSolrConnector implements SolrCo
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();
}

@ -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

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

@ -121,10 +121,15 @@ public class MirrorSolrConnector extends AbstractSolrConnector implements SolrCo
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;}
}
/**

@ -69,6 +69,12 @@ public interface SolrConnector extends Iterable<String> /* 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
*/

@ -121,12 +121,23 @@ public abstract class SolrServerConnector extends AbstractSolrConnector implemen
}
}
@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);

@ -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);
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 {

Loading…
Cancel
Save