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/01/13 23:04:37 UTC

svn commit: r1724516 - in /lucene/dev/branches/branch_5x: ./ solr/ solr/core/ solr/core/src/java/org/apache/solr/servlet/ solr/core/src/java/org/apache/solr/update/processor/ solr/core/src/java/org/apache/solr/util/ solr/core/src/test-files/ solr/core/...

Author: markrmiller
Date: Wed Jan 13 22:04:36 2016
New Revision: 1724516

URL: http://svn.apache.org/viewvc?rev=1724516&view=rev
Log:
SOLR-8451: We should not call method.abort in HttpSolrClient or HttpSolrCall#remoteQuery and HttpSolrCall#remoteQuery should not close streams.

Added:
    lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/client/solrj/ConnectionReuseTest.java
      - copied unchanged from r1723615, lucene/dev/trunk/solr/core/src/test/org/apache/solr/client/solrj/ConnectionReuseTest.java
Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/solr/   (props changed)
    lucene/dev/branches/branch_5x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_5x/solr/core/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/util/TestInjection.java
    lucene/dev/branches/branch_5x/solr/core/src/test-files/log4j.properties
    lucene/dev/branches/branch_5x/solr/solrj/   (props changed)
    lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
    lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java

Modified: lucene/dev/branches/branch_5x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/CHANGES.txt?rev=1724516&r1=1724515&r2=1724516&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/solr/CHANGES.txt Wed Jan 13 22:04:36 2016
@@ -170,6 +170,9 @@ Bug Fixes
 
 * SOLR-8494: SimplePostTool and therefore the bin/post script cannot upload files larger than 2.1GB. (shalin)
 
+* SOLR-8451: We should not call method.abort in HttpSolrClient or HttpSolrCall#remoteQuery and 
+  HttpSolrCall#remoteQuery should not close streams. (Mark Miller)
+
 * SOLR-8533: Raise default maxUpdateConnections and maxUpdateConnectionsPerHost to 100k each.
   (Mark Miller)
 

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java?rev=1724516&r1=1724515&r2=1724516&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java Wed Jan 13 22:04:36 2016
@@ -521,7 +521,6 @@ public class HttpSolrCall {
   private void remoteQuery(String coreUrl, HttpServletResponse resp) throws IOException {
     HttpRequestBase method = null;
     HttpEntity httpEntity = null;
-    boolean success = false;
     try {
       String urlstr = coreUrl + queryParams.toQueryString();
 
@@ -580,24 +579,17 @@ public class HttpSolrCall {
 
         InputStream is = httpEntity.getContent();
         OutputStream os = resp.getOutputStream();
-        try {
-          IOUtils.copyLarge(is, os);
-          os.flush();
-        } finally {
-          IOUtils.closeQuietly(os);   // TODO: I thought we weren't supposed to explicitly close servlet streams
-          IOUtils.closeQuietly(is);
-        }
+
+        IOUtils.copyLarge(is, os);
+        os.flush();
       }
-      success = true;
+
     } catch (IOException e) {
       sendError(new SolrException(
           SolrException.ErrorCode.SERVER_ERROR,
           "Error trying to proxy request for url: " + coreUrl, e));
     } finally {
       EntityUtils.consumeQuietly(httpEntity);
-      if (method != null && !success) {
-        method.abort();
-      }
     }
 
   }

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java?rev=1724516&r1=1724515&r2=1724516&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/update/processor/DistributedUpdateProcessor.java Wed Jan 13 22:04:36 2016
@@ -659,6 +659,9 @@ public class DistributedUpdateProcessor
 
   @Override
   public void processAdd(AddUpdateCommand cmd) throws IOException {
+    
+    assert TestInjection.injectFailUpdateRequests();
+    
     updateCommand = cmd;
 
     if (zkEnabled) {
@@ -1122,6 +1125,9 @@ public class DistributedUpdateProcessor
 
   @Override
   public void processDelete(DeleteUpdateCommand cmd) throws IOException {
+    
+    assert TestInjection.injectFailUpdateRequests();
+    
     updateCommand = cmd;
 
     if (!cmd.isDeleteById()) {
@@ -1577,6 +1583,9 @@ public class DistributedUpdateProcessor
 
   @Override
   public void processCommit(CommitUpdateCommand cmd) throws IOException {
+    
+    assert TestInjection.injectFailUpdateRequests();
+    
     updateCommand = cmd;
     List<Node> nodes = null;
     boolean singleLeader = false;

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/util/TestInjection.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/util/TestInjection.java?rev=1724516&r1=1724515&r2=1724516&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/util/TestInjection.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/util/TestInjection.java Wed Jan 13 22:04:36 2016
@@ -64,12 +64,15 @@ public class TestInjection {
 
   public static String failReplicaRequests = null;
   
+  public static String failUpdateRequests = null;
+  
   private static Set<Timer> timers = Collections.synchronizedSet(new HashSet<Timer>());
 
 
   public static void reset() {
     nonGracefullClose = null;
     failReplicaRequests = null;
+    failUpdateRequests = null;
 
     for (Timer timer : timers) {
       timer.cancel();
@@ -120,6 +123,19 @@ public class TestInjection {
       boolean enabled = pair.getKey();
       int chanceIn100 = pair.getValue();
       if (enabled && RANDOM.nextInt(100) >= (100 - chanceIn100)) {
+        throw new SolrException(ErrorCode.SERVER_ERROR, "Random test update fail");
+      }
+    }
+
+    return true;
+  }
+  
+  public static boolean injectFailUpdateRequests() {
+    if (failUpdateRequests != null) {
+      Pair<Boolean,Integer> pair = parseValue(failUpdateRequests);
+      boolean enabled = pair.getKey();
+      int chanceIn100 = pair.getValue();
+      if (enabled && RANDOM.nextInt(100) >= (100 - chanceIn100)) {
         throw new SolrException(ErrorCode.SERVER_ERROR, "Random test update fail");
       }
     }

Modified: lucene/dev/branches/branch_5x/solr/core/src/test-files/log4j.properties
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test-files/log4j.properties?rev=1724516&r1=1724515&r2=1724516&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test-files/log4j.properties (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test-files/log4j.properties Wed Jan 13 22:04:36 2016
@@ -27,4 +27,10 @@ log4j.logger.org.apache.solr.hadoop=INFO
 #log4j.logger.org.apache.solr.handler.IndexFetcher=DEBUG
 
 #log4j.logger.org.apache.solr.common.cloud.ClusterStateUtil=DEBUG
-#log4j.logger.org.apache.solr.cloud.OverseerAutoReplicaFailoverThread=DEBUG
\ No newline at end of file
+#log4j.logger.org.apache.solr.cloud.OverseerAutoReplicaFailoverThread=DEBUG
+
+#log4j.logger.org.apache.http.impl.conn.PoolingClientConnectionManager=DEBUG
+#log4j.logger.org.apache.http.impl.conn.BasicClientConnectionManager=DEBUG
+#log4j.logger.org.apache.http=DEBUG
+#log4j.logger.org.apache.solr.client.solrj.impl.SolrHttpRequestRetryHandler=DEBUG
+#log4j.logger.org.eclipse.jetty.server=DEBUG
\ No newline at end of file

Modified: lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java?rev=1724516&r1=1724515&r2=1724516&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java (original)
+++ lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java Wed Jan 13 22:04:36 2016
@@ -24,6 +24,7 @@ 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;
@@ -46,6 +47,7 @@ import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.lang.invoke.MethodHandles;
 import java.nio.charset.StandardCharsets;
@@ -56,11 +58,8 @@ import java.util.Set;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
 
 /**
  * ConcurrentUpdateSolrClient buffers all added documents and writes
@@ -198,6 +197,7 @@ public class ConcurrentUpdateSolrClient
         HttpPost method = null;
         HttpResponse response = null;
 
+        InputStream rspBody = null;
         try {
           final UpdateRequest updateRequest =
               queue.poll(pollQueueTime, TimeUnit.MILLISECONDS);
@@ -280,6 +280,7 @@ public class ConcurrentUpdateSolrClient
           method.addHeader("Content-Type", contentType);
 
           response = client.getHttpClient().execute(method);
+          rspBody = response.getEntity().getContent();
           int statusCode = response.getStatusLine().getStatusCode();
           if (statusCode != HttpStatus.SC_OK) {
             StringBuilder msg = new StringBuilder();
@@ -297,7 +298,7 @@ public class ConcurrentUpdateSolrClient
                   encoding = param.getValue();
                 }
               }
-              NamedList<Object> resp = client.parser.processResponse(response.getEntity().getContent(), encoding);
+              NamedList<Object> resp = client.parser.processResponse(rspBody, encoding);
               NamedList<Object> error = (NamedList<Object>) resp.get("error");
               if (error != null) {
                 solrExc.setMetadata((NamedList<String>) error.get("metadata"));
@@ -314,10 +315,10 @@ public class ConcurrentUpdateSolrClient
         } finally {
           try {
             if (response != null) {
-              response.getEntity().getContent().close();
+              EntityUtils.consume(response.getEntity());
             }
-          } catch (Exception ex) {
-            log.warn("", ex);
+          } catch (Exception e) {
+            log.error("Error consuming and closing http response stream.", e);
           }
         }
       }

Modified: lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java?rev=1724516&r1=1724515&r2=1724516&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java (original)
+++ lucene/dev/branches/branch_5x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java Wed Jan 13 22:04:36 2016
@@ -18,6 +18,7 @@ package org.apache.solr.client.solrj.imp
 
 import org.apache.commons.io.IOUtils;
 import org.apache.http.Header;
+import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.NameValuePair;
@@ -77,8 +78,6 @@ import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
 
-import static java.nio.charset.StandardCharsets.UTF_8;
-
 /**
  * A SolrClient implementation that talks directly to a Solr server via HTTP
  *
@@ -472,16 +471,17 @@ public class HttpSolrClient extends Solr
   protected NamedList<Object> executeMethod(HttpRequestBase method, final ResponseParser processor) throws SolrServerException {
     method.addHeader("User-Agent", AGENT);
     
+    HttpEntity entity = null;
     InputStream respBody = null;
     boolean shouldClose = true;
-    boolean success = false;
     try {
       // Execute the method.
       final HttpResponse response = httpClient.execute(method);
       int httpStatus = response.getStatusLine().getStatusCode();
       
       // Read the contents
-      respBody = response.getEntity().getContent();
+      entity = response.getEntity();
+      respBody = entity.getContent();
       Header ctHeader = response.getLastHeader("content-type");
       String contentType;
       if (ctHeader != null) {
@@ -517,7 +517,6 @@ public class HttpSolrClient extends Solr
         rsp.add("stream", respBody);
         // Only case where stream should not be closed
         shouldClose = false;
-        success = true;
         return rsp;
       }
       
@@ -576,7 +575,6 @@ public class HttpSolrClient extends Solr
         if (metadata != null) rss.setMetadata(metadata);
         throw rss;
       }
-      success = true;
       return rsp;
     } catch (ConnectException e) {
       throw new SolrServerException("Server refused connection at: "
@@ -589,15 +587,11 @@ public class HttpSolrClient extends Solr
       throw new SolrServerException(
           "IOException occured when talking to server at: " + getBaseURL(), e);
     } finally {
-      if (respBody != null && shouldClose) {
+      if (shouldClose) {
         try {
-          respBody.close();
+          EntityUtils.consume(entity);
         } catch (IOException e) {
-          log.error("", e);
-        } finally {
-          if (!success) {
-            method.abort();
-          }
+          log.error("Error consuming and closing http response stream.", e);
         }
       }
     }