You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2016/02/10 21:34:33 UTC
lucene-solr git commit: SOLR-8578: Successful or not,
requests are not always fully consumed by Solrj clients and we count
on HttpClient or the JVM.
Repository: lucene-solr
Updated Branches:
refs/heads/master 5d32609cd -> a8bc427aa
SOLR-8578: Successful or not, requests are not always fully consumed by Solrj clients and we count on HttpClient or the JVM.
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/a8bc427a
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/a8bc427a
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/a8bc427a
Branch: refs/heads/master
Commit: a8bc427aac85d600e1abee28bb373f428c08c7ae
Parents: 5d32609
Author: markrmiller <ma...@apache.org>
Authored: Wed Feb 10 15:32:56 2016 -0500
Committer: markrmiller <ma...@apache.org>
Committed: Wed Feb 10 15:32:56 2016 -0500
----------------------------------------------------------------------
solr/CHANGES.txt | 3 ++
.../solrj/impl/ConcurrentUpdateSolrClient.java | 4 +-
.../solr/client/solrj/impl/HttpSolrClient.java | 7 +---
.../java/org/apache/solr/common/util/Utils.java | 41 ++++++++++++++++++++
4 files changed, 48 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a8bc427a/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 1727211..860e127 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -513,6 +513,9 @@ Bug Fixes
* SOLR-8551: Make collection deletion more robust. (Mark Miller)
+* SOLR-8578: Successful or not, requests are not always fully consumed by Solrj clients and we
+ count on HttpClient or the JVM. (Mark Miller)
+
Optimizations
----------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a8bc427a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
index 2762a9a..5bec96a 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
@@ -23,7 +23,6 @@ import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentProducer;
import org.apache.http.entity.EntityTemplate;
-import org.apache.http.util.EntityUtils;
import org.apache.solr.client.solrj.ResponseParser;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
@@ -41,6 +40,7 @@ import org.apache.solr.common.util.ExecutorUtil;
import org.apache.solr.common.util.IOUtils;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SolrjNamedThreadFactory;
+import org.apache.solr.common.util.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
@@ -314,7 +314,7 @@ public class ConcurrentUpdateSolrClient extends SolrClient {
} finally {
try {
if (response != null) {
- EntityUtils.consume(response.getEntity());
+ Utils.consumeFully(response.getEntity());
}
} catch (Exception e) {
log.error("Error consuming and closing http response stream.", e);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a8bc427a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
index fccac9d..df99560 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
@@ -56,6 +56,7 @@ import org.apache.solr.common.util.ContentStream;
import org.apache.solr.common.util.ExecutorUtil;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SolrjNamedThreadFactory;
+import org.apache.solr.common.util.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
@@ -590,11 +591,7 @@ public class HttpSolrClient extends SolrClient {
"IOException occured when talking to server at: " + getBaseURL(), e);
} finally {
if (shouldClose) {
- try {
- EntityUtils.consume(entity);
- } catch (IOException e) {
- log.error("Error consuming and closing http response stream.", e);
- }
+ Utils.consumeFully(entity);
}
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a8bc427a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java
index c807dbe..03b8b2c 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/Utils.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/Utils.java
@@ -17,7 +17,9 @@
package org.apache.solr.common.util;
import java.io.IOException;
+import java.io.InputStream;
import java.io.StringReader;
+import java.lang.invoke.MethodHandles;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
@@ -31,16 +33,22 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.http.HttpEntity;
+import org.apache.http.util.EntityUtils;
import org.apache.solr.common.SolrException;
import org.noggit.CharArr;
import org.noggit.JSONParser;
import org.noggit.JSONWriter;
import org.noggit.ObjectBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableSet;
public class Utils {
+ private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
public static Map getDeepCopy(Map map, int maxDepth) {
return getDeepCopy(map, maxDepth, true);
}
@@ -161,6 +169,39 @@ public class Utils {
return false;
}
+
+ /**
+ * If the passed entity has content, make sure it is fully
+ * read and closed.
+ *
+ * @param entity to consume or null
+ */
+ public static void consumeFully(HttpEntity entity) {
+ if (entity != null) {
+ try {
+ // make sure the stream is full read
+ readFully(entity.getContent());
+ } catch (UnsupportedOperationException e) {
+ // nothing to do then
+ } catch (IOException e) {
+ // quiet
+ } finally {
+ // close the stream
+ EntityUtils.consumeQuietly(entity);
+ }
+ }
+ }
+
+ /**
+ * Make sure the InputStream is fully read.
+ *
+ * @param is to read
+ * @throws IOException on problem with IO
+ */
+ private static void readFully(InputStream is) throws IOException {
+ is.skip(is.available());
+ while (is.read() != -1) {}
+ }
public static final Pattern ARRAY_ELEMENT_INDEX = Pattern
.compile("(\\S*?)\\[(\\d+)\\]");