tried some hardening in order not letting any Solr-Searchers open

pull/1/head
sixcooler 11 years ago
parent a16534cb0a
commit 2c2ebb0d92

@ -188,15 +188,14 @@ public class searchresult {
// do the solr request // do the solr request
SolrQueryRequest req = connector.request(post.toSolrParams(null)); SolrQueryRequest req = connector.request(post.toSolrParams(null));
SolrQueryResponse response = null; SolrQueryResponse response = null;
Exception e = null; Writer ow = null;
try {response = connector.query(req);} catch (final SolrException ee) {e = ee;} try {
if (response != null) e = response.getException(); response = connector.query(req);
if (response != null) {
Exception e = response.getException();
if (e != null) { if (e != null) {
ConcurrentLog.logException(e); ConcurrentLog.logException(e);
if (req != null) req.close(); } else {
SolrRequestInfo.clearRequestInfo();
return null;
}
// set some context for the writer // set some context for the writer
/* /*
@ -210,16 +209,20 @@ public class searchresult {
*/ */
// write the result directly to the output stream // write the result directly to the output stream
Writer ow = new FastWriter(new OutputStreamWriter(out, UTF8.charset)); ow = new FastWriter(new OutputStreamWriter(out, UTF8.charset));
try {
responseWriter.write(ow, req, response); responseWriter.write(ow, req, response);
ow.flush(); ow.flush();
}
}
} catch (final SolrException e) {
ConcurrentLog.logException(e);
} catch (final IOException e1) { } catch (final IOException e1) {
} finally { } finally {
req.close(); req.close();
SolrRequestInfo.clearRequestInfo(); SolrRequestInfo.clearRequestInfo();
try {ow.close();} catch (final IOException e1) {} if (ow != null) try {ow.close();} catch (final IOException e1) {}
} }
if (response == null) return null;
// log result // log result
Object rv = response.getValues().get("response"); Object rv = response.getValues().get("response");

@ -218,38 +218,35 @@ public class select {
// do the solr request, generate facets if we use a special YaCy format // do the solr request, generate facets if we use a special YaCy format
SolrParams params = post.toSolrParams(/*responseWriter instanceof JsonResponseWriter ? new YaCySchema[]{YaCySchema.host_s, YaCySchema.url_file_ext_s, YaCySchema.url_protocol_s} :*/ null); SolrParams params = post.toSolrParams(/*responseWriter instanceof JsonResponseWriter ? new YaCySchema[]{YaCySchema.host_s, YaCySchema.url_file_ext_s, YaCySchema.url_protocol_s} :*/ null);
SolrQueryRequest req = connector.request(params); SolrQueryRequest req = connector.request(params);
Writer ow = null;
SolrQueryResponse response = null; SolrQueryResponse response = null;
Exception e = null; try {
try {response = connector.query(req);} catch (final SolrException ee) {e = ee;} response = connector.query(req);
if (response != null) e = response.getException(); if (response != null) {
Exception e = response.getException();
if (e != null) { if (e != null) {
ConcurrentLog.logException(e); ConcurrentLog.logException(e);
if (req != null) req.close(); } else {
SolrRequestInfo.clearRequestInfo();
return null;
}
// write the result directly to the output stream // write the result directly to the output stream
if (responseWriter instanceof BinaryResponseWriter) { if (responseWriter instanceof BinaryResponseWriter) {
try {
((BinaryResponseWriter) responseWriter).write(out, req, response); ((BinaryResponseWriter) responseWriter).write(out, req, response);
} catch (final IOException e1) {
} finally {
req.close();
SolrRequestInfo.clearRequestInfo();
}
} else { } else {
Writer ow = new FastWriter(new OutputStreamWriter(out, UTF8.charset)); ow = new FastWriter(new OutputStreamWriter(out, UTF8.charset));
try {
responseWriter.write(ow, req, response); responseWriter.write(ow, req, response);
ow.flush(); ow.flush();
}
}
}
} catch (final SolrException e) {
ConcurrentLog.logException(e);
} catch (final IOException e1) { } catch (final IOException e1) {
} finally { } finally {
req.close(); req.close();
SolrRequestInfo.clearRequestInfo(); SolrRequestInfo.clearRequestInfo();
try {ow.close();} catch (final IOException e1) {} if (ow != null) try {ow.close();} catch (final IOException e1) {}
}
} }
if (response == null) return null;
// log result // log result
Object rv = response.getValues().get("response"); Object rv = response.getValues().get("response");

@ -114,6 +114,7 @@ public class SolrServlet implements Filter {
throw new ServletException("Unsupported method: " + hrequest.getMethod()); throw new ServletException("Unsupported method: " + hrequest.getMethod());
} }
Writer out = null;
try { try {
SolrCore core = connector.getCore(); SolrCore core = connector.getCore();
if (core == null) { if (core == null) {
@ -146,7 +147,7 @@ public class SolrServlet implements Filter {
} }
// write response body // write response body
Writer out = new FastWriter(new OutputStreamWriter(response.getOutputStream(), UTF8.charset)); out = new FastWriter(new OutputStreamWriter(response.getOutputStream(), UTF8.charset));
//debug //debug
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -171,16 +172,14 @@ public class SolrServlet implements Filter {
responseWriter.write(out, req, rsp); responseWriter.write(out, req, rsp);
out.flush(); out.flush();
return;
} catch (final Throwable ex) { } catch (final Throwable ex) {
sendError(hresponse, ex); sendError(hresponse, ex);
return;
} finally { } finally {
if (req != null) { if (req != null) {
req.close(); req.close();
} }
SolrRequestInfo.clearRequestInfo(); SolrRequestInfo.clearRequestInfo();
if (out != null) try {out.close();} catch (final IOException e1) {}
} }
} }

@ -269,6 +269,7 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
SolrQueryRequest req = new SolrQueryRequestBase(this.core, params){}; SolrQueryRequest req = new SolrQueryRequestBase(this.core, params){};
req.getContext().put("path", SELECT); req.getContext().put("path", SELECT);
req.getContext().put("webapp", CONTEXT); req.getContext().put("webapp", CONTEXT);
try {
for (String id: ids) { for (String id: ids) {
params.setQuery("{!raw f=" + CollectionSchema.id.getSolrFieldName() + "}" + id); params.setQuery("{!raw f=" + CollectionSchema.id.getSolrFieldName() + "}" + id);
SolrQueryResponse rsp = new SolrQueryResponse(); SolrQueryResponse rsp = new SolrQueryResponse();
@ -276,7 +277,9 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
DocList response = ((ResultContext) rsp.getValues().get("response")).docs; DocList response = ((ResultContext) rsp.getValues().get("response")).docs;
if (response.matches() > 0) idsr.add(id); if (response.matches() > 0) idsr.add(id);
} }
} finally {
req.close(); req.close();
}
return idsr; return idsr;
} }

Loading…
Cancel
Save